diff options
Diffstat (limited to 'js/lib/NJUtils.js')
-rwxr-xr-x | js/lib/NJUtils.js | 102 |
1 files changed, 51 insertions, 51 deletions
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, { | |||
65 | children : { | 65 | children : { |
66 | value : function(el, filter) { | 66 | value : function(el, filter) { |
67 | var f = filter || function(item) { | 67 | var f = filter || function(item) { |
68 | return item.nodeType === 1; | 68 | return item.nodeType === 1; |
69 | }; | 69 | }; |
70 | return this.toArray(el.childNodes).filter(f); | 70 | return this.toArray(el.childNodes).filter(f); |
71 | } | 71 | } |
72 | }, | 72 | }, |
73 | 73 | ||
@@ -185,54 +185,54 @@ exports.NJUtils = Montage.create(Component, { | |||
185 | }, | 185 | }, |
186 | 186 | ||
187 | queryParentSelector : { | 187 | queryParentSelector : { |
188 | value: function(el, strSelector) { | 188 | value: function(el, strSelector) { |
189 | // queryParentSelector: | 189 | // queryParentSelector: |
190 | // Given a DOM element el (required), walk up the DOM tree | 190 | // Given a DOM element el (required), walk up the DOM tree |
191 | // and find the first parent that matches selector strSelector (required). | 191 | // and find the first parent that matches selector strSelector (required). |
192 | // Returns: The element that matches, or false if there is no match | 192 | // Returns: The element that matches, or false if there is no match |
193 | // or if insufficient parameters are supplied. | 193 | // or if insufficient parameters are supplied. |
194 | 194 | ||
195 | if ((typeof(el) === "undefined") || (typeof(strSelector) === "undefined")) { | 195 | if ((typeof(el) === "undefined") || (typeof(strSelector) === "undefined")) { |
196 | // Parameters are required, m'kay? | 196 | // Parameters are required, m'kay? |
197 | return false; | 197 | return false; |
198 | } else if ((typeof(el) !== "object") || (typeof(strSelector) !== "string" )) { | 198 | } else if ((typeof(el) !== "object") || (typeof(strSelector) !== "string" )) { |
199 | // You also have to use the right parameters. | 199 | // You also have to use the right parameters. |
200 | return false; | 200 | return false; |
201 | } | 201 | } |
202 | 202 | ||
203 | // First, get an empty clone of the parent. | 203 | // First, get an empty clone of the parent. |
204 | var myParent = el.parentNode; | 204 | var myParent = el.parentNode; |
205 | var clone = myParent.cloneNode(false); | 205 | var clone = myParent.cloneNode(false); |
206 | if (clone === null) { | 206 | if (clone === null) { |
207 | return false; | 207 | return false; |
208 | } | 208 | } |
209 | 209 | ||
210 | // If we're at the top of the DOM, our clone will be an htmlDocument. | 210 | // If we're at the top of the DOM, our clone will be an htmlDocument. |
211 | // htmlDocument has no tagName. | 211 | // htmlDocument has no tagName. |
212 | if (typeof(clone.tagName) !== "undefined") { | 212 | if (typeof(clone.tagName) !== "undefined") { |
213 | // create a bogus div to use as a base for querySelector | 213 | // create a bogus div to use as a base for querySelector |
214 | var temp = document.createElement("div"); | 214 | var temp = document.createElement("div"); |
215 | 215 | ||
216 | // Append the clone to the bogus div | 216 | // Append the clone to the bogus div |
217 | temp.appendChild(clone); | 217 | temp.appendChild(clone); |
218 | 218 | ||
219 | // Now we can use querySelector! Sweet. | 219 | // Now we can use querySelector! Sweet. |
220 | var selectorTest = temp.querySelector(strSelector); | 220 | var selectorTest = temp.querySelector(strSelector); |
221 | 221 | ||
222 | // What has querySelector returned? | 222 | // What has querySelector returned? |
223 | if (selectorTest === null) { | 223 | if (selectorTest === null) { |
224 | // No match, so recurse. | 224 | // No match, so recurse. |
225 | return this.queryParentSelector(myParent, strSelector); | 225 | return this.queryParentSelector(myParent, strSelector); |
226 | } else { | 226 | } else { |
227 | // Match! Return the element. | 227 | // Match! Return the element. |
228 | return myParent; | 228 | return myParent; |
229 | } | 229 | } |
230 | } else { | 230 | } else { |
231 | // We're at the top of the DOM so we're done. | 231 | // We're at the top of the DOM so we're done. |
232 | return false; | 232 | return false; |
233 | } | 233 | } |
234 | } | 234 | } |
235 | 235 | ||
236 | }, | 236 | }, |
237 | 237 | ||
238 | // Returns the numerical value and unit string from a string. | 238 | // Returns the numerical value and unit string from a string. |