Comparing version 0.1.12 to 0.1.13
@@ -42,3 +42,2 @@ var cwd = process.cwd(); | ||
.write(cwd, 'jymin.min.js', 'minified'); | ||
}); | ||
@@ -45,0 +44,0 @@ |
217
jymin.js
/** | ||
* _ _ ___ _ _ ____ | ||
* | |_ _ _ __ ___ (_)_ __ __ __/ _ \ / | / |___ \ | ||
* _ | | | | | '_ ` _ \| | '_ \ \ \ / / | | || | | | __) | | ||
* | |_| | |_| | | | | | | | | | | \ V /| |_| || |_| |/ __/ | ||
* \___/ \__, |_| |_| |_|_|_| |_| \_/ \___(_)_(_)_|_____| | ||
* _ _ ___ _ _ _____ | ||
* | |_ _ _ __ ___ (_)_ __ __ __/ _ \ / | / |___ / | ||
* _ | | | | | '_ ` _ \| | '_ \ \ \ / / | | || | | | |_ \ | ||
* | |_| | |_| | | | | | | | | | | \ V /| |_| || |_| |___) | | ||
* \___/ \__, |_| |_| |_|_|_| |_| \_/ \___(_)_(_)_|____/ | ||
* |___/ | ||
@@ -33,3 +33,3 @@ * | ||
this.jymin = {version: '0.1.12'}; | ||
this.jymin = {version: '0.1.13'}; | ||
@@ -285,3 +285,3 @@ /** | ||
*/ | ||
var pushItem = function ( | ||
var push = function ( | ||
array, // Array: The array to push the item into. | ||
@@ -296,2 +296,15 @@ item // mixed: The item to push. | ||
var merge = function ( | ||
array, // Array: The array to merge into. | ||
items // mixed+: The items to merge into the array. | ||
) { | ||
for (var i = 1, l = arguments.length; i < l; i++) { | ||
items = arguments[i]; | ||
// TODO: Use splice instead of push to get better performance? | ||
forEach(items, function (item) { | ||
array.push(item); | ||
}); | ||
} | ||
}; | ||
/** | ||
@@ -301,3 +314,3 @@ * Push padding values onto an array up to a specified length. | ||
*/ | ||
var padArray = function ( | ||
var pad = function ( | ||
array, // Array: The array to check for items. | ||
@@ -397,7 +410,11 @@ padToLength, // number: The minimum number of items in the array. | ||
var getElement = function ( | ||
id, // string|DOMElement*: DOM element or ID of a DOM element. | ||
parentElement // DOMElement: Document or DOM element for getElementById. (Default: document) | ||
parentElement, // DOMElement|: Document or DOM element for getElementById. (Default: document) | ||
id // string|DOMElement: DOM element or ID of a DOM element. | ||
) { | ||
if (getLength(arguments) < 2) { | ||
id = parentElement; | ||
parentElement = document; | ||
} | ||
// If the argument is not a string, just assume it's already an element reference, and return it. | ||
return isString(id) ? (parentElement || document).getElementById(id) : id; | ||
return isString(id) ? parentElement.getElementById(id) : id; | ||
}; | ||
@@ -409,7 +426,10 @@ | ||
var getElementsByTagName = function ( | ||
tagName, // string: Name of the tag to look for. (Default: "*") | ||
parentElement // DOMElement: Document or DOM element for getElementsByTagName. (Default: document) | ||
parentElement, // DOMElement|: Document or DOM element for getElementsByTagName. (Default: document) | ||
tagName // string|: Name of the tag to look for. (Default: "*") | ||
) { | ||
parentElement = getElement(parentElement || document); | ||
return parentElement ? parentElement.getElementsByTagName(tagName || '*') : []; | ||
if (getLength(arguments) < 2) { | ||
tagName = parentElement; | ||
parentElement = document; | ||
} | ||
return parentElement.getElementsByTagName(tagName || '*'); | ||
}; | ||
@@ -421,14 +441,18 @@ | ||
var getElementsByTagAndClass = function ( | ||
tagAndClass, | ||
parentElement | ||
parentElement, | ||
tagAndClass | ||
) { | ||
if (getLength(arguments) < 2) { | ||
tagAndClass = parentElement; | ||
parentElement = document; | ||
} | ||
tagAndClass = tagAndClass.split('.'); | ||
var tagName = (tagAndClass[0] || '*').toUpperCase(); | ||
var className = tagAndClass[1]; | ||
var anyTag = (tagName == '*'); | ||
if (className) { | ||
parentElement = getElement(parentElement || document); | ||
var elements = []; | ||
if (parentElement.getElementsByClassName) { | ||
forEach(parentElement.getElementsByClassName(className), function(element) { | ||
if (element.tagName == tagName) { | ||
if (anyTag || (element.tagName == tagName)) { | ||
elements.push(element); | ||
@@ -439,3 +463,3 @@ } | ||
else { | ||
forEach(getElementsByTagName(tagName), function(element) { | ||
forEach(getElementsByTagName(parentElement, tagName), function(element) { | ||
if (hasClass(element, className)) { | ||
@@ -448,3 +472,3 @@ elements.push(element); | ||
else { | ||
elements = getElementsByTagName(tagName, parentElement); | ||
elements = getElementsByTagName(parentElement, tagName); | ||
} | ||
@@ -463,6 +487,4 @@ return elements; | ||
// If a tag name is specified, keep walking up. | ||
if (tagName && parentElement) { | ||
if (parentElement.tagName != tagName) { | ||
parentElement = getParent(parentElement, tagName); | ||
} | ||
if (tagName && parentElement && parentElement.tagName != tagName) { | ||
parentElement = getParent(parentElement, tagName); | ||
} | ||
@@ -835,23 +857,46 @@ return parentElement; | ||
/** | ||
* Run a callback on each element with a given tag and class. | ||
* Run a callback on each element matching a given selector. | ||
*/ | ||
var forElements = function ( | ||
tagAndClass, | ||
var all = function ( | ||
parentElement, | ||
selector, | ||
callback | ||
) { | ||
var elements = getElementsByTagAndClass(tagAndClass); | ||
forEach(elements, callback); | ||
}; | ||
/** | ||
* Run a callback on an element with a given id. | ||
*/ | ||
var forElement = function ( | ||
id, | ||
callback | ||
) { | ||
var element = getElement(id); | ||
if (element) { | ||
callback(element); | ||
if (!selector || isFunction(selector)) { | ||
callback = selector; | ||
selector = parentElement | ||
parentElement = document; | ||
} | ||
var elements; | ||
if (contains(selector, ',')) { | ||
elements = []; | ||
var selectors = splitByCommas(selector); | ||
forEach(selectors, function (piece) { | ||
var more = all(parentElement, piece); | ||
if (getLength(more)) { | ||
merge(elements, more); | ||
} | ||
}); | ||
} | ||
else if (contains(selector, ' ')) { | ||
var pos = selector.indexOf(' '); | ||
var preSelector = selector.substr(0, pos); | ||
var postSelector = selector.substr(pos + 1); | ||
elements = []; | ||
all(parentElement, preSelector, function (element) { | ||
var children = all(element, postSelector); | ||
merge(elements, children); | ||
}); | ||
} | ||
else if (selector[0] == '#') { | ||
var element = getElement(parentElement, selector.substr(1)); | ||
elements = element ? [element] : []; | ||
} | ||
else { | ||
elements = getElementsByTagAndClass(parentElement, selector); | ||
} | ||
if (callback) { | ||
forEach(elements, callback); | ||
} | ||
return elements; | ||
}; | ||
@@ -862,10 +907,10 @@ /** | ||
var bind = function ( | ||
element, // DOMElement|string*: Element or ID of element to bind to. | ||
eventName, // string*: Name of event (e.g. "click", "mouseover", "keyup"). | ||
eventHandler, // function*: Function to run when the event is triggered. `eventHandler(element, event, target, customData)` | ||
customData, // object: Custom data to pass through to the event handler when it's triggered. | ||
element, // DOMElement|string: Element or ID of element to bind to. | ||
eventName, // string: Name of event (e.g. "click", "mouseover", "keyup"). | ||
eventHandler, // function: Function to run when the event is triggered. `eventHandler(element, event, target, customData)` | ||
customData, // object|: Custom data to pass through to the event handler when it's triggered. | ||
multiBindCustomData | ||
) { | ||
// Allow multiple events to be bound at once using a space-delimited string. | ||
if (containsString(eventName, ' ')) { | ||
if (contains(eventName, ' ')) { | ||
var eventNames = splitBySpaces(eventName); | ||
@@ -912,2 +957,6 @@ forEach(eventNames, function (singleEventName) { | ||
} | ||
var handlers = (element._HANDLERS = element._HANDLERS || {}); | ||
var queue = (handlers[eventName] = handlers[eventName] || []); | ||
push(queue, eventHandler); | ||
} | ||
@@ -917,2 +966,32 @@ }; | ||
/** | ||
* Trigger an element event. | ||
*/ | ||
var trigger = function ( | ||
element, // object: Element to trigger an event on. | ||
event, // object|String: Event to trigger. | ||
target, // object|: Fake target. | ||
customData // object|: Custom data to pass to handlers. | ||
) { | ||
if (isString(event)) { | ||
event = {type: event}; | ||
} | ||
if (!target) { | ||
target = element; | ||
} | ||
var handlers = element._HANDLERS; | ||
if (handlers) { | ||
var queue = handlers[event.type]; | ||
forEach(queue, function (callback) { | ||
callback(element, event, target, customData); | ||
}); | ||
} | ||
if (!event.cancelBubble) { | ||
element = getParent(element); | ||
if (element) { | ||
trigger(element, event, target, customData); | ||
} | ||
} | ||
}; | ||
/** | ||
* Stop event bubbling. | ||
@@ -1126,3 +1205,3 @@ */ | ||
var options = input.options; | ||
if (isBoolean(checked)) { | ||
if (type == 'c' || type == 'r') { | ||
value = checked ? value : null; | ||
@@ -1134,3 +1213,3 @@ } | ||
if (option.selected) { | ||
pushItem(value, option.value); | ||
push(value, option.value); | ||
} | ||
@@ -1311,3 +1390,3 @@ }); | ||
// Put an item in the queue and wait. | ||
pushItem(queue, callback); | ||
push(queue, callback); | ||
} | ||
@@ -1334,3 +1413,3 @@ | ||
*/ | ||
var containsString = function ( | ||
var contains = function ( | ||
string, | ||
@@ -1355,3 +1434,3 @@ substring | ||
*/ | ||
var trimString = function ( | ||
var trim = function ( | ||
string | ||
@@ -1440,2 +1519,33 @@ ) { | ||
/** | ||
* Returns a lowercase string. | ||
*/ | ||
var lower = function ( | ||
object | ||
) { | ||
return ensureString(object).toLowerCase(); | ||
}; | ||
/** | ||
* Returns an uppercase string. | ||
*/ | ||
var upper = function ( | ||
object | ||
) { | ||
return ensureString(object).toUpperCase(); | ||
}; | ||
/** | ||
* Returns a query string generated by serializing an object and joined using a delimiter (defaults to '&') | ||
*/ | ||
var buildQueryString = function ( | ||
object | ||
) { | ||
var queryParams = []; | ||
forIn(object, function(value, key) { | ||
queryParams.push(escape(key) + '=' + escape(value)); | ||
}); | ||
return queryParams.join('&'); | ||
}; | ||
/** | ||
* Return the browser version if the browser name matches or zero if it doesn't. | ||
@@ -1449,5 +1559,2 @@ */ | ||
}; | ||
// Make an undefined value available. | ||
var undefined = window.undefined; | ||
/** | ||
@@ -1454,0 +1561,0 @@ * Return true if a variable is a given type. |
@@ -15,3 +15,3 @@ { | ||
], | ||
"version": "0.1.12", | ||
"version": "0.1.13", | ||
"main": "chug/chug.js", | ||
@@ -18,0 +18,0 @@ "homepage": "http://lighter.io/jymin", |
@@ -109,3 +109,3 @@ /** | ||
*/ | ||
var pushItem = function ( | ||
var push = function ( | ||
array, // Array: The array to push the item into. | ||
@@ -120,2 +120,15 @@ item // mixed: The item to push. | ||
var merge = function ( | ||
array, // Array: The array to merge into. | ||
items // mixed+: The items to merge into the array. | ||
) { | ||
for (var i = 1, l = arguments.length; i < l; i++) { | ||
items = arguments[i]; | ||
// TODO: Use splice instead of push to get better performance? | ||
forEach(items, function (item) { | ||
array.push(item); | ||
}); | ||
} | ||
}; | ||
/** | ||
@@ -125,3 +138,3 @@ * Push padding values onto an array up to a specified length. | ||
*/ | ||
var padArray = function ( | ||
var pad = function ( | ||
array, // Array: The array to check for items. | ||
@@ -128,0 +141,0 @@ padToLength, // number: The minimum number of items in the array. |
@@ -7,7 +7,11 @@ /** | ||
var getElement = function ( | ||
id, // string|DOMElement*: DOM element or ID of a DOM element. | ||
parentElement // DOMElement: Document or DOM element for getElementById. (Default: document) | ||
parentElement, // DOMElement|: Document or DOM element for getElementById. (Default: document) | ||
id // string|DOMElement: DOM element or ID of a DOM element. | ||
) { | ||
if (getLength(arguments) < 2) { | ||
id = parentElement; | ||
parentElement = document; | ||
} | ||
// If the argument is not a string, just assume it's already an element reference, and return it. | ||
return isString(id) ? (parentElement || document).getElementById(id) : id; | ||
return isString(id) ? parentElement.getElementById(id) : id; | ||
}; | ||
@@ -19,7 +23,10 @@ | ||
var getElementsByTagName = function ( | ||
tagName, // string: Name of the tag to look for. (Default: "*") | ||
parentElement // DOMElement: Document or DOM element for getElementsByTagName. (Default: document) | ||
parentElement, // DOMElement|: Document or DOM element for getElementsByTagName. (Default: document) | ||
tagName // string|: Name of the tag to look for. (Default: "*") | ||
) { | ||
parentElement = getElement(parentElement || document); | ||
return parentElement ? parentElement.getElementsByTagName(tagName || '*') : []; | ||
if (getLength(arguments) < 2) { | ||
tagName = parentElement; | ||
parentElement = document; | ||
} | ||
return parentElement.getElementsByTagName(tagName || '*'); | ||
}; | ||
@@ -31,14 +38,18 @@ | ||
var getElementsByTagAndClass = function ( | ||
tagAndClass, | ||
parentElement | ||
parentElement, | ||
tagAndClass | ||
) { | ||
if (getLength(arguments) < 2) { | ||
tagAndClass = parentElement; | ||
parentElement = document; | ||
} | ||
tagAndClass = tagAndClass.split('.'); | ||
var tagName = (tagAndClass[0] || '*').toUpperCase(); | ||
var className = tagAndClass[1]; | ||
var anyTag = (tagName == '*'); | ||
if (className) { | ||
parentElement = getElement(parentElement || document); | ||
var elements = []; | ||
if (parentElement.getElementsByClassName) { | ||
forEach(parentElement.getElementsByClassName(className), function(element) { | ||
if (element.tagName == tagName) { | ||
if (anyTag || (element.tagName == tagName)) { | ||
elements.push(element); | ||
@@ -49,3 +60,3 @@ } | ||
else { | ||
forEach(getElementsByTagName(tagName), function(element) { | ||
forEach(getElementsByTagName(parentElement, tagName), function(element) { | ||
if (hasClass(element, className)) { | ||
@@ -58,3 +69,3 @@ elements.push(element); | ||
else { | ||
elements = getElementsByTagName(tagName, parentElement); | ||
elements = getElementsByTagName(parentElement, tagName); | ||
} | ||
@@ -73,6 +84,4 @@ return elements; | ||
// If a tag name is specified, keep walking up. | ||
if (tagName && parentElement) { | ||
if (parentElement.tagName != tagName) { | ||
parentElement = getParent(parentElement, tagName); | ||
} | ||
if (tagName && parentElement && parentElement.tagName != tagName) { | ||
parentElement = getParent(parentElement, tagName); | ||
} | ||
@@ -445,23 +454,46 @@ return parentElement; | ||
/** | ||
* Run a callback on each element with a given tag and class. | ||
* Run a callback on each element matching a given selector. | ||
*/ | ||
var forElements = function ( | ||
tagAndClass, | ||
var all = function ( | ||
parentElement, | ||
selector, | ||
callback | ||
) { | ||
var elements = getElementsByTagAndClass(tagAndClass); | ||
forEach(elements, callback); | ||
}; | ||
/** | ||
* Run a callback on an element with a given id. | ||
*/ | ||
var forElement = function ( | ||
id, | ||
callback | ||
) { | ||
var element = getElement(id); | ||
if (element) { | ||
callback(element); | ||
if (!selector || isFunction(selector)) { | ||
callback = selector; | ||
selector = parentElement | ||
parentElement = document; | ||
} | ||
var elements; | ||
if (contains(selector, ',')) { | ||
elements = []; | ||
var selectors = splitByCommas(selector); | ||
forEach(selectors, function (piece) { | ||
var more = all(parentElement, piece); | ||
if (getLength(more)) { | ||
merge(elements, more); | ||
} | ||
}); | ||
} | ||
else if (contains(selector, ' ')) { | ||
var pos = selector.indexOf(' '); | ||
var preSelector = selector.substr(0, pos); | ||
var postSelector = selector.substr(pos + 1); | ||
elements = []; | ||
all(parentElement, preSelector, function (element) { | ||
var children = all(element, postSelector); | ||
merge(elements, children); | ||
}); | ||
} | ||
else if (selector[0] == '#') { | ||
var element = getElement(parentElement, selector.substr(1)); | ||
elements = element ? [element] : []; | ||
} | ||
else { | ||
elements = getElementsByTagAndClass(parentElement, selector); | ||
} | ||
if (callback) { | ||
forEach(elements, callback); | ||
} | ||
return elements; | ||
}; |
@@ -5,10 +5,10 @@ /** | ||
var bind = function ( | ||
element, // DOMElement|string*: Element or ID of element to bind to. | ||
eventName, // string*: Name of event (e.g. "click", "mouseover", "keyup"). | ||
eventHandler, // function*: Function to run when the event is triggered. `eventHandler(element, event, target, customData)` | ||
customData, // object: Custom data to pass through to the event handler when it's triggered. | ||
element, // DOMElement|string: Element or ID of element to bind to. | ||
eventName, // string: Name of event (e.g. "click", "mouseover", "keyup"). | ||
eventHandler, // function: Function to run when the event is triggered. `eventHandler(element, event, target, customData)` | ||
customData, // object|: Custom data to pass through to the event handler when it's triggered. | ||
multiBindCustomData | ||
) { | ||
// Allow multiple events to be bound at once using a space-delimited string. | ||
if (containsString(eventName, ' ')) { | ||
if (contains(eventName, ' ')) { | ||
var eventNames = splitBySpaces(eventName); | ||
@@ -55,2 +55,6 @@ forEach(eventNames, function (singleEventName) { | ||
} | ||
var handlers = (element._HANDLERS = element._HANDLERS || {}); | ||
var queue = (handlers[eventName] = handlers[eventName] || []); | ||
push(queue, eventHandler); | ||
} | ||
@@ -60,2 +64,32 @@ }; | ||
/** | ||
* Trigger an element event. | ||
*/ | ||
var trigger = function ( | ||
element, // object: Element to trigger an event on. | ||
event, // object|String: Event to trigger. | ||
target, // object|: Fake target. | ||
customData // object|: Custom data to pass to handlers. | ||
) { | ||
if (isString(event)) { | ||
event = {type: event}; | ||
} | ||
if (!target) { | ||
target = element; | ||
} | ||
var handlers = element._HANDLERS; | ||
if (handlers) { | ||
var queue = handlers[event.type]; | ||
forEach(queue, function (callback) { | ||
callback(element, event, target, customData); | ||
}); | ||
} | ||
if (!event.cancelBubble) { | ||
element = getParent(element); | ||
if (element) { | ||
trigger(element, event, target, customData); | ||
} | ||
} | ||
}; | ||
/** | ||
* Stop event bubbling. | ||
@@ -62,0 +96,0 @@ */ |
@@ -13,3 +13,3 @@ /** | ||
var options = input.options; | ||
if (isBoolean(checked)) { | ||
if (type == 'c' || type == 'r') { | ||
value = checked ? value : null; | ||
@@ -21,3 +21,3 @@ } | ||
if (option.selected) { | ||
pushItem(value, option.value); | ||
push(value, option.value); | ||
} | ||
@@ -24,0 +24,0 @@ }); |
@@ -21,3 +21,3 @@ /** | ||
// Put an item in the queue and wait. | ||
pushItem(queue, callback); | ||
push(queue, callback); | ||
} | ||
@@ -24,0 +24,0 @@ |
@@ -13,3 +13,3 @@ /** | ||
*/ | ||
var containsString = function ( | ||
var contains = function ( | ||
string, | ||
@@ -34,3 +34,3 @@ substring | ||
*/ | ||
var trimString = function ( | ||
var trim = function ( | ||
string | ||
@@ -119,2 +119,33 @@ ) { | ||
/** | ||
* Returns a lowercase string. | ||
*/ | ||
var lower = function ( | ||
object | ||
) { | ||
return ensureString(object).toLowerCase(); | ||
}; | ||
/** | ||
* Returns an uppercase string. | ||
*/ | ||
var upper = function ( | ||
object | ||
) { | ||
return ensureString(object).toUpperCase(); | ||
}; | ||
/** | ||
* Returns a query string generated by serializing an object and joined using a delimiter (defaults to '&') | ||
*/ | ||
var buildQueryString = function ( | ||
object | ||
) { | ||
var queryParams = []; | ||
forIn(object, function(value, key) { | ||
queryParams.push(escape(key) + '=' + escape(value)); | ||
}); | ||
return queryParams.join('&'); | ||
}; | ||
/** | ||
* Return the browser version if the browser name matches or zero if it doesn't. | ||
@@ -121,0 +152,0 @@ */ |
@@ -1,4 +0,1 @@ | ||
// Make an undefined value available. | ||
var undefined = window.undefined; | ||
/** | ||
@@ -5,0 +2,0 @@ * Return true if a variable is a given type. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
89824
3282