Comparing version 0.1.10 to 0.1.11
127
jymin.js
/** | ||
* _ _ ___ _ _ ___ | ||
* | |_ _ _ __ ___ (_)_ __ __ __/ _ \ / | / |/ _ \ | ||
* _ | | | | | '_ ` _ \| | '_ \ \ \ / / | | || | | | | | | | ||
* | |_| | |_| | | | | | | | | | | \ V /| |_| || |_| | |_| | | ||
* \___/ \__, |_| |_| |_|_|_| |_| \_/ \___(_)_(_)_|\___/ | ||
* _ _ ___ _ _ _ | ||
* | |_ _ _ __ ___ (_)_ __ __ __/ _ \ / | / / | | ||
* _ | | | | | '_ ` _ \| | '_ \ \ \ / / | | || | | | | | ||
* | |_| | |_| | | | | | | | | | | \ V /| |_| || |_| | | | ||
* \___/ \__, |_| |_| |_|_|_| |_| \_/ \___(_)_(_)_|_| | ||
* |___/ | ||
@@ -26,2 +26,3 @@ * | ||
* https://github.com/zerious/jymin/blob/master/scripts/numbers.js | ||
* https://github.com/zerious/jymin/blob/master/scripts/ready.js | ||
* https://github.com/zerious/jymin/blob/master/scripts/strings.js | ||
@@ -33,3 +34,3 @@ * https://github.com/zerious/jymin/blob/master/scripts/types.js | ||
this.jymin = {version: '0.1.10'}; | ||
this.jymin = {version: '0.1.11'}; | ||
@@ -72,2 +73,3 @@ /** | ||
if (request.readyState == 4) { | ||
--getResponse._WAITING; | ||
var isSuccess = (request.status == 200); | ||
@@ -78,3 +80,4 @@ var callback = isSuccess ? | ||
var response = request.responseText; | ||
if (isSuccess && evalJson) { | ||
if (evalJson) { | ||
var object; | ||
try { | ||
@@ -84,9 +87,12 @@ // Trick Uglify into thinking there's no eval. | ||
e('eval.J=' + response); | ||
response = e.J; | ||
object = e.J; | ||
} | ||
catch (e) { | ||
//+env:dev | ||
log('ERROR: Could not parse JSON: "' + response + '"'); | ||
error('Could not parse JSON: "' + response + '"'); | ||
//-env:dev | ||
object = {_ERROR: 'Invalid JSON', _TEXT: response}; | ||
} | ||
object.request = request; | ||
response = object; | ||
} | ||
@@ -101,2 +107,3 @@ callback(response, request); | ||
} | ||
getResponse._WAITING = (getResponse._WAITING || 0) + 1; | ||
request.send(data || null); | ||
@@ -225,2 +232,17 @@ } | ||
/** | ||
* Ensure that a property exists by creating it if it doesn't. | ||
*/ | ||
var ensureProperty = function ( | ||
object, | ||
property, | ||
defaultValue | ||
) { | ||
var value = object[property]; | ||
if (!value) { | ||
value = object[property] = defaultValue; | ||
} | ||
return value; | ||
}; | ||
/** | ||
* Get the length of an array. | ||
@@ -477,4 +499,4 @@ * @return number: Array length. | ||
var keyAndValue = attribute.split('='); | ||
var key = keyAndValue[0]; | ||
var value = keyAndValue[1]; | ||
var key = unescape(keyAndValue[0]); | ||
var value = unescape(keyAndValue[1]); | ||
element[key] = value; | ||
@@ -792,3 +814,3 @@ element.setAttribute(key, value); | ||
var head = getElementsByTagName('head')[0]; | ||
var script = addElement(0, 'script'); | ||
var script = addElement(head, 'script'); | ||
if (callback) { | ||
@@ -863,4 +885,4 @@ script.onload = callback; | ||
*/ | ||
var stopEvent = function ( | ||
event // object*: Event to be canceled. | ||
var stopPropagation = function ( | ||
event // object: Event to be canceled. | ||
) { | ||
@@ -874,2 +896,11 @@ event.cancelBubble = true; | ||
/** | ||
* Prevent the default action for this event. | ||
*/ | ||
var preventDefault = function ( | ||
event // object: Event to prevent from doing its default action. | ||
) { | ||
event.preventDefault(); | ||
}; | ||
/** | ||
* Bind an event handler for both the focus and blur events. | ||
@@ -1144,3 +1175,3 @@ */ | ||
/** | ||
* Push an item into the history. | ||
* Replace the current item in the history. | ||
*/ | ||
@@ -1163,2 +1194,10 @@ var replaceHistory = function ( | ||
/** | ||
* Listen for a history change. | ||
*/ | ||
var onHistoryPop = function ( | ||
callback | ||
) { | ||
bind(window, 'popstate', callback); | ||
}; | ||
/** | ||
* Log values to the console, if it's available. | ||
@@ -1201,6 +1240,6 @@ */ | ||
*/ | ||
var ifConsole = function (method, arguments) { | ||
var ifConsole = function (method, args) { | ||
var console = window.console; | ||
if (console && console[method]) { | ||
console[method].apply(console, arguments); | ||
console[method].apply(console, args); | ||
} | ||
@@ -1221,2 +1260,32 @@ }; | ||
/** | ||
* Execute a callback when the page loads. | ||
*/ | ||
var onReady = window.onReady = function ( | ||
callback | ||
) { | ||
// If there's no queue, create it as a property of this function. | ||
var queue = ensureProperty(onReady, '_QUEUE', []); | ||
// If there's a callback, push it into the queue. | ||
if (callback) { | ||
// The first item in the queue causes onReady to be triggered. | ||
if (!getLength(queue)) { | ||
setTimeout(function () { | ||
onReady() | ||
}, 1); | ||
} | ||
// Put an item in the queue and wait. | ||
pushItem(queue, callback); | ||
} | ||
// If there's no callback, onReady has been triggered, so run callbacks. | ||
else { | ||
forEach(queue, function (callback) { | ||
callback(); | ||
}); | ||
} | ||
}; | ||
/** | ||
* Ensure a value is a string. | ||
@@ -1241,2 +1310,12 @@ */ | ||
/** | ||
* Return true if the string starts with the given substring. | ||
*/ | ||
var startsWith = function ( | ||
string, | ||
substring | ||
) { | ||
return ensureString(string).indexOf(substring) == 0; | ||
}; | ||
/** | ||
* Trim the whitespace from a string. | ||
@@ -1283,2 +1362,16 @@ */ | ||
/** | ||
* Perform a RegExp match, and call a callback on the result; | ||
*/ | ||
var match = function ( | ||
string, | ||
pattern, | ||
callback | ||
) { | ||
var result = string.match(pattern); | ||
if (result) { | ||
callback.apply(string, result); | ||
} | ||
}; | ||
/** | ||
* Reduce a string to its alphabetic characters. | ||
@@ -1285,0 +1378,0 @@ */ |
{ | ||
"name": "jymin", | ||
"description": "jymin is a Zerious module", | ||
"description": "Minifier-friendly JavaScript for the real-time world", | ||
"keywords": [ | ||
@@ -15,3 +15,3 @@ "jymin", | ||
], | ||
"version": "0.1.10", | ||
"version": "0.1.11", | ||
"main": "chug/chug.js", | ||
@@ -18,0 +18,0 @@ "homepage": "http://lighter.io/jymin", |
@@ -37,2 +37,3 @@ /** | ||
if (request.readyState == 4) { | ||
--getResponse._WAITING; | ||
var isSuccess = (request.status == 200); | ||
@@ -43,3 +44,4 @@ var callback = isSuccess ? | ||
var response = request.responseText; | ||
if (isSuccess && evalJson) { | ||
if (evalJson) { | ||
var object; | ||
try { | ||
@@ -49,9 +51,12 @@ // Trick Uglify into thinking there's no eval. | ||
e('eval.J=' + response); | ||
response = e.J; | ||
object = e.J; | ||
} | ||
catch (e) { | ||
//+env:dev | ||
log('ERROR: Could not parse JSON: "' + response + '"'); | ||
error('Could not parse JSON: "' + response + '"'); | ||
//-env:dev | ||
object = {_ERROR: 'Invalid JSON', _TEXT: response}; | ||
} | ||
object.request = request; | ||
response = object; | ||
} | ||
@@ -66,2 +71,3 @@ callback(response, request); | ||
} | ||
getResponse._WAITING = (getResponse._WAITING || 0) + 1; | ||
request.send(data || null); | ||
@@ -68,0 +74,0 @@ } |
@@ -51,2 +51,17 @@ /** | ||
/** | ||
* Ensure that a property exists by creating it if it doesn't. | ||
*/ | ||
var ensureProperty = function ( | ||
object, | ||
property, | ||
defaultValue | ||
) { | ||
var value = object[property]; | ||
if (!value) { | ||
value = object[property] = defaultValue; | ||
} | ||
return value; | ||
}; | ||
/** | ||
* Get the length of an array. | ||
@@ -53,0 +68,0 @@ * @return number: Array length. |
@@ -106,4 +106,4 @@ /** | ||
var keyAndValue = attribute.split('='); | ||
var key = keyAndValue[0]; | ||
var value = keyAndValue[1]; | ||
var key = unescape(keyAndValue[0]); | ||
var value = unescape(keyAndValue[1]); | ||
element[key] = value; | ||
@@ -421,3 +421,3 @@ element.setAttribute(key, value); | ||
var head = getElementsByTagName('head')[0]; | ||
var script = addElement(0, 'script'); | ||
var script = addElement(head, 'script'); | ||
if (callback) { | ||
@@ -424,0 +424,0 @@ script.onload = callback; |
@@ -60,4 +60,4 @@ /** | ||
*/ | ||
var stopEvent = function ( | ||
event // object*: Event to be canceled. | ||
var stopPropagation = function ( | ||
event // object: Event to be canceled. | ||
) { | ||
@@ -71,2 +71,11 @@ event.cancelBubble = true; | ||
/** | ||
* Prevent the default action for this event. | ||
*/ | ||
var preventDefault = function ( | ||
event // object: Event to prevent from doing its default action. | ||
) { | ||
event.preventDefault(); | ||
}; | ||
/** | ||
* Bind an event handler for both the focus and blur events. | ||
@@ -73,0 +82,0 @@ */ |
@@ -29,3 +29,3 @@ /** | ||
/** | ||
* Push an item into the history. | ||
* Replace the current item in the history. | ||
*/ | ||
@@ -47,1 +47,9 @@ var replaceHistory = function ( | ||
/** | ||
* Listen for a history change. | ||
*/ | ||
var onHistoryPop = function ( | ||
callback | ||
) { | ||
bind(window, 'popstate', callback); | ||
}; |
@@ -39,7 +39,7 @@ /** | ||
*/ | ||
var ifConsole = function (method, arguments) { | ||
var ifConsole = function (method, args) { | ||
var console = window.console; | ||
if (console && console[method]) { | ||
console[method].apply(console, arguments); | ||
console[method].apply(console, args); | ||
} | ||
}; |
@@ -21,2 +21,12 @@ /** | ||
/** | ||
* Return true if the string starts with the given substring. | ||
*/ | ||
var startsWith = function ( | ||
string, | ||
substring | ||
) { | ||
return ensureString(string).indexOf(substring) == 0; | ||
}; | ||
/** | ||
* Trim the whitespace from a string. | ||
@@ -63,2 +73,16 @@ */ | ||
/** | ||
* Perform a RegExp match, and call a callback on the result; | ||
*/ | ||
var match = function ( | ||
string, | ||
pattern, | ||
callback | ||
) { | ||
var result = string.match(pattern); | ||
if (result) { | ||
callback.apply(string, result); | ||
} | ||
}; | ||
/** | ||
* Reduce a string to its alphabetic characters. | ||
@@ -65,0 +89,0 @@ */ |
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
83495
22
3018