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 From 04343eda8c2f870b0da55cfdc8003c99fe1cc4de Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Fri, 6 Jul 2012 11:53:10 -0700 Subject: Remove trailing spaces --- js/lib/NJUtils.js | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'js/lib/NJUtils.js') diff --git a/js/lib/NJUtils.js b/js/lib/NJUtils.js index e924e1b8..b7cb28e9 100755 --- a/js/lib/NJUtils.js +++ b/js/lib/NJUtils.js @@ -39,7 +39,7 @@ var Montage = require("montage/core/core").Montage, exports.NJUtils = Montage.create(Component, { /* =============== DOM Access ================ */ - + ///// Quick "getElementById" $ : { value: function(id, doc) { @@ -47,7 +47,7 @@ exports.NJUtils = Montage.create(Component, { return doc.getElementById(id); } }, - + ///// Quick "getElementsByClassName" which also returns as an Array ///// Can return as NodeList by passing true as second argument $$ : { @@ -57,7 +57,7 @@ exports.NJUtils = Montage.create(Component, { return (asNodeList) ? list : this.toArray(list); } }, - + ///// Get child nodes of element ///// Omit filter to only return element nodes ///// Pass in filter function to minimize collection, or @@ -70,9 +70,9 @@ exports.NJUtils = Montage.create(Component, { return this.toArray(el.childNodes).filter(f); } }, - + /* ============= DOM Manipulation ============= */ - + ///// Creates and returns text node from string textNode : { value: function(text) { @@ -95,7 +95,7 @@ exports.NJUtils = Montage.create(Component, { return el; } }, - + decor: { value: function(el, attr) { if (typeof attr === 'object') { @@ -183,7 +183,7 @@ exports.NJUtils = Montage.create(Component, { return node; } }, - + queryParentSelector : { value: function(el, strSelector) { // queryParentSelector: @@ -191,7 +191,7 @@ exports.NJUtils = Montage.create(Component, { // 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; @@ -199,26 +199,26 @@ exports.NJUtils = Montage.create(Component, { // 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. @@ -232,7 +232,7 @@ exports.NJUtils = Montage.create(Component, { return false; } } - + }, // Returns the numerical value and unit string from a string. @@ -257,14 +257,14 @@ exports.NJUtils = Montage.create(Component, { }, /* ================= Style methods ================= */ - + ///// Get computed height of element height : { value: function(node, pseudo) { return node.ownerDocument.defaultView.getComputedStyle(node, pseudo).getPropertyValue('height'); } }, - + /* ================= Array methods ================= */ ///// Return an array from an array-like object @@ -273,9 +273,9 @@ exports.NJUtils = Montage.create(Component, { return Array.prototype.slice.call(arrayLikeObj); } }, - + /* ================= String methods ================= */ - + ///// Return the last part of a path (e.g. filename) getFileNameFromPath : { value: function(path) { @@ -310,9 +310,9 @@ exports.NJUtils = Montage.create(Component, { value: function(len) { var length; len ? length = len : length = 8; - + return Uuid.generate().substring(0,length); } } - + }); -- cgit v1.2.3