From a089699c8915636ba4f158d77dba9b012bc93208 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 4 Mar 2011 19:02:28 +0300 Subject: build custom layer of Dojo to speed up loading of tt-rss (refs #293) --- lib/dojo/NodeList-traverse.js | 628 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 507 insertions(+), 121 deletions(-) (limited to 'lib/dojo/NodeList-traverse.js') diff --git a/lib/dojo/NodeList-traverse.js b/lib/dojo/NodeList-traverse.js index 4fda2e7ea..b5314eed6 100644 --- a/lib/dojo/NodeList-traverse.js +++ b/lib/dojo/NodeList-traverse.js @@ -5,127 +5,513 @@ */ -if(!dojo._hasResource["dojo.NodeList-traverse"]){ -dojo._hasResource["dojo.NodeList-traverse"]=true; +if(!dojo._hasResource["dojo.NodeList-traverse"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojo.NodeList-traverse"] = true; dojo.provide("dojo.NodeList-traverse"); -dojo.extend(dojo.NodeList,{_buildArrayFromCallback:function(_1){ -var _2=[]; -for(var i=0;i + // |
Red One
+ // | Some Text + // |
Blue One
+ // |
Red Two
+ // |
Blue Two
+ // | + // Running this code: + // | dojo.query(".container").children(); + // returns the four divs that are children of the container div. + // Running this code: + // | dojo.query(".container").children(".red"); + // returns the two divs that have the class "red". + return this._getRelatedUniqueNodes(query, function(node, ary){ + return dojo._toArray(node.childNodes); + }); //dojo.NodeList + }, + + closest: function(/*String*/query){ + // summary: + // Returns closest parent that matches query, including current node in this + // dojo.NodeList if it matches the query. + // description: + // .end() can be used on the returned dojo.NodeList to get back to the + // original dojo.NodeList. + // query: + // a CSS selector. + // returns: + // dojo.NodeList, the closest parent that matches the query, including the current + // node in this dojo.NodeList if it matches the query. + // example: + // assume a DOM created by this markup: + // |
+ // |
Red One
+ // | Some Text + // |
Blue One
+ // |
Red Two
+ // |
Blue Two
+ // |
+ // Running this code: + // | dojo.query(".red").closest(".container"); + // returns the div with class "container". + var self = this; + return this._getRelatedUniqueNodes(query, function(node, ary){ + do{ + if(self._filterQueryResult([node], query).length){ + return node; + } + }while((node = node.parentNode) && node.nodeType == 1); + return null; //To make rhino strict checking happy. + }); //dojo.NodeList + }, + + parent: function(/*String?*/query){ + // summary: + // Returns immediate parent elements for nodes in this dojo.NodeList. + // Optionally takes a query to filter the parent elements. + // description: + // .end() can be used on the returned dojo.NodeList to get back to the + // original dojo.NodeList. + // query: + // a CSS selector. + // returns: + // dojo.NodeList, immediate parent elements for nodes in this dojo.NodeList. + // example: + // assume a DOM created by this markup: + // |
+ // |
Red One
+ // |
Blue One
+ // |
Red Two
+ // |
Blue Two
+ // |
+ // Running this code: + // | dojo.query(".text").parent(); + // returns the two divs with class "blue". + // Running this code: + // | dojo.query(".text").parent(".first"); + // returns the one div with class "blue" and "first". + return this._getRelatedUniqueNodes(query, function(node, ary){ + return node.parentNode; + }); //dojo.NodeList + }, + + parents: function(/*String?*/query){ + // summary: + // Returns all parent elements for nodes in this dojo.NodeList. + // Optionally takes a query to filter the child elements. + // description: + // .end() can be used on the returned dojo.NodeList to get back to the + // original dojo.NodeList. + // query: + // a CSS selector. + // returns: + // dojo.NodeList, all parent elements for nodes in this dojo.NodeList. + // example: + // assume a DOM created by this markup: + // |
+ // |
Red One
+ // |
Blue One
+ // |
Red Two
+ // |
Blue Two
+ // |
+ // Running this code: + // | dojo.query(".text").parents(); + // returns the two divs with class "blue", the div with class "container", + // | the body element and the html element. + // Running this code: + // | dojo.query(".text").parents(".container"); + // returns the one div with class "container". + return this._getRelatedUniqueNodes(query, function(node, ary){ + var pary = [] + while(node.parentNode){ + node = node.parentNode; + pary.push(node); + } + return pary; + }); //dojo.NodeList + }, + + siblings: function(/*String?*/query){ + // summary: + // Returns all sibling elements for nodes in this dojo.NodeList. + // Optionally takes a query to filter the sibling elements. + // description: + // .end() can be used on the returned dojo.NodeList to get back to the + // original dojo.NodeList. + // query: + // a CSS selector. + // returns: + // dojo.NodeList, all sibling elements for nodes in this dojo.NodeList. + // example: + // assume a DOM created by this markup: + // |
+ // |
Red One
+ // | Some Text + // |
Blue One
+ // |
Red Two
+ // |
Blue Two
+ // |
+ // Running this code: + // | dojo.query(".first").siblings(); + // returns the two divs with class "red" and the other div + // | with class "blue" that does not have "first". + // Running this code: + // | dojo.query(".first").siblings(".red"); + // returns the two div with class "red". + return this._getRelatedUniqueNodes(query, function(node, ary){ + var pary = [] + var nodes = (node.parentNode && node.parentNode.childNodes); + for(var i = 0; i < nodes.length; i++){ + if(nodes[i] != node){ + pary.push(nodes[i]); + } + } + return pary; + }); //dojo.NodeList + }, + + next: function(/*String?*/query){ + // summary: + // Returns the next element for nodes in this dojo.NodeList. + // Optionally takes a query to filter the next elements. + // description: + // .end() can be used on the returned dojo.NodeList to get back to the + // original dojo.NodeList. + // query: + // a CSS selector. + // returns: + // dojo.NodeList, the next element for nodes in this dojo.NodeList. + // example: + // assume a DOM created by this markup: + // |
+ // |
Red One
+ // | Some Text + // |
Blue One
+ // |
Red Two
+ // |
Blue Two
+ // |
+ // Running this code: + // | dojo.query(".first").next(); + // returns the div with class "red" and has innerHTML of "Red Two". + // Running this code: + // | dojo.query(".last").next(".red"); + // does not return any elements. + return this._getRelatedUniqueNodes(query, function(node, ary){ + var next = node.nextSibling; + while(next && next.nodeType != 1){ + next = next.nextSibling; + } + return next; + }); //dojo.NodeList + }, + + nextAll: function(/*String?*/query){ + // summary: + // Returns all sibling elements that come after the nodes in this dojo.NodeList. + // Optionally takes a query to filter the sibling elements. + // description: + // .end() can be used on the returned dojo.NodeList to get back to the + // original dojo.NodeList. + // query: + // a CSS selector. + // returns: + // dojo.NodeList, all sibling elements that come after the nodes in this dojo.NodeList. + // example: + // assume a DOM created by this markup: + // |
+ // |
Red One
+ // | Some Text + // |
Blue One
+ // | + // | + // |
+ // Running this code: + // | dojo.query(".first").nextAll(); + // returns the two divs with class of "next". + // Running this code: + // | dojo.query(".first").nextAll(".red"); + // returns the one div with class "red" and innerHTML "Red Two". + return this._getRelatedUniqueNodes(query, function(node, ary){ + var pary = [] + var next = node; + while((next = next.nextSibling)){ + if(next.nodeType == 1){ + pary.push(next); + } + } + return pary; + }); //dojo.NodeList + }, + + prev: function(/*String?*/query){ + // summary: + // Returns the previous element for nodes in this dojo.NodeList. + // Optionally takes a query to filter the previous elements. + // description: + // .end() can be used on the returned dojo.NodeList to get back to the + // original dojo.NodeList. + // query: + // a CSS selector. + // returns: + // dojo.NodeList, the previous element for nodes in this dojo.NodeList. + // example: + // assume a DOM created by this markup: + // |
+ // |
Red One
+ // | Some Text + // |
Blue One
+ // |
Red Two
+ // |
Blue Two
+ // |
+ // Running this code: + // | dojo.query(".first").prev(); + // returns the div with class "red" and has innerHTML of "Red One". + // Running this code: + // | dojo.query(".first").prev(".blue"); + // does not return any elements. + return this._getRelatedUniqueNodes(query, function(node, ary){ + var prev = node.previousSibling; + while(prev && prev.nodeType != 1){ + prev = prev.previousSibling; + } + return prev; + }); //dojo.NodeList + }, + + prevAll: function(/*String?*/query){ + // summary: + // Returns all sibling elements that come before the nodes in this dojo.NodeList. + // Optionally takes a query to filter the sibling elements. + // description: + // The returned nodes will be in reverse DOM order -- the first node in the list will + // be the node closest to the original node/NodeList. + // .end() can be used on the returned dojo.NodeList to get back to the + // original dojo.NodeList. + // query: + // a CSS selector. + // returns: + // dojo.NodeList, all sibling elements that come before the nodes in this dojo.NodeList. + // example: + // assume a DOM created by this markup: + // |
+ // | + // | Some Text + // | + // |
Red Two
+ // |
Blue Two
+ // |
+ // Running this code: + // | dojo.query(".second").prevAll(); + // returns the two divs with class of "prev". + // Running this code: + // | dojo.query(".first").prevAll(".red"); + // returns the one div with class "red prev" and innerHTML "Red One". + return this._getRelatedUniqueNodes(query, function(node, ary){ + var pary = [] + var prev = node; + while((prev = prev.previousSibling)){ + if(prev.nodeType == 1){ + pary.push(prev); + } + } + return pary; + }); //dojo.NodeList + }, + + andSelf: function(){ + // summary: + // Adds the nodes from the previous dojo.NodeList to the current dojo.NodeList. + // description: + // .end() can be used on the returned dojo.NodeList to get back to the + // original dojo.NodeList. + // returns: + // dojo.NodeList + // example: + // assume a DOM created by this markup: + // |
+ // | + // | Some Text + // | + // |
Red Two
+ // |
Blue Two
+ // |
+ // Running this code: + // | dojo.query(".second").prevAll().andSelf(); + // returns the two divs with class of "prev", as well as the div with class "second". + return this.concat(this._parent); + }, + + //Alternate methods for the :first/:last/:even/:odd pseudos. + first: function(){ + // summary: + // Returns the first node in this dojo.NodeList as a dojo.NodeList. + // description: + // .end() can be used on the returned dojo.NodeList to get back to the + // original dojo.NodeList. + // returns: + // dojo.NodeList, with the first node in this dojo.NodeList + // example: + // assume a DOM created by this markup: + // |
+ // |
Red One
+ // |
Blue One
+ // |
Red Two
+ // |
Blue Two
+ // |
+ // Running this code: + // | dojo.query(".blue").first(); + // returns the div with class "blue" and "first". + return this._wrap(((this[0] && [this[0]]) || []), this); //dojo.NodeList + }, + + last: function(){ + // summary: + // Returns the last node in this dojo.NodeList as a dojo.NodeList. + // description: + // .end() can be used on the returned dojo.NodeList to get back to the + // original dojo.NodeList. + // returns: + // dojo.NodeList, with the last node in this dojo.NodeList + // example: + // assume a DOM created by this markup: + // |
+ // |
Red One
+ // |
Blue One
+ // |
Red Two
+ // |
Blue Two
+ // |
+ // Running this code: + // | dojo.query(".blue").last(); + // returns the last div with class "blue", + return this._wrap((this.length ? [this[this.length - 1]] : []), this); //dojo.NodeList + }, + + even: function(){ + // summary: + // Returns the even nodes in this dojo.NodeList as a dojo.NodeList. + // description: + // .end() can be used on the returned dojo.NodeList to get back to the + // original dojo.NodeList. + // returns: + // dojo.NodeList, with the even nodes in this dojo.NodeList + // example: + // assume a DOM created by this markup: + // |
+ // |
Red One
+ // |
Blue One
+ // |
Red Two
+ // |
Blue Two
+ // |
+ // Running this code: + // | dojo.query(".interior").even(); + // returns the two divs with class "blue" + return this.filter(function(item, i){ + return i % 2 != 0; + }); //dojo.NodeList + }, + + odd: function(){ + // summary: + // Returns the odd nodes in this dojo.NodeList as a dojo.NodeList. + // description: + // .end() can be used on the returned dojo.NodeList to get back to the + // original dojo.NodeList. + // returns: + // dojo.NodeList, with the odd nodes in this dojo.NodeList + // example: + // assume a DOM created by this markup: + // |
+ // |
Red One
+ // |
Blue One
+ // |
Red Two
+ // |
Blue Two
+ // |
+ // Running this code: + // | dojo.query(".interior").odd(); + // returns the two divs with class "red" + return this.filter(function(item, i){ + return i % 2 == 0; + }); //dojo.NodeList + } }); -}}); + } -- cgit v1.2.3