[Pkg-javascript-commits] [dojo] 124/149: fixes #14629, feature test to use native contains
David Prévot
taffit at moszumanska.debian.org
Sat Feb 27 03:13:55 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 13aa0fcc89d4433f376f6b329408b4efdb55ff7b
Author: Dylan Schiemann <dylan at dojotoolkit.org>
Date: Fri Jan 1 08:33:18 2016 -0700
fixes #14629, feature test to use native contains
---
dom.js | 62 +++++++++++++++++++++++++++++++++++---------------------------
1 file changed, 35 insertions(+), 27 deletions(-)
diff --git a/dom.js b/dom.js
index 0d0ffa3..7cae0eb 100644
--- a/dom.js
+++ b/dom.js
@@ -92,33 +92,41 @@ define(["./sniff", "./_base/window"],
};
=====*/
- dom.isDescendant = function(/*DOMNode|String*/ node, /*DOMNode|String*/ ancestor){
- // summary:
- // Returns true if node is a descendant of ancestor
- // node: DOMNode|String
- // string id or node reference to test
- // ancestor: DOMNode|String
- // string id or node reference of potential parent to test against
- //
- // example:
- // Test is node id="bar" is a descendant of node id="foo"
- // | require(["dojo/dom"], function(dom){
- // | if(dom.isDescendant("bar", "foo")){ ... }
- // | });
-
- try{
- node = dom.byId(node);
- ancestor = dom.byId(ancestor);
- while(node){
- if(node == ancestor){
- return true; // Boolean
+ // Test for DOMNode.contains() method, available everywhere except FF8-
+ // and IE8-, where it's available in general, but not on document itself,
+ // and also problems when either ancestor or node are text nodes.
+ has.add("dom-contains", !!document.contains);
+ dom.isDescendant = has("dom-contains") ?
+ // FF9+, IE9+, webkit, opera, iOS, Android, Edge, etc.
+ function(/*DOMNode|String*/ node, /*DOMNode|String*/ ancestor){
+ return !!( (ancestor = dom.byId(ancestor)) && ancestor.contains(dom.byId(node)) );
+ } :
+ function(/*DOMNode|String*/ node, /*DOMNode|String*/ ancestor){
+ // summary:
+ // Returns true if node is a descendant of ancestor
+ // node: DOMNode|String
+ // string id or node reference to test
+ // ancestor: DOMNode|String
+ // string id or node reference of potential parent to test against
+ //
+ // example:
+ // Test is node id="bar" is a descendant of node id="foo"
+ // | require(["dojo/dom"], function(dom){
+ // | if(dom.isDescendant("bar", "foo")){ ... }
+ // | });
+
+ try{
+ node = dom.byId(node);
+ ancestor = dom.byId(ancestor);
+ while(node){
+ if(node == ancestor){
+ return true; // Boolean
+ }
+ node = node.parentNode;
}
- node = node.parentNode;
- }
- }catch(e){ /* squelch, return false */ }
- return false; // Boolean
- };
-
+ }catch(e){ /* squelch, return false */ }
+ return false; // Boolean
+ };
// TODO: do we need setSelectable in the base?
@@ -132,7 +140,7 @@ define(["./sniff", "./_base/window"],
has.add("css-user-select", function(global, doc, element){
// Avoid exception when dom.js is loaded in non-browser environments
if(!element){ return false; }
-
+
var style = element.style;
var prefixes = ["Khtml", "O", "Moz", "Webkit"],
i = prefixes.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