From 648ee61ae84216d0236e0dbc211addc13b2cfa3a Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Fri, 6 Jul 2012 11:52:06 -0700 Subject: Expand tabs --- js/lib/NJUtils.js | 102 +++++++++++++++++++++++++++--------------------------- 1 file changed, 51 insertions(+), 51 deletions(-) (limited to 'js/lib/NJUtils.js') diff --git a/js/lib/NJUtils.js b/js/lib/NJUtils.js index 1406ad98..e924e1b8 100755 --- a/js/lib/NJUtils.js +++ b/js/lib/NJUtils.js @@ -65,9 +65,9 @@ exports.NJUtils = Montage.create(Component, { children : { value : function(el, filter) { var f = filter || function(item) { - return item.nodeType === 1; - }; - return this.toArray(el.childNodes).filter(f); + return item.nodeType === 1; + }; + return this.toArray(el.childNodes).filter(f); } }, @@ -185,54 +185,54 @@ exports.NJUtils = Montage.create(Component, { }, queryParentSelector : { - value: function(el, strSelector) { - // queryParentSelector: - // Given a DOM element el (required), walk up the DOM tree - // and find the first parent that matches selector strSelector (required). - // Returns: The element that matches, or false if there is no match - // or if insufficient parameters are supplied. - - if ((typeof(el) === "undefined") || (typeof(strSelector) === "undefined")) { - // Parameters are required, m'kay? - return false; - } else if ((typeof(el) !== "object") || (typeof(strSelector) !== "string" )) { - // You also have to use the right parameters. - return false; - } - - // First, get an empty clone of the parent. - var myParent = el.parentNode; - var clone = myParent.cloneNode(false); - if (clone === null) { - return false; - } - - // If we're at the top of the DOM, our clone will be an htmlDocument. - // htmlDocument has no tagName. - if (typeof(clone.tagName) !== "undefined") { - // create a bogus div to use as a base for querySelector - var temp = document.createElement("div"); - - // Append the clone to the bogus div - temp.appendChild(clone); - - // Now we can use querySelector! Sweet. - var selectorTest = temp.querySelector(strSelector); - - // What has querySelector returned? - if (selectorTest === null) { - // No match, so recurse. - return this.queryParentSelector(myParent, strSelector); - } else { - // Match! Return the element. - return myParent; - } - } else { - // We're at the top of the DOM so we're done. - return false; - } - } - + value: function(el, strSelector) { + // queryParentSelector: + // Given a DOM element el (required), walk up the DOM tree + // and find the first parent that matches selector strSelector (required). + // Returns: The element that matches, or false if there is no match + // or if insufficient parameters are supplied. + + if ((typeof(el) === "undefined") || (typeof(strSelector) === "undefined")) { + // Parameters are required, m'kay? + return false; + } else if ((typeof(el) !== "object") || (typeof(strSelector) !== "string" )) { + // You also have to use the right parameters. + return false; + } + + // First, get an empty clone of the parent. + var myParent = el.parentNode; + var clone = myParent.cloneNode(false); + if (clone === null) { + return false; + } + + // If we're at the top of the DOM, our clone will be an htmlDocument. + // htmlDocument has no tagName. + if (typeof(clone.tagName) !== "undefined") { + // create a bogus div to use as a base for querySelector + var temp = document.createElement("div"); + + // Append the clone to the bogus div + temp.appendChild(clone); + + // Now we can use querySelector! Sweet. + var selectorTest = temp.querySelector(strSelector); + + // What has querySelector returned? + if (selectorTest === null) { + // No match, so recurse. + return this.queryParentSelector(myParent, strSelector); + } else { + // Match! Return the element. + return myParent; + } + } else { + // We're at the top of the DOM so we're done. + return false; + } + } + }, // Returns the numerical value and unit string from a string. -- cgit v1.2.3