示例#1
0
        private JsArray <HtmlElement> findChildNodesForSelector(JsArray <HtmlElement> elements, JsArray <JsString> selectorArray)
        {
            var selector = selectorArray.shift();

            //We need to actually abstract this so we can deal with IE and Opera returning a collection instead of a NodeList

            var newElements = new JsArray <HtmlElement>();

            if (selector.substr(0, 1) == ".")
            {
                var className = selector.substring(1);
                //Lets assume this is a class selector
                while (elements.length > 0)
                {
                    var element = elements.pop();
                    var nodes   = element.getElementsByClassName(className);
                    for (var j = 0; j < nodes.length; j++)
                    {
                        newElements.push(nodes[j].As <HtmlElement>());
                    }
                }
            }
            else
            {
                //invalid but going to assume type for now
                while (elements.length > 0)
                {
                    var element = elements.pop();
                    var nodes   = element.getElementsByTagName(selector);

                    for (var j = 0; j < nodes.length; j++)
                    {
                        newElements.push(nodes[j].As <HtmlElement>());
                    }
                }
            }

            //Only recurse if there is another selector
            if (selectorArray.length > 0)
            {
                newElements = findChildNodesForSelector(newElements, selectorArray);
            }

            return(newElements);
        }
        private JsArray<HtmlElement> findChildNodesForSelector(JsArray<HtmlElement> elements, JsArray<JsString> selectorArray)
        {
            var selector = selectorArray.shift();

            //We need to actually abstract this so we can deal with IE and Opera returning a collection instead of a NodeList

            var newElements = new JsArray<HtmlElement>();

            if ( selector.substr( 0, 1 ) == "." ) {
                var className = selector.substring( 1 );
                //Lets assume this is a class selector
                while ( elements.length > 0 ) {
                    var element = elements.pop();
                    var nodes = element.getElementsByClassName( className );
                    for ( var j=0; j<nodes.length; j++) {
                        newElements.push( nodes[ j ].As<HtmlElement>() );
                    }
                }

            } else {
                //invalid but going to assume type for now
                while (elements.length > 0) {
                    var element = elements.pop();
                    var nodes = element.getElementsByTagName(selector);

                    for (var j = 0; j < nodes.length; j++) {
                        newElements.push( nodes[j].As<HtmlElement>() );
                    }
                }
            }

            //Only recurse if there is another selector
            if (selectorArray.length > 0) {
                newElements = findChildNodesForSelector(newElements, selectorArray);
            }

            return newElements;
        }
示例#3
0
 public T Dequeue()
 {
     return(storage.shift().As <T>());
 }