Beispiel #1
0
        public static void UpdateDomElement(DOMElement target, InsertionMode insertionMode, string content)
        {
            if (target != null)
            {
                switch (insertionMode)
                {
                case InsertionMode.Replace:
                    target.InnerHTML = content;
                    break;

                case InsertionMode.InsertBefore:
                    if (content != null && content.Length > 0)
                    {
                        // Trimming here may be a bit too aggressive.  It is done to make behavior consistent across
                        // browsers (since IE normalizes whitespace BEFORE building its internal data structures).
                        // However, it may end up trimming whitespace left intentionally by the developer.
                        target.InnerHTML = content + target.InnerHTML.TrimStart();
                    }
                    break;

                case InsertionMode.InsertAfter:
                    if (content != null && content.Length > 0)
                    {
                        // See comment for InsertBefore re: Trimming
                        target.InnerHTML = target.InnerHTML.TrimEnd() + content;
                    }
                    break;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Returns a literal object for the text between HtmlStart (the last position of the end of a
        /// tag) and the current position. If !AllowLiterals then it's wrapped in a span.
        /// </summary>
        ///
        /// <param name="factory">
        /// The HTML factory to operate against
        /// </param>
        /// <param name="literal">
        /// [out] The literal.
        /// </param>
        ///
        /// <returns>
        /// true if it succeeds, false if it fails.
        /// </returns>

        public bool TryGetLiteral(HtmlElementFactory factory, out IDomObject literal)
        {
            if (Pos <= HtmlStart)
            {
                literal = null;
                return(false);
            }

            // There's plain text -return it as a literal.

            DomText lit;

            switch (InsertionMode)
            {
            case InsertionMode.Invalid:
                lit = new DomInvalidElement();
                break;

            case InsertionMode.Text:
                InsertionMode = InsertionMode.Default;
                lit           = new DomInnerText();
                break;

            default:
                lit = new DomText();
                break;
            }
            literal = lit;

            //if (factory.IsBound)
            //{
            //    lit.SetTextIndex(factory.Document, factory.Document.DocumentIndex.TokenizeString(HtmlStart, Pos - HtmlStart));
            //}
            //else
            //{
            string text = factory.Html.SubstringBetween(HtmlStart, Pos);

            literal.NodeValue = HtmlData.HtmlDecode(text);
            //}

            if (WrapLiterals)
            {
                DomElement wrapper = DomElement.Create("span");
                wrapper.AppendChildUnsafe(literal);
                literal = wrapper;
            }


            if (Parent != null)
            {
                ((DomElement)Parent.Element).AppendChildUnsafe(literal);
                Reset();
                return(false);
            }
            else
            {
                TokenizerState = TokenizerState.Finished;
                return(true);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Use this to prepare the iterator object to continue finding siblings. It retains the parent.
        /// It just avoids having to recreate an instance of this object for the next tag.
        /// </summary>

        public void Reset()
        {
            TokenizerState = TokenizerState.Default;
            HtmlStart      = Pos;
            InsertionMode  = InsertionMode.Default;
            Element        = null;
        }
        /// <summary>
        /// Inserts a new comment node either before or after the
        /// currently selected node.
        /// </summary>
        void InsertComment(XmlComment comment, InsertionMode insertionMode)
        {
            ExtTreeNode selectedNode = (ExtTreeNode)SelectedNode;

            if (selectedNode != null)
            {
                ExtTreeNode        parentNode = (ExtTreeNode)selectedNode.Parent;
                XmlCommentTreeNode newNode    = new XmlCommentTreeNode(comment);
                int index = 0;
                if (parentNode != null)
                {
                    index = parentNode.Nodes.IndexOf(selectedNode);
                }
                else
                {
                    index = Nodes.IndexOf(selectedNode);
                }
                if (insertionMode == InsertionMode.After)
                {
                    index++;
                }
                if (parentNode != null)
                {
                    newNode.Insert(index, parentNode);
                }
                else
                {
                    newNode.Insert(index, this);
                }
            }
        }
Beispiel #5
0
 public AjaxContext(WebRequest request, DOMElement updateTarget, DOMElement loadingElement, InsertionMode insertionMode)
 {
     _request        = request;
     _updateTarget   = updateTarget;
     _loadingElement = loadingElement;
     _insertionMode  = insertionMode;
 }
Beispiel #6
0
        /// <summary>
        /// Use this to prepare the iterator object to continue finding siblings. It retains the parent.
        /// It just avoids having to recreate an instance of this object for the next tag.
        /// </summary>

        public void Reset()
        {
            TokenizerState = TokenizerState.Default;
            HtmlStart = Pos;
            InsertionMode = InsertionMode.Default;
            Element = null;
        }
Beispiel #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ListBoxItemDragEventArgs"/> class.
 /// </summary>
 /// <param name="dragIndex">The index of the item that initiated the drag operation.</param>
 /// <param name="insertionIndex">The index of the the <see cref="LevelItem"/> that is the target of the drag operation.</param>
 /// <param name="insertionMode">The relation of the <see cref="InsertionIndex"/>.</param>
 /// <param name="x">The x-coordinate of a mouse click, in pixels.</param>
 /// <param name="y">The y-coordinate of a mouse click, in pixels.</param>
 public ListBoxItemDragEventArgs(int dragIndex, int insertionIndex, InsertionMode insertionMode, int x, int y)
     : this()
 {
     this.DragIndex      = dragIndex;
     this.X              = x;
     this.Y              = y;
     this.InsertionIndex = insertionIndex;
     this.InsertionMode  = insertionMode;
 }
 private static AjaxOptions SetAjaxUpdateTarget(string targetId, InsertionMode mode = InsertionMode.Replace)
 {
     return(new AjaxOptions
     {
         UpdateTargetId = targetId,
         HttpMethod = "GET",
         InsertionMode = mode
     });
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ListViewItemDragEventArgs"/> class.
 /// </summary>
 /// <param name="sourceItem">The <see cref="ListViewItem"/> that initiated the drag operation.</param>
 /// <param name="dropItem">The <see cref="ListViewItem"/> located at the mouse coordinates.</param>
 /// <param name="insertionIndex">The index of the the <see cref="ListViewItem"/> that is the target of the drag operation.</param>
 /// <param name="insertionMode">The relation of the <see cref="InsertionIndex"/>.</param>
 /// <param name="x">The x-coordinate of a mouse click, in pixels.</param>
 /// <param name="y">The y-coordinate of a mouse click, in pixels.</param>
 public ListViewItemDragEventArgs(ListViewItem sourceItem, ListViewItem dropItem, int insertionIndex, InsertionMode insertionMode, int x, int y)
   : this()
 {
   this.Item = sourceItem;
   this.DropItem = dropItem;
   this.X = x;
   this.Y = y;
   this.InsertionIndex = insertionIndex;
   this.InsertionMode = insertionMode;
 }
Beispiel #10
0
 public AjaxEditModel(T model, bool readOnly, string controller, string action, InsertionMode insertionMode, string dialogElementId, string gridElementId)
 {
     Model           = model;
     ReadOnly        = readOnly;
     Controller      = controller;
     Action          = action;
     InsertionMode   = insertionMode;
     DialogElementId = dialogElementId;
     GridElementId   = gridElementId;
 }
Beispiel #11
0
        public static MvcHtmlString GetTimer <VM>(
            this HtmlHelper <VM> htmlHelper, TimeSpan timeInterval,
            string actionName,
            string targetIdName,
            string controllerName = null,
            object parameters     = null,
            string routeName      = null,
            string protocol       = null,
            string hostname       = null,
            string fragment       = null,
            InsertionMode mode    = InsertionMode.Replace,
            string afterSuccess   = null
            )
        {
            if (string.IsNullOrWhiteSpace(targetIdName))
            {
                throw new ArgumentNullException("targetIdName");
            }

            System.Web.Routing.RouteValueDictionary routeDictionary = null;
            if (parameters != null)
            {
                routeDictionary = new System.Web.Routing.RouteValueDictionary(parameters);
            }
            else
            {
                routeDictionary = new System.Web.Routing.RouteValueDictionary();
            }
            string ajaxUrl = UrlHelper.GenerateUrl(
                routeName,
                actionName,
                controllerName,
                protocol,
                hostname,
                fragment,
                routeDictionary,
                htmlHelper.RouteCollection,
                htmlHelper.ViewContext.RequestContext,
                true);
            string modeS;

            switch (mode)
            {
            case InsertionMode.Replace: modeS = "0"; break;

            case InsertionMode.InsertBefore: modeS = "-1"; break;

            case InsertionMode.InsertAfter: modeS = "1"; break;

            default: modeS = "1"; break;
            }
            return(MvcHtmlString.Create(
                       string.Format(getTimerScript, ajaxUrl, targetIdName, timeInterval.TotalMilliseconds, modeS, afterSuccess == null ? "null" : afterSuccess)
                       ));
        }
        public void InsertionModeUnobtrusiveTests(InsertionMode mode, string expected)
        {
            // Arrange
            AjaxOptions options = new AjaxOptions { InsertionMode = mode };

            // Act
            string result = options.InsertionModeUnobtrusive;
            
            // Assert
            Assert.Equal(expected, result);
        }
Beispiel #13
0
        public void InsertionModeUnobtrusiveTests(InsertionMode mode, string expected)
        {
            // Arrange
            AjaxOptions options = new AjaxOptions {
                InsertionMode = mode
            };

            // Act
            string result = options.InsertionModeUnobtrusive;

            // Assert
            Assert.Equal(expected, result);
        }
        /// <summary>
        /// Inserts a new text node either before or after the
        /// currently selected node.
        /// </summary>
        void InsertTextNode(XmlText textNode, InsertionMode insertionMode)
        {
            ExtTreeNode selectedNode = (ExtTreeNode)SelectedNode;

            if (selectedNode != null)
            {
                XmlElementTreeNode parentNode = (XmlElementTreeNode)selectedNode.Parent;
                XmlTextTreeNode    newNode    = new XmlTextTreeNode(textNode);
                int index = parentNode.Nodes.IndexOf(selectedNode);
                if (insertionMode == InsertionMode.After)
                {
                    index++;
                }
                newNode.Insert(index, parentNode);
            }
        }
Beispiel #15
0
        internal static string InsertionModeToString(InsertionMode insertionMode)
        {
            switch (insertionMode)
            {
            case InsertionMode.Replace:
                return("Sys.Mvc.InsertionMode.replace");

            case InsertionMode.InsertBefore:
                return("Sys.Mvc.InsertionMode.insertBefore");

            case InsertionMode.InsertAfter:
                return("Sys.Mvc.InsertionMode.insertAfter");

            default:
                return(((int)insertionMode).ToString(CultureInfo.InvariantCulture));
            }
        }
Beispiel #16
0
        public static AjaxOptions AjaxOptions(string httpMethod, string updateTargetId, bool loading,
                                              string onSuccess, string onFailure, InsertionMode inseretionMode)
        {
            var options = new AjaxOptions();

            options.InsertionMode = inseretionMode;
            options.OnFailure     = string.IsNullOrEmpty(onFailure) ? "ShowToast('An error occurs', 'Ko')" : onFailure;
            if (!string.IsNullOrEmpty(onSuccess))
            {
                options.OnSuccess = onSuccess;
            }
            options.UpdateTargetId = string.IsNullOrEmpty(updateTargetId) ? "content" : updateTargetId;
            if (loading)
            {
                options.LoadingElementId = "loader";
            }
            options.HttpMethod = string.IsNullOrEmpty(httpMethod) ? "GET" : httpMethod;
            return(options);
        }
Beispiel #17
0
        public void ToUnobtrusiveHtmlAttributesWithUpdateTargetIdAndExplicitInsertionMode(
            InsertionMode mode,
            string expectedMode
            )
        {
            // Arrange
            AjaxOptions options = new AjaxOptions
            {
                InsertionMode  = mode,
                UpdateTargetId = "someId"
            };

            // Act
            var attributes = options.ToUnobtrusiveHtmlAttributes();

            // Assert
            Assert.Equal(3, attributes.Count);
            Assert.Equal("true", attributes["data-ajax"]);
            Assert.Equal("#someId", attributes["data-ajax-update"]);
            Assert.Equal(expectedMode, attributes["data-ajax-mode"]);
        }
Beispiel #18
0
        public static AjaxOptions GetAjaxOptions(string url, 
            string updateTargetId,
            InsertionMode insertionMode = InsertionMode.Replace,
            int loadingElementDuration = LoadingElementDuration,
            string httpMethod = HttpMethodPost, 
            string loadingElementId = LoadingElementId,
            string onBegin = Empty,
            string onComplete = Empty,
            string onFailure = Empty,
            string onSuccess = Empty)
        {
            var result = new AjaxOptions
            {
                HttpMethod = httpMethod,
                LoadingElementDuration = loadingElementDuration,
                InsertionMode = insertionMode,
                LoadingElementId = loadingElementId,
                UpdateTargetId = updateTargetId,
                Url = url
            };

            if (!String.IsNullOrWhiteSpace(onBegin))
            {
                result.OnBegin = onBegin;
            }
            if (!String.IsNullOrWhiteSpace(onComplete))
            {
                result.OnComplete = onComplete;
            }
            if (!String.IsNullOrWhiteSpace(onFailure))
            {
                result.OnFailure = onFailure;
            }
            if (!String.IsNullOrWhiteSpace(onSuccess))
            {
                result.OnSuccess = onSuccess;
            }

            return result;
        }
Beispiel #19
0
 internal StateSnapshot(StackNode <T>[] stack,
                        StackNode <T>[] listOfActiveFormattingElements,
                        T formPointer,
                        T headPointer,
                        T deepTreeSurrogateParent,
                        InsertionMode mode,
                        InsertionMode originalMode,
                        bool framesetOk,
                        bool needToDropLF,
                        bool quirks)
 {
     Stack = stack;
     ListOfActiveFormattingElements = listOfActiveFormattingElements;
     FormPointer             = formPointer;
     HeadPointer             = headPointer;
     DeepTreeSurrogateParent = deepTreeSurrogateParent;
     Mode           = mode;
     OriginalMode   = originalMode;
     IsFramesetOk   = framesetOk;
     IsNeedToDropLF = needToDropLF;
     IsQuirks       = quirks;
 }
		/// <summary>
		/// Inserts a new text node either before or after the 
		/// currently selected node.
		/// </summary>
		void InsertTextNode(XmlText textNode, InsertionMode insertionMode)
		{
			ExtTreeNode selectedNode = (ExtTreeNode)SelectedNode;
			if (selectedNode != null) {
				XmlElementTreeNode parentNode = (XmlElementTreeNode)selectedNode.Parent;
				XmlTextTreeNode newNode = new XmlTextTreeNode(textNode);
				int index = parentNode.Nodes.IndexOf(selectedNode);
				if (insertionMode == InsertionMode.After) {
					index++;
				}
				newNode.Insert(index, parentNode);
			}
		}
Beispiel #21
0
        internal static string ToJavascriptString(InsertionMode insertionMode)
        {
            switch (insertionMode)
            {
                case InsertionMode.InsertBefore:
                    return "Sys.Mvc.InsertionMode.insertBefore";

                case InsertionMode.InsertAfter:
                    return "Sys.Mvc.InsertionMode.insertAfter";

                case InsertionMode.Replace:
                    return "Sys.Mvc.InsertionMode.replace";

                default:
                    return insertionMode.ToString();
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ListViewItemDragEventArgs"/> class.
 /// </summary>
 /// <param name="sourceItem">The <see cref="ListViewItem"/> that initiated the drag operation.</param>
 /// <param name="dropItem">The <see cref="ListViewItem"/> located at the mouse coordinates.</param>
 /// <param name="insertionIndex">The index of the the <see cref="ListViewItem"/> that is the target of the drag operation.</param>
 /// <param name="insertionMode">The relation of the <see cref="InsertionIndex"/>.</param>
 /// <param name="x">The x-coordinate of a mouse click, in pixels.</param>
 /// <param name="y">The y-coordinate of a mouse click, in pixels.</param>
 public ListViewItemDragEventArgs(ListViewItem sourceItem, ListViewItem dropItem, int insertionIndex, InsertionMode insertionMode, int x, int y)
     : this()
 {
     this.Item           = sourceItem;
     this.DropItem       = dropItem;
     this.X              = x;
     this.Y              = y;
     this.InsertionIndex = insertionIndex;
     this.InsertionMode  = insertionMode;
 }
        public void ToUnobtrusiveHtmlAttributesWithUpdateTargetIdAndExplicitInsertionMode(InsertionMode mode, string expectedMode)
        {
            // Arrange
            AjaxOptions options = new AjaxOptions
            {
                InsertionMode = mode,
                UpdateTargetId = "someId"
            };

            // Act
            var attributes = options.ToUnobtrusiveHtmlAttributes();

            // Assert
            Assert.Equal(3, attributes.Count);
            Assert.Equal("true", attributes["data-ajax"]);
            Assert.Equal("#someId", attributes["data-ajax-update"]);
            Assert.Equal(expectedMode, attributes["data-ajax-mode"]);
        }
Beispiel #24
0
 public TControl InsertionMode(InsertionMode newValue)
 {
     Context.InsertionMode = newValue;
     return((TControl)this);
 }
Beispiel #25
0
 public CtAjaxOptions SetInsertionMode(InsertionMode mode)
 {
     this.InsertionMode = mode;
     return(this);
 }
Beispiel #26
0
        /// <summary>
        /// Returns a literal object for the text between HtmlStart (the last position of the end of a
        /// tag) and the current position. If !AllowLiterals then it's wrapped in a span.
        /// </summary>
        ///
        /// <param name="factory">
        /// The HTML factory to operate against
        /// </param>
        /// <param name="literal">
        /// [out] The literal.
        /// </param>
        ///
        /// <returns>
        /// true if it succeeds, false if it fails.
        /// </returns>

        public bool TryGetLiteral(HtmlElementFactory factory, out IDomObject literal)
        {


            if (Pos <= HtmlStart)
            {
                literal = null;
                return false;
            }

            // There's plain text -return it as a literal.
            
            DomText lit;
            switch(InsertionMode) {
                case InsertionMode.Invalid:
                    lit = new DomInvalidElement();
                    break;
                case InsertionMode.Text:
                    InsertionMode =InsertionMode.Default;
                    lit = new DomInnerText();
                    break;
                default:
                    lit = new DomText();
                    break;
            }
            literal = lit;

            if (factory.IsBound)
            {
                lit.SetTextIndex(factory.Document, factory.Document.DocumentIndex.TokenizeString(HtmlStart, Pos - HtmlStart));
            }
            else
            {
                string text = factory.Html.SubstringBetween(HtmlStart, Pos);
                literal.NodeValue = HtmlData.HtmlDecode(text);
            }

            if (WrapLiterals)
            {
                DomElement wrapper = DomElement.Create("span");
                wrapper.ChildNodesInternal.AddAlways(literal);
                literal = wrapper;
            }
        

            if (Parent != null)
            {
                ((DomElement)Parent.Element).ChildNodesInternal.AddAlways(literal);
                Reset();
                return false;
            }
            else
            {
                TokenizerState = TokenizerState.Finished;
                return true;
            }
        }
 private CurrentTokenizerTokenState UseTheRulesFor(InsertionMode insertionMode)
 {
     // FIXME: This algorithm can't work if processing the token implies processing other tokens as well
     InsertionMode previousInsertionMode = _insertionMode;
     _insertionMode = insertionMode;
     CurrentTokenizerTokenState state;
     do {
         state = ParseToken();
     } while (state == CurrentTokenizerTokenState.Unprocessed);
     if (_insertionMode == insertionMode) {
         _insertionMode = previousInsertionMode;
     }
     return state;
 }
 public InputRangeSetup WithMode(InsertionMode mode)
 {
     Mode = mode;
     return(this);
 }
Beispiel #29
0
 public AjaxCompanyContracotrEditModel(T model, bool readOnly, string controller, string action, InsertionMode insertionMode, string dialogElementId, string gridElementId, int idFirmy, int idKontrahenta)
     : base(model, readOnly, controller, action, insertionMode, dialogElementId, gridElementId, idFirmy)
 {
     IdKontrahenta = idKontrahenta;
 }
Beispiel #30
0
 public AjaxCompanyEditModel(T model, bool readOnly, string controller, string action, InsertionMode insertionMode, string dialogElementId, string gridElementId, int idFirmy)
     : base(model, readOnly, controller, action, insertionMode, dialogElementId, gridElementId)
 {
     IdFirmy = idFirmy;
 }
		/// <summary>
		/// Inserts a new comment node either before or after the 
		/// currently selected node.
		/// </summary>
		void InsertComment(XmlComment comment, InsertionMode insertionMode)
		{
			ExtTreeNode selectedNode = (ExtTreeNode)SelectedNode;
			if (selectedNode != null) {
				ExtTreeNode parentNode = (ExtTreeNode)selectedNode.Parent;
				XmlCommentTreeNode newNode = new XmlCommentTreeNode(comment);
				int index = 0;
				if (parentNode != null) {
					index = parentNode.Nodes.IndexOf(selectedNode);
				} else {
					index = Nodes.IndexOf(selectedNode);
				}
				if (insertionMode == InsertionMode.After) {
					index++;
				}
				if (parentNode != null) {
					newNode.Insert(index, parentNode);
				} else {
					newNode.Insert(index, this);
				}
			}
		}
Beispiel #32
0
        public DOMParser(HtmlDocument document, bool logging = false)
        {
            _document = document;
            _InsertionMode = InsertionMode.Initial;
            _openElements = new StackOpenElements();
            _attributes = new List<HtmlAttribute>();
            _content = new StringBuilder();
            _tokenType = TokenType.Usual;
            _declarationType = DeclarationType.Comment;
            Errors = new List<ParseError>();
            _openFormattingElements = new FormattedElementsList(_openElements);
            _tokenIndex = 0;
            _logging = logging;

            InitActionMaps();

            StartConstruction();
        }
 internal static string InsertionModeToString(InsertionMode insertionMode) {
     switch (insertionMode) {
         case InsertionMode.Replace:
             return "Sys.Mvc.InsertionMode.replace";
         case InsertionMode.InsertBefore:
             return "Sys.Mvc.InsertionMode.insertBefore";
         case InsertionMode.InsertAfter:
             return "Sys.Mvc.InsertionMode.insertAfter";
         default:
             return ((int)insertionMode).ToString(CultureInfo.InvariantCulture);
     }
 }
Beispiel #34
0
 public AjaxContext(WebRequest request, DOMElement updateTarget, DOMElement loadingElement, InsertionMode insertionMode) {
     _request = request;
     _updateTarget = updateTarget;
     _loadingElement = loadingElement;
     _insertionMode = insertionMode;
 }
 public static void UpdateDomElement(DOMElement target, InsertionMode insertionMode, string content) {
     if (target != null) {
         switch (insertionMode) {
             case InsertionMode.Replace:
                 target.InnerHTML = content;
                 break;
             case InsertionMode.InsertBefore:
                 if (content != null && content.Length > 0) {
                     // Trimming here may be a bit too aggressive.  It is done to make behavior consistent across
                     // browsers (since IE normalizes whitespace BEFORE building its internal data structures).
                     // However, it may end up trimming whitespace left intentionally by the developer.
                     target.InnerHTML = content + target.InnerHTML.TrimStart();
                 }
                 break;
             case InsertionMode.InsertAfter:
                 if (content != null && content.Length > 0) {
                     // See comment for InsertBefore re: Trimming
                     target.InnerHTML = target.InnerHTML.TrimEnd() + content;
                 }
                 break;
         }
     }
 }