Ejemplo n.º 1
0
        public static TNode AsNode <TNode>(this INodeConvertible <TNode> e)
        //where TNode : INode

        // we are talking about dom nodes
            where TNode : IHTMLElement
        {
            if (e == null)
            {
                return(null);
            }

            // will this work?
            // jsc needs to maintain a dispatch vtable for all native objects for which we want to add and extend interfaces.
            var xWebGLRenderingContext = e as ScriptCoreLib.JavaScript.WebGL.WebGLRenderingContext;

            if (xWebGLRenderingContext != null)
            {
                //return xWebGLRenderingContext.InternalAsNode();
                // hack. inline that method for now..
                return((TNode)(IHTMLElement)xWebGLRenderingContext.canvas);
            }

            var n = e.as_INode();

            if (n != null)
            {
                return((TNode)n);
            }


            return(e.InternalAsNode());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// detaches the node from dom; should be renamed to Orphanize
        /// </summary>
        //[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)
        //, ObsoleteAttribute("", false)
        //]
        //public static T Dispose<T>(this T e)
        //    where T : INode
        //{
        //    return e.Orphanize();
        //}



        public static void Clear(this INodeConvertible <IHTMLElement> ee)
        {
            var e = ee.AsNode();

            var p = e.firstChild;

            while (p != null)
            {
                e.removeChild(p);
                p = e.firstChild;
            }
        }
Ejemplo n.º 3
0
        public static void ReplaceWith(this INodeConvertible <IHTMLElement> ee, INodeConvertible <IHTMLElement> evalue)
        {
            // unless its from vb
            // then it could be just a number coming in...
            // Z:\jsc.svn\examples\javascript\vb\LEST97\LEST97\Application.vb

            var e     = ee.AsNode();
            var value = evalue.AsNode();

            // http://msdn.microsoft.com/en-us/library/system.xml.linq.xnode.replacewith.aspx

            if (e.parentNode == null)
            {
                return;
            }

            // tested by
            // X:\jsc.svn\examples\javascript\appengine\RemainingMillisExperiment\RemainingMillisExperiment\Application.cs
            // X:\jsc.svn\examples\javascript\svg\SVGNavigationTiming\SVGNavigationTiming\Application.cs


            var old = e.attributes.Select(x => new { x.name, x.value }).ToArray();

            var old_id = ((IHTMLElement)e).id;

            e.parentNode.replaceChild(value, e);


            // merge attributes
            foreach (var item in old)
            {
                if (!value.hasAttribute(item.name))
                {
                    value.setAttribute(item.name, item.value);
                }
            }

            if (!string.IsNullOrEmpty(old_id))
            {
                //((IHTMLElement)value).id = old_id;

                // we just swapped out id's. make the old element forget its id
                e.id = "";
            }
        }
Ejemplo n.º 4
0
 public static IHTMLCanvas AsCanvas(this INodeConvertible <IHTMLDiv> l)
 {
     // X:\jsc.svn\examples\javascript\canvas\AsCanvasExperiment\AsCanvasExperiment\Application.cs
     return((IHTMLCanvas)l.AsNode());
 }
Ejemplo n.º 5
0
 public static IEnumerable <IHTMLImage> ImageElements(this INodeConvertible <IHTMLElement> e)
 {
     return(e.AsNode().querySelectorAll(IHTMLElement.HTMLElementEnum.img).Select(k => (IHTMLImage)k));
 }
Ejemplo n.º 6
0
 public static IEnumerable <IHTMLAudio> AudioElements(this INodeConvertible <IHTMLElement> e)
 {
     return(e.AsNode().querySelectorAll(IHTMLElement.HTMLElementEnum.audio).Select(k => (IHTMLAudio)k));
 }