[Pkg-javascript-commits] [dojo] 16/149: Squashed commit of the following:

David Prévot taffit at moszumanska.debian.org
Sat Feb 27 03:13:42 UTC 2016


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository dojo.

commit d0386bc5f10dbc1c76a79b5c1e640288c8e578c0
Author: Eduardo Matos <eduardo.matos.silva at gmail.com>
Date:   Wed Sep 3 17:14:35 2014 -0600

    Squashed commit of the following:
    
    commit b40a3a75b684be132046915af321de89191c1a7a
    Author: Eduardo Matos <eduardo.matos at blive-ti.com.br>
    Date:   Thu May 29 09:45:29 2014 -0300
    
        remove unnecessary console.log
    
    commit b68828fe53dc09fba5f4c565ff134d82b074e35c
    Author: Eduardo Matos <eduardo.matos at blive-ti.com.br>
    Date:   Thu May 29 08:28:54 2014 -0300
    
        fix regression tests on ie8
    
    commit e8553dae947744bb7e0d6991cb46bc9d8d31027f
    Author: Eduardo Matos <eduardo.matos at blive-ti.com.br>
    Date:   Thu May 15 10:52:31 2014 -0300
    
        use 'array.some' instead of 'for' loop
    
    commit 6c250e436e02cebc39201ac9592a9b083d5646b1
    Author: Eduardo Matos <eduardo.matos at blive-ti.com.br>
    Date:   Thu May 15 10:43:24 2014 -0300
    
        cross browser get all child nodes recursively
    
    commit ad40ac8707fc225747f817c797f29b0f714ba284
    Author: Eduardo Matos <eduardo.matos at blive-ti.com.br>
    Date:   Thu May 15 09:33:01 2014 -0300
    
        avoid error on internet explorer
    
        internet explorer doesn't support the 'contains'
        method on the document object.
        solution: verify if root(element) has parent and is not
        the document itself
    
    commit c278faaa0803dc74ae5a6bfbad8265f56428fe08
    Author: Eduardo Matos <eduardo.matos.silva at gmail.com>
    Date:   Tue May 13 22:43:49 2014 -0300
    
        allow id lookup on document fragment
    
    commit d5f5bad40febdaacaaecac1a6d031b44292732aa
    Author: Eduardo Matos <eduardo.matos.silva at gmail.com>
    Date:   Tue May 13 22:21:10 2014 -0300
    
        allow id lookup on detached nodes
---
 selector/acme.js             | 50 ++++++++++++++++++++++++++++++++++++++++++--
 selector/lite.js             |  6 +++++-
 tests/query/query.html       | 19 +++++++++++++++--
 tests/query/queryQuirks.html | 25 ++++++++++++++++++++--
 4 files changed, 93 insertions(+), 7 deletions(-)

diff --git a/selector/acme.js b/selector/acme.js
index 8fd3c95..b8d77ab 100644
--- a/selector/acme.js
+++ b/selector/acme.js
@@ -816,11 +816,37 @@ define([
 	};
 
 	// get an array of child *elements*, skipping text and comment nodes
-	var _childElements = function(filterFunc){
+	var _childElements = function(filterFunc, recursive){
+
+		var _toArray = function (iterable) {
+			var result = [];
+
+			try {
+				result = Array.prototype.slice.call(iterable);
+			} catch(e) {
+				// IE8- throws an error when we try convert HTMLCollection
+				// to array using Array.prototype.slice.call
+				for(var i = 0, len = iterable.length; i < len; i++) {
+					result.push(iterable[i]);
+				}
+			}
+
+			return result;
+		};
+
 		filterFunc = filterFunc||yesman;
 		return function(root, ret, bag){
 			// get an array of child elements, skipping text and comment nodes
-			var te, x = 0, tret = root.children || root.childNodes;
+			var te, x = 0, tret = []; tret = _toArray(root.children || root.childNodes);
+
+			if(recursive) {
+				array.forEach(tret, function (node) {
+					if(node.nodeType === 1) {
+						tret = tret.concat(_toArray(node.getElementsByTagName("*")));
+					}
+				});
+			}
+
 			while(te = tret[x++]){
 				if(
 					_simpleNodeTest(te) &&
@@ -928,6 +954,26 @@ define([
 
 				retFunc = function(root, arr){
 					var te = dom.byId(query.id, (root.ownerDocument||root));
+
+					// We can't look for ID inside a detached dom.
+					// loop over all elements searching for specified id.
+					if(root.ownerDocument && !_isDescendant(root, root.ownerDocument)) {
+
+						// document-fragment or regular HTMLElement
+						var roots = root.nodeType === 11? root.childNodes: [root];
+
+						array.some(roots, function (currentRoot) {
+							var elems = _childElements(function (node) {
+								return node.id === query.id;
+							}, true)(currentRoot, []);
+
+							if(elems.length) {
+								te = elems[0];
+								return false;
+							}
+						});
+					}
+
 					if(!te || !filterFunc(te)){ return; }
 					if(9 == root.nodeType){ // if root's a doc, we just return directly
 						return getArr(te, arr);
diff --git a/selector/lite.js b/selector/lite.js
index 6dc4118..c35aa65 100644
--- a/selector/lite.js
+++ b/selector/lite.js
@@ -29,8 +29,12 @@ var liteEngine = function(selector, root){
 			.exec(selector);
 	root = root || doc;
 	if(match){
+		var isInsideDomTree = has('ie') === 8 && has('quirks')?
+			root.nodeType === doc.nodeType:
+			root.parentNode !== null && root.nodeType !== 9 && root.parentNode === doc;
+
 		// fast path regardless of whether or not querySelectorAll exists
-		if(match[2]){
+		if(match[2] && isInsideDomTree){
 			// an #id
 			// use dojo.byId if available as it fixes the id retrieval in IE, note that we can't use the dojo namespace in 2.0, but if there is a conditional module use, we will use that
 			var found = dojo.byId ? dojo.byId(match[2], doc) : doc.getElementById(match[2]);
diff --git a/tests/query/query.html b/tests/query/query.html
index 592f1ad..f65a9b2 100644
--- a/tests/query/query.html
+++ b/tests/query/query.html
@@ -12,8 +12,8 @@
 			var selector = specified ? specified[0].split("=")[1] : "acme";
 
 			require(["doh", "dojo/_base/array", "dojo/dom", "dojo/request/iframe",
-				"dojo/query!"+selector, "dojo/NodeList", "dojo/sniff", "dojo/domReady!"],
-					function(doh, array, dom, iframe, dq, NodeList, has){
+				"dojo/query!"+selector, "dojo/NodeList", "dojo/sniff", "dojo/dom-construct", "dojo/domReady!"],
+					function(doh, array, dom, iframe, dq, NodeList, has, domConstruct){
 				query = dq; // make a global
 
 				function createDocument(xml){
@@ -236,6 +236,21 @@
 						var i = query("div");
 						// smoke test
 						i.sort(function(a,b){ return 1; })
+					},
+					function document_fragment() {
+						var detachedDom = domConstruct.toDom("<i><u><a></a><b id='b'></b></u></i>");
+						var documentFragment = domConstruct.toDom("<i></i>    <u><a></a><b id='b'></b></u>");
+
+						doh.is(1, query("#b", detachedDom).length);
+						doh.is(1, query("#b", detachedDom.firstChild).length);
+						doh.is(1, query("#b", documentFragment).length);
+						doh.is(1, query("#b", documentFragment.childNodes[2]).length);
+
+						var detachedDom2 = domConstruct.toDom("<i><u><a></a><b></b></u></i>");
+						var documentFragment2 = domConstruct.toDom("<i></i>    <u><a></a><b></b></u>");
+
+						doh.is(0, query("#b", detachedDom2).length);
+						doh.is(0, query("#b", documentFragment2).length);
 					}
 				]);
 
diff --git a/tests/query/queryQuirks.html b/tests/query/queryQuirks.html
index 8612e35..749249d 100644
--- a/tests/query/queryQuirks.html
+++ b/tests/query/queryQuirks.html
@@ -10,8 +10,8 @@
 			var specified = window.location.search.substr(1).match(/selector=(.*)/);
 			var selector = specified ? specified[0].split("=")[1] : "acme";
 
-			require(["dojo", "doh", "dojo/query!"+selector, "dojo/sniff", "dojo/io/iframe", "dojo/domReady!"],
-					function(dojo, doh, dq, has){
+			require(["dojo", "doh", "dojo/query!"+selector, "dojo/sniff", "dojo/dom-construct", "dojo/io/iframe", "dojo/domReady!"],
+					function(dojo, doh, dq, has, domConstruct){
 				query = dq; // make a global
 
 				function createDocument(xml){
@@ -219,6 +219,27 @@
 						var i = query("div");
 						// smoke test
 						i.sort(function(a,b){ return 1; })
+					},
+					function document_fragment() {
+						var detachedDom = domConstruct.toDom("<i><u><a></a><b id='b'></b></u></i>");
+						var documentFragment = domConstruct.toDom("<i></i>    <u><a></a><b id='b'></b></u>");
+
+						doh.is(1, query("#b", detachedDom).length);
+						doh.is(1, query("#b", detachedDom.firstChild).length);
+						doh.is(1, query("#b", documentFragment).length);
+
+						// In IE8 in quirks mode there is no text node on the document fragment
+						if(has('ie') === 8) {
+							doh.is(1, query("#b", documentFragment.childNodes[1]).length);
+						} else {
+							doh.is(1, query("#b", documentFragment.childNodes[2]).length);
+						}
+
+						var detachedDom2 = domConstruct.toDom("<i><u><a></a><b></b></u></i>");
+						var documentFragment2 = domConstruct.toDom("<i></i>    <u><a></a><b></b></u>");
+
+						doh.is(0, query("#b", detachedDom2).length);
+						doh.is(0, query("#b", documentFragment2).length);
 					}
 				]);
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/dojo.git



More information about the Pkg-javascript-commits mailing list