コード例 #1
0
        /// <summary>
        /// Detach from manually attached behaviors
        /// </summary>
        protected override void DetachBehaviors()
        {
            try
            {
                SnapRectEvent -= new SnapRectEventHandler(htmlEditor_SnapRectEvent);
                MouseUp -= new HtmlEventHandler(htmlEditor_MouseUp);

                base.DetachBehaviors();

                if (_titleBehavior != null)
                {
                    _titleBehavior.TitleChanged -= new EventHandler(titleBehavior_TitleChanged);
                    _titleBehavior.EditableRegionFocusChanged -= new EventHandler(regionBehavior_EditableRegionFocusChanged);
                    _titleBehavior.DetachFromElement();
                    _titleBehavior = null;
                }
                if (_bodyBehavior != null)
                {
                    _bodyBehavior.EditableRegionFocusChanged -= new EventHandler(regionBehavior_EditableRegionFocusChanged);
                    _bodyBehavior.DetachFromElement();
                    _bodyBehavior = null;
                }
            }
            catch (Exception ex)
            {
                Trace.Fail("Unexpected exception detaching behavior -- investigate this immediately!!!!: " + ex.ToString());
            }
        }
コード例 #2
0
        /// <summary>
        /// Attach to behaviors manually
        /// </summary>
        /// <param name="context"></param>
        protected override void AttachBehaviors(IHtmlEditorComponentContext context)
        {
            if (Editable)
            {
                base.AttachBehaviors(context);

                // re-attach to behaviors
                IHTMLElement titleElement = PostTitleElement;
                IHTMLElement bodyElement = PostBodyElement;

                if (titleElement != null)
                {
                    // WinLive 247899, 240926: If we have a title element, check if it has a parent anchor <A> element
                    // Remove parent anchor, otherwise
                    //  a. we cannot perform mouse based text selection inside title text
                    //  b. clicking in the middle of title text will place the cursor at the beginning, causing
                    //     inconsistent selection states in other parts (like damage services)
                    RemoveParentAnchorFromTitle(titleElement, context.MarkupServices);

                    _titleBehavior = new PostTitleEditingElementBehavior(context, null, bodyElement);
                    TitleBehavior.AttachToElement(titleElement);
                    TitleBehavior.TitleChanged += new EventHandler(titleBehavior_TitleChanged);
                    TitleBehavior.EditableRegionFocusChanged += new EventHandler(regionBehavior_EditableRegionFocusChanged);
                }

                if (bodyElement != null)
                {
                    _bodyBehavior = new PostBodyEditingElementBehavior(this, context, titleElement, null);
                    BodyBehavior.EditableRegionFocusChanged += new EventHandler(regionBehavior_EditableRegionFocusChanged);
                    BodyBehavior.AttachToElement(bodyElement);
                }

                SnapRectEvent += new SnapRectEventHandler(htmlEditor_SnapRectEvent);
                MouseUp += new HtmlEventHandler(htmlEditor_MouseUp);
            }
            else
            {
                _titleBehavior = null;
                _bodyBehavior = null;
            }
        }