Exemplo n.º 1
0
        /// <summary>
        /// Inserts new HTML elements specified by the given HTML string at
        /// a position relative to the current element specified by the position.
        /// </summary>
        /// <param name="position">The relation to the current element.</param>
        /// <param name="html">The HTML code to generate elements for.</param>
        public void Insert(AdjacentPosition position, String html)
        {
            var useThis    = position == AdjacentPosition.BeforeBegin || position == AdjacentPosition.AfterEnd;
            var nodeParent = useThis ? this : Parent as Element;
            var nodes      = new DocumentFragment(html, nodeParent);

            switch (position)
            {
            case AdjacentPosition.BeforeBegin:
                Parent.InsertBefore(nodes, this);
                break;

            case AdjacentPosition.AfterEnd:
                Parent.InsertChild(Parent.IndexOf(this) + 1, nodes);
                break;

            case AdjacentPosition.AfterBegin:
                InsertChild(0, nodes);
                break;

            case AdjacentPosition.BeforeEnd:
                AppendChild(nodes);
                break;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Runs the mutation macro as defined in 5.2.2 Mutation methods
        /// of http://www.w3.org/TR/domcore/.
        /// </summary>
        /// <param name="nodes">The nodes array to add.</param>
        /// <returns>A (single) node.</returns>
        protected Node MutationMacro(Node[] nodes)
        {
            if (nodes.Length > 1)
            {
                var node = new DocumentFragment();

                for (int i = 0; i < nodes.Length; i++)
                {
                    node.AppendChild(nodes[i]);
                }

                return(node);
            }

            return(nodes[0]);
        }
Exemplo n.º 3
0
        public void insertAdjacentHTML(AdjacentPosition position, String html)
        {
            var nodeParent = position == AdjacentPosition.BeforeBegin || position == AdjacentPosition.AfterEnd ? this : _parent;
            var nodes      = new DocumentFragment(DocumentBuilder.HtmlFragment(html, nodeParent));

            switch (position)
            {
            case AdjacentPosition.BeforeBegin:
                ParentNode.InsertBefore(nodes, this);
                break;

            case AdjacentPosition.AfterEnd:
                ParentNode.InsertChild(ParentNode.IndexOf(this) + 1, nodes);
                break;

            case AdjacentPosition.AfterBegin:
                InsertChild(0, nodes);
                break;

            case AdjacentPosition.BeforeEnd:
                AppendChild(nodes);
                break;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Runs the mutation macro as defined in 5.2.2 Mutation methods
        /// of http://www.w3.org/TR/domcore/.
        /// </summary>
        /// <param name="nodes">The nodes array to add.</param>
        /// <returns>A (single) node.</returns>
        protected Node MutationMacro(Node[] nodes)
        {
            if (nodes.Length > 1)
            {
                var node = new DocumentFragment();

                for (int i = 0; i < nodes.Length; i++)
                    node.AppendChild(nodes[i]);

                return node;
            }

            return nodes[0];
        }
Exemplo n.º 5
0
        /// <summary>
        /// Inserts new HTML elements specified by the given HTML string at
        /// a position relative to the current element specified by the position.
        /// </summary>
        /// <param name="position">The relation to the current element.</param>
        /// <param name="html">The HTML code to generate elements for.</param>
        public void Insert(AdjacentPosition position, String html)
        {
            var useThis = position == AdjacentPosition.BeforeBegin || position == AdjacentPosition.AfterEnd;
            var nodeParent = useThis ? this : Parent as Element;
            var nodes = new DocumentFragment(html, nodeParent);

            switch (position)
            {
                case AdjacentPosition.BeforeBegin:
                    Parent.InsertBefore(nodes, this);
                    break;

                case AdjacentPosition.AfterEnd:
                    Parent.InsertChild(Parent.IndexOf(this) + 1, nodes);
                    break;

                case AdjacentPosition.AfterBegin:
                    InsertChild(0, nodes);
                    break;

                case AdjacentPosition.BeforeEnd:
                    AppendChild(nodes);
                    break;
            }
        }