From 7bee50379c1df86bb571e0e8d6c08e24d25231f5 Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Mon, 9 Jul 2012 16:38:08 -0700 Subject: BSD License --- js/lib/NJUtils.js | 63 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 31 deletions(-) (limited to 'js/lib/NJUtils.js') diff --git a/js/lib/NJUtils.js b/js/lib/NJUtils.js index 1406ad98..cbd936a6 100755 --- a/js/lib/NJUtils.js +++ b/js/lib/NJUtils.js @@ -1,24 +1,25 @@ /* -Copyright (c) 2012, Motorola Mobility, Inc +Copyright (c) 2012, Motorola Mobility LLC. All Rights Reserved. -BSD License. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Motorola Mobility nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. +* Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of Motorola Mobility LLC nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS @@ -39,7 +40,7 @@ var Montage = require("montage/core/core").Montage, exports.NJUtils = Montage.create(Component, { /* =============== DOM Access ================ */ - + ///// Quick "getElementById" $ : { value: function(id, doc) { @@ -47,7 +48,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 +58,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 +71,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 +96,7 @@ exports.NJUtils = Montage.create(Component, { return el; } }, - + decor: { value: function(el, attr) { if (typeof attr === 'object') { @@ -183,7 +184,7 @@ exports.NJUtils = Montage.create(Component, { return node; } }, - + queryParentSelector : { value: function(el, strSelector) { // queryParentSelector: @@ -191,7 +192,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 +200,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 +233,7 @@ exports.NJUtils = Montage.create(Component, { return false; } } - + }, // Returns the numerical value and unit string from a string. @@ -257,14 +258,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 +274,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 +311,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