update interface (fixes issue #6)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* almond 0.2.6 Copyright (c) 2011-2012, The Dojo Foundation All Rights Reserved.
|
||||
* @license almond 0.3.1 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved.
|
||||
* Available via the MIT or new BSD license.
|
||||
* see: http://github.com/jrburke/almond for details
|
||||
*/
|
||||
@@ -16,7 +16,8 @@ var requirejs, require, define;
|
||||
config = {},
|
||||
defining = {},
|
||||
hasOwn = Object.prototype.hasOwnProperty,
|
||||
aps = [].slice;
|
||||
aps = [].slice,
|
||||
jsSuffixRegExp = /\.js$/;
|
||||
|
||||
function hasProp(obj, prop) {
|
||||
return hasOwn.call(obj, prop);
|
||||
@@ -31,7 +32,7 @@ var requirejs, require, define;
|
||||
* @returns {String} normalized name
|
||||
*/
|
||||
function normalize(name, baseName) {
|
||||
var nameParts, nameSegment, mapValue, foundMap,
|
||||
var nameParts, nameSegment, mapValue, foundMap, lastIndex,
|
||||
foundI, foundStarMap, starI, i, j, part,
|
||||
baseParts = baseName && baseName.split("/"),
|
||||
map = config.map,
|
||||
@@ -43,14 +44,19 @@ var requirejs, require, define;
|
||||
//otherwise, assume it is a top-level require that will
|
||||
//be relative to baseUrl in the end.
|
||||
if (baseName) {
|
||||
//Convert baseName to array, and lop off the last part,
|
||||
//so that . matches that "directory" and not name of the baseName's
|
||||
//module. For instance, baseName of "one/two/three", maps to
|
||||
//"one/two/three.js", but we want the directory, "one/two" for
|
||||
//this normalization.
|
||||
baseParts = baseParts.slice(0, baseParts.length - 1);
|
||||
name = name.split('/');
|
||||
lastIndex = name.length - 1;
|
||||
|
||||
name = baseParts.concat(name.split("/"));
|
||||
// Node .js allowance:
|
||||
if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
|
||||
name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
|
||||
}
|
||||
|
||||
//Lop off the last part of baseParts, so that . matches the
|
||||
//"directory" and not name of the baseName's module. For instance,
|
||||
//baseName of "one/two/three", maps to "one/two/three.js", but we
|
||||
//want the directory, "one/two" for this normalization.
|
||||
name = baseParts.slice(0, baseParts.length - 1).concat(name);
|
||||
|
||||
//start trimDots
|
||||
for (i = 0; i < name.length; i += 1) {
|
||||
@@ -142,7 +148,15 @@ var requirejs, require, define;
|
||||
//A version of a require function that passes a moduleName
|
||||
//value for items that may need to
|
||||
//look up paths relative to the moduleName
|
||||
return req.apply(undef, aps.call(arguments, 0).concat([relName, forceSync]));
|
||||
var args = aps.call(arguments, 0);
|
||||
|
||||
//If first arg is not require('string'), and there is only
|
||||
//one arg, it is the array form without a callback. Insert
|
||||
//a null so that the following concat is correct.
|
||||
if (typeof args[0] !== 'string' && args.length === 1) {
|
||||
args.push(null);
|
||||
}
|
||||
return req.apply(undef, args.concat([relName, forceSync]));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -259,14 +273,14 @@ var requirejs, require, define;
|
||||
main = function (name, deps, callback, relName) {
|
||||
var cjsModule, depName, ret, map, i,
|
||||
args = [],
|
||||
callbackType = typeof callback,
|
||||
usingExports;
|
||||
|
||||
//Use name if no relName
|
||||
relName = relName || name;
|
||||
|
||||
//Call the callback to define the module, if necessary.
|
||||
if (typeof callback === 'function') {
|
||||
|
||||
if (callbackType === 'undefined' || callbackType === 'function') {
|
||||
//Pull out the defined dependencies and pass the ordered
|
||||
//values to the callback.
|
||||
//Default to [require, exports, module] if no deps
|
||||
@@ -297,7 +311,7 @@ var requirejs, require, define;
|
||||
}
|
||||
}
|
||||
|
||||
ret = callback.apply(defined[name], args);
|
||||
ret = callback ? callback.apply(defined[name], args) : undefined;
|
||||
|
||||
if (name) {
|
||||
//If setting exports via "module" is in play,
|
||||
@@ -332,6 +346,13 @@ var requirejs, require, define;
|
||||
} else if (!deps.splice) {
|
||||
//deps is a config object, not an array.
|
||||
config = deps;
|
||||
if (config.deps) {
|
||||
req(config.deps, config.callback);
|
||||
}
|
||||
if (!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (callback.splice) {
|
||||
//callback is an array, which means it is a dependency list.
|
||||
//Adjust args if there are dependencies
|
||||
@@ -376,11 +397,7 @@ var requirejs, require, define;
|
||||
* the config return value is used.
|
||||
*/
|
||||
req.config = function (cfg) {
|
||||
config = cfg;
|
||||
if (config.deps) {
|
||||
req(config.deps, config.callback);
|
||||
}
|
||||
return req;
|
||||
return req(cfg);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -389,6 +406,9 @@ var requirejs, require, define;
|
||||
requirejs._defined = defined;
|
||||
|
||||
define = function (name, deps, callback) {
|
||||
if (typeof name !== 'string') {
|
||||
throw new Error('See almond README: incorrect module build, no module name');
|
||||
}
|
||||
|
||||
//This module may not have dependencies
|
||||
if (!deps.splice) {
|
||||
@@ -1,10 +0,0 @@
|
||||
;(function ()
|
||||
{
|
||||
navigator.getUserMedia = (
|
||||
navigator.getUserMedia ||
|
||||
navigator.webkitGetUserMedia ||
|
||||
navigator.mozGetUserMedia ||
|
||||
navigator.msGetUserMedia ||
|
||||
false
|
||||
);
|
||||
})()
|
||||
@@ -0,0 +1,292 @@
|
||||
//! glitch-canvas by snorpey, MIT License
|
||||
(function(window, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(factory);
|
||||
} else if (typeof exports === "object") {
|
||||
module.exports = factory();
|
||||
} else {
|
||||
window.glitch = factory();
|
||||
}
|
||||
})(this, function() {
|
||||
|
||||
function Glitcher ( webworkerPath ) {
|
||||
if ( ! ( this instanceof Glitcher ) ) {
|
||||
return new Glitcher( webworkerPath );
|
||||
}
|
||||
|
||||
var self = this
|
||||
var canvas1El = document.createElement( 'canvas' );
|
||||
var canvas2El = document.createElement( 'canvas' );
|
||||
var ctx1 = canvas1El.getContext( '2d' );
|
||||
var ctx2 = canvas2El.getContext( '2d' );
|
||||
var img = new Image();
|
||||
var base64;
|
||||
var img;
|
||||
var newImageData;
|
||||
var i;
|
||||
var len;
|
||||
var params;
|
||||
var worker;
|
||||
var base64Chars;
|
||||
var base64Map;
|
||||
var reversedBase64Map;
|
||||
var byteArrayImageData;
|
||||
var jpgHeaderLength;
|
||||
|
||||
function init () {
|
||||
if ( webworkerPath && 'Worker' in window ) {
|
||||
worker = new Worker( webworkerPath );
|
||||
worker.addEventListener( 'message', workerResponded, false );
|
||||
} else {
|
||||
base64Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
||||
base64Map = base64Chars.split( '' );
|
||||
reversedBase64Map = { };
|
||||
|
||||
base64Map.forEach( function ( val, key ) {
|
||||
reversedBase64Map[val] = key;
|
||||
} );
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
function glitch ( imageData, parameters, callback ) {
|
||||
if (
|
||||
isValidImageData( imageData ) &&
|
||||
isType( parameters, 'parameters', 'object' ) &&
|
||||
isType( callback, 'callback', 'function' )
|
||||
) {
|
||||
resizeCanvas( canvas1El, imageData );
|
||||
resizeCanvas( canvas2El, imageData );
|
||||
params = getNormalizedParameters( parameters );
|
||||
base64 = getBase64FromImageData( imageData, params.quality );
|
||||
|
||||
img.onload = function () {
|
||||
ctx1.drawImage( img, 0, 0 );
|
||||
newImageData = ctx1.getImageData( 0, 0, imageData.width, imageData.height );
|
||||
callback ( newImageData );
|
||||
img.onload = null;
|
||||
};
|
||||
|
||||
if ( worker ) {
|
||||
worker.postMessage( { glitch: { base64: base64, parameters: params } } );
|
||||
} else {
|
||||
byteArrayImageData = base64ToByteArray( base64 );
|
||||
jpgHeaderLength = getJpegHeaderSize( byteArrayImageData );
|
||||
|
||||
for ( i = 0, len = params.iterations; i < len; i++ ) {
|
||||
glitchJpegBytes( byteArrayImageData, jpgHeaderLength, params.seed, params.amount, i, params.iterations );
|
||||
}
|
||||
|
||||
img.src = byteArrayToBase64( byteArrayImageData );
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
function workerResponded ( event ) {
|
||||
if ( event && event.data && event.data.glitched ) {
|
||||
glitched( event.data.glitched );
|
||||
} else {
|
||||
window.console && console.log( 'glitchworker response', event.data );
|
||||
}
|
||||
}
|
||||
|
||||
function workerFailed ( err ) {
|
||||
window.console && console.log( err.message || err );
|
||||
}
|
||||
|
||||
function glitched ( newBase64ImageData ) {
|
||||
img.src = newBase64ImageData;
|
||||
}
|
||||
|
||||
function resizeCanvas ( canvas, size ) {
|
||||
if ( canvas.width !== size.width ) {
|
||||
canvas.width = size.width;
|
||||
}
|
||||
|
||||
if ( canvas.height !== size.height ) {
|
||||
canvas.height = size.height;
|
||||
}
|
||||
}
|
||||
|
||||
function getNormalizedParameters ( parameters ) {
|
||||
return {
|
||||
seed: ( parameters.seed || 0 ) / 100,
|
||||
quality: ( parameters.quality || 0 ) / 100,
|
||||
amount: ( parameters.amount || 0 ) / 100,
|
||||
iterations: parameters.iterations || 0
|
||||
};
|
||||
}
|
||||
|
||||
function getBase64FromImageData ( imageData, quality ) {
|
||||
var q = typeof quality === 'number' && quality < 1 && quality > 0 ? quality : .1;
|
||||
|
||||
ctx2.putImageData( imageData, 0, 0 );
|
||||
|
||||
var base64 = canvas2El.toDataURL( 'image/jpeg', q );
|
||||
|
||||
switch ( base64.length % 4 ) {
|
||||
case 3:
|
||||
base64 += '=';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
base64 += '==';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
base64 += '===';
|
||||
break;
|
||||
}
|
||||
|
||||
return base64;
|
||||
}
|
||||
|
||||
function isValidImageData ( imageData ) {
|
||||
if (
|
||||
isType( imageData, 'imageData', 'object' ) &&
|
||||
isType( imageData.width, 'imageData.width', 'number' ) &&
|
||||
isType( imageData.height, 'imageData.height', 'number' ) &&
|
||||
isType( imageData.data, 'imageData.data', 'object' ) &&
|
||||
isType( imageData.data.length, 'imageData.data.length', 'number' ) &&
|
||||
checkNumber( imageData.data.length, 'imageData.data.length', isPositive, '> 0' )
|
||||
) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function isType ( it, name, expectedType ) {
|
||||
if ( typeof it === expectedType ) {
|
||||
return true;
|
||||
} else {
|
||||
error( it, 'typeof ' + name, '"' + expectedType + '"', '"' + typeof it + '"' );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function checkNumber ( it, name, condition, conditionName ) {
|
||||
if ( condition( it ) === true) {
|
||||
return true;
|
||||
} else {
|
||||
error( it, name, conditionName, 'not' );
|
||||
}
|
||||
}
|
||||
|
||||
function isPositive ( nr ) {
|
||||
return nr > 0;
|
||||
}
|
||||
|
||||
function error ( it, name, expected, result ) {
|
||||
throw new Error( 'glitch(): Expected ' + name + ' to be ' + expected + ', but it was ' + result + '.' );
|
||||
}
|
||||
|
||||
// all functions beyond this point are only used if no webworker is available
|
||||
|
||||
function glitchJpegBytes ( byteArray, jpgHeaderLength, seed, amount, i, len ) {
|
||||
var maxIndex = byteArray.length - jpgHeaderLength - 4;
|
||||
var pxMin = parseInt( maxIndex / len * i, 10 );
|
||||
var pxMax = parseInt( maxIndex / len * ( i + 1 ), 10 );
|
||||
var delta = pxMax - pxMin;
|
||||
var pxIndex = parseInt( pxMin + delta * seed, 10 );
|
||||
|
||||
if ( pxIndex > maxIndex ) {
|
||||
pxIndex = maxIndex;
|
||||
}
|
||||
|
||||
var index = Math.floor( jpgHeaderLength + pxIndex );
|
||||
|
||||
byteArray[index] = Math.floor( amount * 256 );
|
||||
}
|
||||
|
||||
function base64ToByteArray ( str ) {
|
||||
var result = [ ];
|
||||
var digitNum;
|
||||
var cur;
|
||||
var prev;
|
||||
|
||||
for ( i = 23, len = str.length; i < len; i++ ) {
|
||||
cur = reversedBase64Map[str.charAt( i )];
|
||||
digitNum = ( i - 23 ) % 4;
|
||||
|
||||
switch ( digitNum ) {
|
||||
case 1:
|
||||
result.push( prev << 2 | cur >> 4 );
|
||||
break;
|
||||
|
||||
case 2:
|
||||
result.push( ( prev & 15 ) << 4 | cur >> 2 );
|
||||
break;
|
||||
|
||||
case 3:
|
||||
result.push( ( prev & 3 ) << 6 | cur );
|
||||
break;
|
||||
}
|
||||
|
||||
prev = cur;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function byteArrayToBase64 ( arr ) {
|
||||
var result = [ 'data:image/jpeg;base64,' ];
|
||||
var byteNum;
|
||||
var cur;
|
||||
var prev;
|
||||
|
||||
for ( i = 0, len = arr.length; i < len; i++ ) {
|
||||
cur = arr[i];
|
||||
byteNum = i % 3;
|
||||
|
||||
switch (byteNum) {
|
||||
case 0:
|
||||
result.push( base64Map[cur >> 2] );
|
||||
break;
|
||||
|
||||
case 1:
|
||||
result.push( base64Map[( prev & 3 ) << 4 | cur >> 4] );
|
||||
break;
|
||||
|
||||
case 2:
|
||||
result.push( base64Map[( prev & 15 ) << 2 | cur >> 6] );
|
||||
result.push( base64Map[cur & 63] );
|
||||
break;
|
||||
}
|
||||
|
||||
prev = cur;
|
||||
}
|
||||
|
||||
if ( byteNum === 0 ) {
|
||||
result.push( base64Map[( prev & 3 ) << 4] );
|
||||
result.push( '==' );
|
||||
} else if ( byteNum === 1 ) {
|
||||
result.push( base64Map[( prev & 15 ) << 2] );
|
||||
result.push( '=' );
|
||||
}
|
||||
|
||||
return result.join( '' );
|
||||
}
|
||||
|
||||
function getJpegHeaderSize ( data ) {
|
||||
var result = 417;
|
||||
|
||||
for ( i = 0, len = data.length; i < len; i++ ) {
|
||||
if ( data[i] === 255 && data[i + 1] === 218 ) {
|
||||
result = i + 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
self.glitch = glitch;
|
||||
self.init = init;
|
||||
}
|
||||
|
||||
return Glitcher;
|
||||
});
|
||||
@@ -1,198 +0,0 @@
|
||||
//! glitch-canvas by snorpey, MIT License
|
||||
(function(window, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(factory);
|
||||
} else if (typeof exports === "object") {
|
||||
module.exports = factory();
|
||||
} else {
|
||||
window.glitch = factory();
|
||||
}
|
||||
})(this, function() {
|
||||
var canvas_1 = document.createElement("canvas");
|
||||
var canvas_2 = document.createElement("canvas");
|
||||
var ctx_1 = canvas_1.getContext("2d");
|
||||
var ctx_2 = canvas_2.getContext("2d");
|
||||
var base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
var base64_map = base64_chars.split("");
|
||||
var reversed_base64_map = {};
|
||||
var params;
|
||||
var base64;
|
||||
var byte_array;
|
||||
var jpg_header_length;
|
||||
var img;
|
||||
var new_image_data;
|
||||
var i;
|
||||
var len;
|
||||
base64_map.forEach(function(val, key) {
|
||||
reversed_base64_map[val] = key;
|
||||
});
|
||||
function glitchImageData(image_data, parameters, callback) {
|
||||
if (isValidImageData(image_data) && checkType(parameters, "parameters", "object") && checkType(callback, "callback", "function")) {
|
||||
params = getNormalizedParameters(parameters);
|
||||
resizeCanvas(canvas_1, image_data);
|
||||
resizeCanvas(canvas_2, image_data);
|
||||
base64 = getBase64FromImageData(image_data, params.quality);
|
||||
byte_array = base64ToByteArray(base64);
|
||||
jpg_header_length = getJpegHeaderSize(byte_array);
|
||||
for (i = 0, len = params.iterations; i < len; i++) {
|
||||
glitchJpegBytes(byte_array, jpg_header_length, params.seed, params.amount, i, params.iterations);
|
||||
}
|
||||
img = new Image();
|
||||
img.onload = function() {
|
||||
ctx_1.drawImage(img, 0, 0);
|
||||
new_image_data = ctx_1.getImageData(0, 0, image_data.width, image_data.height);
|
||||
callback(new_image_data);
|
||||
};
|
||||
img.src = byteArrayToBase64(byte_array);
|
||||
}
|
||||
}
|
||||
function resizeCanvas(canvas, size) {
|
||||
if (canvas.width !== size.width) {
|
||||
canvas.width = size.width;
|
||||
}
|
||||
if (canvas.height !== size.height) {
|
||||
canvas.height = size.height;
|
||||
}
|
||||
}
|
||||
function glitchJpegBytes(byte_array, jpg_header_length, seed, amount, i, len) {
|
||||
var max_index = byte_array.length - jpg_header_length - 4;
|
||||
var px_min = parseInt(max_index / len * i, 10);
|
||||
var px_max = parseInt(max_index / len * (i + 1), 10);
|
||||
var delta = px_max - px_min;
|
||||
var px_i = parseInt(px_min + delta * seed, 10);
|
||||
if (px_i > max_index) {
|
||||
px_i = max_index;
|
||||
}
|
||||
var index = Math.floor(jpg_header_length + px_i);
|
||||
byte_array[index] = Math.floor(amount * 256);
|
||||
}
|
||||
function getBase64FromImageData(image_data, quality) {
|
||||
var q = typeof quality === "number" && quality < 1 && quality > 0 ? quality : .1;
|
||||
ctx_2.putImageData(image_data, 0, 0);
|
||||
var base64 = canvas_2.toDataURL("image/jpeg", q);
|
||||
switch (base64.length % 4) {
|
||||
case 3:
|
||||
base64 += "=";
|
||||
break;
|
||||
|
||||
case 2:
|
||||
base64 += "==";
|
||||
break;
|
||||
|
||||
case 1:
|
||||
base64 += "===";
|
||||
break;
|
||||
}
|
||||
return base64;
|
||||
}
|
||||
function getJpegHeaderSize(data) {
|
||||
var result = 417;
|
||||
for (i = 0, len = data.length; i < len; i++) {
|
||||
if (data[i] === 255 && data[i + 1] === 218) {
|
||||
result = i + 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function base64ToByteArray(str) {
|
||||
var result = [];
|
||||
var digit_num;
|
||||
var cur;
|
||||
var prev;
|
||||
for (i = 23, len = str.length; i < len; i++) {
|
||||
cur = reversed_base64_map[str.charAt(i)];
|
||||
digit_num = (i - 23) % 4;
|
||||
switch (digit_num) {
|
||||
case 1:
|
||||
result.push(prev << 2 | cur >> 4);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
result.push((prev & 15) << 4 | cur >> 2);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
result.push((prev & 3) << 6 | cur);
|
||||
break;
|
||||
}
|
||||
prev = cur;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function byteArrayToBase64(arr) {
|
||||
var result = [ "data:image/jpeg;base64," ];
|
||||
var byte_num;
|
||||
var cur;
|
||||
var prev;
|
||||
for (i = 0, len = arr.length; i < len; i++) {
|
||||
cur = arr[i];
|
||||
byte_num = i % 3;
|
||||
switch (byte_num) {
|
||||
case 0:
|
||||
result.push(base64_map[cur >> 2]);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
result.push(base64_map[(prev & 3) << 4 | cur >> 4]);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
result.push(base64_map[(prev & 15) << 2 | cur >> 6]);
|
||||
result.push(base64_map[cur & 63]);
|
||||
break;
|
||||
}
|
||||
prev = cur;
|
||||
}
|
||||
if (byte_num === 0) {
|
||||
result.push(base64_map[(prev & 3) << 4]);
|
||||
result.push("==");
|
||||
} else if (byte_num === 1) {
|
||||
result.push(base64_map[(prev & 15) << 2]);
|
||||
result.push("=");
|
||||
}
|
||||
return result.join("");
|
||||
}
|
||||
function getImageDataCopy(image_data) {
|
||||
var copy = ctx_2.createImageData(image_data.width, image_data.height);
|
||||
copy.data.set(image_data.data);
|
||||
return copy;
|
||||
}
|
||||
function getNormalizedParameters(parameters) {
|
||||
return {
|
||||
seed: (parameters.seed || 0) / 100,
|
||||
quality: (parameters.quality || 0) / 100,
|
||||
amount: (parameters.amount || 0) / 100,
|
||||
iterations: parameters.iterations || 0
|
||||
};
|
||||
}
|
||||
function isValidImageData(image_data) {
|
||||
if (checkType(image_data, "image_data", "object") && checkType(image_data.width, "image_data.width", "number") && checkType(image_data.height, "image_data.height", "number") && checkType(image_data.data, "image_data.data", "object") && checkType(image_data.data.length, "image_data.data.length", "number") && checkNumber(image_data.data.length, "image_data.data.length", isPositive, "> 0")) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function checkType(it, name, expected_type) {
|
||||
if (typeof it === expected_type) {
|
||||
return true;
|
||||
} else {
|
||||
error(it, "typeof " + name, '"' + expected_type + '"', '"' + typeof it + '"');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function checkNumber(it, name, condition, condition_name) {
|
||||
if (condition(it) === true) {
|
||||
return true;
|
||||
} else {
|
||||
error(it, name, condition_name, "not");
|
||||
}
|
||||
}
|
||||
function isPositive(nr) {
|
||||
return nr > 0;
|
||||
}
|
||||
function error(it, name, expected, result) {
|
||||
throw new Error("glitch(): Expected " + name + " to be " + expected + ", but it was " + result + ".");
|
||||
}
|
||||
return glitchImageData;
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,274 @@
|
||||
/*
|
||||
* JavaScript MD5 1.0.1
|
||||
* https://github.com/blueimp/JavaScript-MD5
|
||||
*
|
||||
* Copyright 2011, Sebastian Tschan
|
||||
* https://blueimp.net
|
||||
*
|
||||
* Licensed under the MIT license:
|
||||
* http://www.opensource.org/licenses/MIT
|
||||
*
|
||||
* Based on
|
||||
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
|
||||
* Digest Algorithm, as defined in RFC 1321.
|
||||
* Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
|
||||
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
|
||||
* Distributed under the BSD License
|
||||
* See http://pajhome.org.uk/crypt/md5 for more info.
|
||||
*/
|
||||
|
||||
/*jslint bitwise: true */
|
||||
/*global unescape, define */
|
||||
|
||||
(function ($) {
|
||||
'use strict';
|
||||
|
||||
/*
|
||||
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
|
||||
* to work around bugs in some JS interpreters.
|
||||
*/
|
||||
function safe_add(x, y) {
|
||||
var lsw = (x & 0xFFFF) + (y & 0xFFFF),
|
||||
msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
||||
return (msw << 16) | (lsw & 0xFFFF);
|
||||
}
|
||||
|
||||
/*
|
||||
* Bitwise rotate a 32-bit number to the left.
|
||||
*/
|
||||
function bit_rol(num, cnt) {
|
||||
return (num << cnt) | (num >>> (32 - cnt));
|
||||
}
|
||||
|
||||
/*
|
||||
* These functions implement the four basic operations the algorithm uses.
|
||||
*/
|
||||
function md5_cmn(q, a, b, x, s, t) {
|
||||
return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b);
|
||||
}
|
||||
function md5_ff(a, b, c, d, x, s, t) {
|
||||
return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
|
||||
}
|
||||
function md5_gg(a, b, c, d, x, s, t) {
|
||||
return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
|
||||
}
|
||||
function md5_hh(a, b, c, d, x, s, t) {
|
||||
return md5_cmn(b ^ c ^ d, a, b, x, s, t);
|
||||
}
|
||||
function md5_ii(a, b, c, d, x, s, t) {
|
||||
return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the MD5 of an array of little-endian words, and a bit length.
|
||||
*/
|
||||
function binl_md5(x, len) {
|
||||
/* append padding */
|
||||
x[len >> 5] |= 0x80 << (len % 32);
|
||||
x[(((len + 64) >>> 9) << 4) + 14] = len;
|
||||
|
||||
var i, olda, oldb, oldc, oldd,
|
||||
a = 1732584193,
|
||||
b = -271733879,
|
||||
c = -1732584194,
|
||||
d = 271733878;
|
||||
|
||||
for (i = 0; i < x.length; i += 16) {
|
||||
olda = a;
|
||||
oldb = b;
|
||||
oldc = c;
|
||||
oldd = d;
|
||||
|
||||
a = md5_ff(a, b, c, d, x[i], 7, -680876936);
|
||||
d = md5_ff(d, a, b, c, x[i + 1], 12, -389564586);
|
||||
c = md5_ff(c, d, a, b, x[i + 2], 17, 606105819);
|
||||
b = md5_ff(b, c, d, a, x[i + 3], 22, -1044525330);
|
||||
a = md5_ff(a, b, c, d, x[i + 4], 7, -176418897);
|
||||
d = md5_ff(d, a, b, c, x[i + 5], 12, 1200080426);
|
||||
c = md5_ff(c, d, a, b, x[i + 6], 17, -1473231341);
|
||||
b = md5_ff(b, c, d, a, x[i + 7], 22, -45705983);
|
||||
a = md5_ff(a, b, c, d, x[i + 8], 7, 1770035416);
|
||||
d = md5_ff(d, a, b, c, x[i + 9], 12, -1958414417);
|
||||
c = md5_ff(c, d, a, b, x[i + 10], 17, -42063);
|
||||
b = md5_ff(b, c, d, a, x[i + 11], 22, -1990404162);
|
||||
a = md5_ff(a, b, c, d, x[i + 12], 7, 1804603682);
|
||||
d = md5_ff(d, a, b, c, x[i + 13], 12, -40341101);
|
||||
c = md5_ff(c, d, a, b, x[i + 14], 17, -1502002290);
|
||||
b = md5_ff(b, c, d, a, x[i + 15], 22, 1236535329);
|
||||
|
||||
a = md5_gg(a, b, c, d, x[i + 1], 5, -165796510);
|
||||
d = md5_gg(d, a, b, c, x[i + 6], 9, -1069501632);
|
||||
c = md5_gg(c, d, a, b, x[i + 11], 14, 643717713);
|
||||
b = md5_gg(b, c, d, a, x[i], 20, -373897302);
|
||||
a = md5_gg(a, b, c, d, x[i + 5], 5, -701558691);
|
||||
d = md5_gg(d, a, b, c, x[i + 10], 9, 38016083);
|
||||
c = md5_gg(c, d, a, b, x[i + 15], 14, -660478335);
|
||||
b = md5_gg(b, c, d, a, x[i + 4], 20, -405537848);
|
||||
a = md5_gg(a, b, c, d, x[i + 9], 5, 568446438);
|
||||
d = md5_gg(d, a, b, c, x[i + 14], 9, -1019803690);
|
||||
c = md5_gg(c, d, a, b, x[i + 3], 14, -187363961);
|
||||
b = md5_gg(b, c, d, a, x[i + 8], 20, 1163531501);
|
||||
a = md5_gg(a, b, c, d, x[i + 13], 5, -1444681467);
|
||||
d = md5_gg(d, a, b, c, x[i + 2], 9, -51403784);
|
||||
c = md5_gg(c, d, a, b, x[i + 7], 14, 1735328473);
|
||||
b = md5_gg(b, c, d, a, x[i + 12], 20, -1926607734);
|
||||
|
||||
a = md5_hh(a, b, c, d, x[i + 5], 4, -378558);
|
||||
d = md5_hh(d, a, b, c, x[i + 8], 11, -2022574463);
|
||||
c = md5_hh(c, d, a, b, x[i + 11], 16, 1839030562);
|
||||
b = md5_hh(b, c, d, a, x[i + 14], 23, -35309556);
|
||||
a = md5_hh(a, b, c, d, x[i + 1], 4, -1530992060);
|
||||
d = md5_hh(d, a, b, c, x[i + 4], 11, 1272893353);
|
||||
c = md5_hh(c, d, a, b, x[i + 7], 16, -155497632);
|
||||
b = md5_hh(b, c, d, a, x[i + 10], 23, -1094730640);
|
||||
a = md5_hh(a, b, c, d, x[i + 13], 4, 681279174);
|
||||
d = md5_hh(d, a, b, c, x[i], 11, -358537222);
|
||||
c = md5_hh(c, d, a, b, x[i + 3], 16, -722521979);
|
||||
b = md5_hh(b, c, d, a, x[i + 6], 23, 76029189);
|
||||
a = md5_hh(a, b, c, d, x[i + 9], 4, -640364487);
|
||||
d = md5_hh(d, a, b, c, x[i + 12], 11, -421815835);
|
||||
c = md5_hh(c, d, a, b, x[i + 15], 16, 530742520);
|
||||
b = md5_hh(b, c, d, a, x[i + 2], 23, -995338651);
|
||||
|
||||
a = md5_ii(a, b, c, d, x[i], 6, -198630844);
|
||||
d = md5_ii(d, a, b, c, x[i + 7], 10, 1126891415);
|
||||
c = md5_ii(c, d, a, b, x[i + 14], 15, -1416354905);
|
||||
b = md5_ii(b, c, d, a, x[i + 5], 21, -57434055);
|
||||
a = md5_ii(a, b, c, d, x[i + 12], 6, 1700485571);
|
||||
d = md5_ii(d, a, b, c, x[i + 3], 10, -1894986606);
|
||||
c = md5_ii(c, d, a, b, x[i + 10], 15, -1051523);
|
||||
b = md5_ii(b, c, d, a, x[i + 1], 21, -2054922799);
|
||||
a = md5_ii(a, b, c, d, x[i + 8], 6, 1873313359);
|
||||
d = md5_ii(d, a, b, c, x[i + 15], 10, -30611744);
|
||||
c = md5_ii(c, d, a, b, x[i + 6], 15, -1560198380);
|
||||
b = md5_ii(b, c, d, a, x[i + 13], 21, 1309151649);
|
||||
a = md5_ii(a, b, c, d, x[i + 4], 6, -145523070);
|
||||
d = md5_ii(d, a, b, c, x[i + 11], 10, -1120210379);
|
||||
c = md5_ii(c, d, a, b, x[i + 2], 15, 718787259);
|
||||
b = md5_ii(b, c, d, a, x[i + 9], 21, -343485551);
|
||||
|
||||
a = safe_add(a, olda);
|
||||
b = safe_add(b, oldb);
|
||||
c = safe_add(c, oldc);
|
||||
d = safe_add(d, oldd);
|
||||
}
|
||||
return [a, b, c, d];
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert an array of little-endian words to a string
|
||||
*/
|
||||
function binl2rstr(input) {
|
||||
var i,
|
||||
output = '';
|
||||
for (i = 0; i < input.length * 32; i += 8) {
|
||||
output += String.fromCharCode((input[i >> 5] >>> (i % 32)) & 0xFF);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a raw string to an array of little-endian words
|
||||
* Characters >255 have their high-byte silently ignored.
|
||||
*/
|
||||
function rstr2binl(input) {
|
||||
var i,
|
||||
output = [];
|
||||
output[(input.length >> 2) - 1] = undefined;
|
||||
for (i = 0; i < output.length; i += 1) {
|
||||
output[i] = 0;
|
||||
}
|
||||
for (i = 0; i < input.length * 8; i += 8) {
|
||||
output[i >> 5] |= (input.charCodeAt(i / 8) & 0xFF) << (i % 32);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the MD5 of a raw string
|
||||
*/
|
||||
function rstr_md5(s) {
|
||||
return binl2rstr(binl_md5(rstr2binl(s), s.length * 8));
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the HMAC-MD5, of a key and some data (raw strings)
|
||||
*/
|
||||
function rstr_hmac_md5(key, data) {
|
||||
var i,
|
||||
bkey = rstr2binl(key),
|
||||
ipad = [],
|
||||
opad = [],
|
||||
hash;
|
||||
ipad[15] = opad[15] = undefined;
|
||||
if (bkey.length > 16) {
|
||||
bkey = binl_md5(bkey, key.length * 8);
|
||||
}
|
||||
for (i = 0; i < 16; i += 1) {
|
||||
ipad[i] = bkey[i] ^ 0x36363636;
|
||||
opad[i] = bkey[i] ^ 0x5C5C5C5C;
|
||||
}
|
||||
hash = binl_md5(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
|
||||
return binl2rstr(binl_md5(opad.concat(hash), 512 + 128));
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a raw string to a hex string
|
||||
*/
|
||||
function rstr2hex(input) {
|
||||
var hex_tab = '0123456789abcdef',
|
||||
output = '',
|
||||
x,
|
||||
i;
|
||||
for (i = 0; i < input.length; i += 1) {
|
||||
x = input.charCodeAt(i);
|
||||
output += hex_tab.charAt((x >>> 4) & 0x0F) +
|
||||
hex_tab.charAt(x & 0x0F);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
* Encode a string as utf-8
|
||||
*/
|
||||
function str2rstr_utf8(input) {
|
||||
return unescape(encodeURIComponent(input));
|
||||
}
|
||||
|
||||
/*
|
||||
* Take string arguments and return either raw or hex encoded strings
|
||||
*/
|
||||
function raw_md5(s) {
|
||||
return rstr_md5(str2rstr_utf8(s));
|
||||
}
|
||||
function hex_md5(s) {
|
||||
return rstr2hex(raw_md5(s));
|
||||
}
|
||||
function raw_hmac_md5(k, d) {
|
||||
return rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d));
|
||||
}
|
||||
function hex_hmac_md5(k, d) {
|
||||
return rstr2hex(raw_hmac_md5(k, d));
|
||||
}
|
||||
|
||||
function md5(string, key, raw) {
|
||||
if (!key) {
|
||||
if (!raw) {
|
||||
return hex_md5(string);
|
||||
}
|
||||
return raw_md5(string);
|
||||
}
|
||||
if (!raw) {
|
||||
return hex_hmac_md5(key, string);
|
||||
}
|
||||
return raw_hmac_md5(key, string);
|
||||
}
|
||||
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define(function () {
|
||||
return md5;
|
||||
});
|
||||
} else {
|
||||
$.md5 = md5;
|
||||
}
|
||||
}(this));
|
||||
@@ -1,31 +0,0 @@
|
||||
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
|
||||
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
|
||||
|
||||
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
|
||||
|
||||
// MIT license
|
||||
|
||||
(function() {
|
||||
var lastTime = 0;
|
||||
var vendors = ['ms', 'moz', 'webkit', 'o'];
|
||||
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
|
||||
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
|
||||
window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
|
||||
|| window[vendors[x]+'CancelRequestAnimationFrame'];
|
||||
}
|
||||
|
||||
if (!window.requestAnimationFrame)
|
||||
window.requestAnimationFrame = function(callback, element) {
|
||||
var currTime = new Date().getTime();
|
||||
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
|
||||
var id = window.setTimeout(function() { callback(currTime + timeToCall); },
|
||||
timeToCall);
|
||||
lastTime = currTime + timeToCall;
|
||||
return id;
|
||||
};
|
||||
|
||||
if (!window.cancelAnimationFrame)
|
||||
window.cancelAnimationFrame = function(id) {
|
||||
clearTimeout(id);
|
||||
};
|
||||
}());
|
||||
@@ -1,5 +1,5 @@
|
||||
/** vim: et:ts=4:sw=4:sts=4
|
||||
* @license RequireJS 2.1.4 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
|
||||
* @license RequireJS 2.1.20 Copyright (c) 2010-2015, The Dojo Foundation All Rights Reserved.
|
||||
* Available via the MIT or new BSD license.
|
||||
* see: http://github.com/jrburke/requirejs for details
|
||||
*/
|
||||
@@ -12,7 +12,7 @@ var requirejs, require, define;
|
||||
(function (global) {
|
||||
var req, s, head, baseElement, dataMain, src,
|
||||
interactiveScript, currentlyAddingScript, mainScript, subPath,
|
||||
version = '2.1.4',
|
||||
version = '2.1.20',
|
||||
commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,
|
||||
cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,
|
||||
jsSuffixRegExp = /\.js$/,
|
||||
@@ -21,8 +21,7 @@ var requirejs, require, define;
|
||||
ostring = op.toString,
|
||||
hasOwn = op.hasOwnProperty,
|
||||
ap = Array.prototype,
|
||||
apsp = ap.splice,
|
||||
isBrowser = !!(typeof window !== 'undefined' && navigator && document),
|
||||
isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document),
|
||||
isWebWorker = !isBrowser && typeof importScripts !== 'undefined',
|
||||
//PS3 indicates loaded and complete, but need to wait for complete
|
||||
//specifically. Sequence is 'loading', 'loaded', execution,
|
||||
@@ -108,7 +107,10 @@ var requirejs, require, define;
|
||||
if (source) {
|
||||
eachProp(source, function (value, prop) {
|
||||
if (force || !hasProp(target, prop)) {
|
||||
if (deepStringMixin && typeof value !== 'string') {
|
||||
if (deepStringMixin && typeof value === 'object' && value &&
|
||||
!isArray(value) && !isFunction(value) &&
|
||||
!(value instanceof RegExp)) {
|
||||
|
||||
if (!target[prop]) {
|
||||
target[prop] = {};
|
||||
}
|
||||
@@ -134,7 +136,11 @@ var requirejs, require, define;
|
||||
return document.getElementsByTagName('script');
|
||||
}
|
||||
|
||||
//Allow getting a global that expressed in
|
||||
function defaultOnError(err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
//Allow getting a global that is expressed in
|
||||
//dot notation, like 'a.b.c'.
|
||||
function getGlobal(value) {
|
||||
if (!value) {
|
||||
@@ -173,7 +179,7 @@ var requirejs, require, define;
|
||||
|
||||
if (typeof requirejs !== 'undefined') {
|
||||
if (isFunction(requirejs)) {
|
||||
//Do not overwrite and existing requirejs instance.
|
||||
//Do not overwrite an existing requirejs instance.
|
||||
return;
|
||||
}
|
||||
cfg = requirejs;
|
||||
@@ -191,19 +197,27 @@ var requirejs, require, define;
|
||||
var inCheckLoaded, Module, context, handlers,
|
||||
checkLoadedTimeoutId,
|
||||
config = {
|
||||
//Defaults. Do not set a default for map
|
||||
//config to speed up normalize(), which
|
||||
//will run faster if there is no default.
|
||||
waitSeconds: 7,
|
||||
baseUrl: './',
|
||||
paths: {},
|
||||
bundles: {},
|
||||
pkgs: {},
|
||||
shim: {},
|
||||
map: {},
|
||||
config: {}
|
||||
},
|
||||
registry = {},
|
||||
//registry of just enabled modules, to speed
|
||||
//cycle breaking code when lots of modules
|
||||
//are registered, but not activated.
|
||||
enabledRegistry = {},
|
||||
undefEvents = {},
|
||||
defQueue = [],
|
||||
defined = {},
|
||||
urlFetched = {},
|
||||
bundlesMap = {},
|
||||
requireCounter = 1,
|
||||
unnormalizedCounter = 1;
|
||||
|
||||
@@ -218,20 +232,19 @@ var requirejs, require, define;
|
||||
*/
|
||||
function trimDots(ary) {
|
||||
var i, part;
|
||||
for (i = 0; ary[i]; i += 1) {
|
||||
for (i = 0; i < ary.length; i++) {
|
||||
part = ary[i];
|
||||
if (part === '.') {
|
||||
ary.splice(i, 1);
|
||||
i -= 1;
|
||||
} else if (part === '..') {
|
||||
if (i === 1 && (ary[2] === '..' || ary[0] === '..')) {
|
||||
//End of the line. Keep at least one non-dot
|
||||
//path segment at the front so it can be mapped
|
||||
//correctly to disk. Otherwise, there is likely
|
||||
//no path mapping for a path starting with '..'.
|
||||
//This can still fail, but catches the most reasonable
|
||||
//uses of ..
|
||||
break;
|
||||
// If at the start, or previous value is still ..,
|
||||
// keep them so that when converted to a path it may
|
||||
// still work when converted to a path, even though
|
||||
// as an ID it is less than ideal. In larger point
|
||||
// releases, may be better to just kick out an error.
|
||||
if (i === 0 || (i === 1 && ary[2] === '..') || ary[i - 1] === '..') {
|
||||
continue;
|
||||
} else if (i > 0) {
|
||||
ary.splice(i - 1, 2);
|
||||
i -= 2;
|
||||
@@ -251,54 +264,45 @@ var requirejs, require, define;
|
||||
* @returns {String} normalized name
|
||||
*/
|
||||
function normalize(name, baseName, applyMap) {
|
||||
var pkgName, pkgConfig, mapValue, nameParts, i, j, nameSegment,
|
||||
foundMap, foundI, foundStarMap, starI,
|
||||
baseParts = baseName && baseName.split('/'),
|
||||
normalizedBaseParts = baseParts,
|
||||
var pkgMain, mapValue, nameParts, i, j, nameSegment, lastIndex,
|
||||
foundMap, foundI, foundStarMap, starI, normalizedBaseParts,
|
||||
baseParts = (baseName && baseName.split('/')),
|
||||
map = config.map,
|
||||
starMap = map && map['*'];
|
||||
|
||||
//Adjust any relative paths.
|
||||
if (name && name.charAt(0) === '.') {
|
||||
//If have a base name, try to normalize against it,
|
||||
//otherwise, assume it is a top-level require that will
|
||||
//be relative to baseUrl in the end.
|
||||
if (baseName) {
|
||||
if (getOwn(config.pkgs, baseName)) {
|
||||
//If the baseName is a package name, then just treat it as one
|
||||
//name to concat the name with.
|
||||
normalizedBaseParts = baseParts = [baseName];
|
||||
} else {
|
||||
//Convert baseName to array, and lop off the last part,
|
||||
//so that . matches that 'directory' and not name of the baseName's
|
||||
//module. For instance, baseName of 'one/two/three', maps to
|
||||
//'one/two/three.js', but we want the directory, 'one/two' for
|
||||
//this normalization.
|
||||
normalizedBaseParts = baseParts.slice(0, baseParts.length - 1);
|
||||
}
|
||||
if (name) {
|
||||
name = name.split('/');
|
||||
lastIndex = name.length - 1;
|
||||
|
||||
name = normalizedBaseParts.concat(name.split('/'));
|
||||
trimDots(name);
|
||||
|
||||
//Some use of packages may use a . path to reference the
|
||||
//'main' module name, so normalize for that.
|
||||
pkgConfig = getOwn(config.pkgs, (pkgName = name[0]));
|
||||
name = name.join('/');
|
||||
if (pkgConfig && name === pkgName + '/' + pkgConfig.main) {
|
||||
name = pkgName;
|
||||
}
|
||||
} else if (name.indexOf('./') === 0) {
|
||||
// No baseName, so this is ID is resolved relative
|
||||
// to baseUrl, pull off the leading dot.
|
||||
name = name.substring(2);
|
||||
// If wanting node ID compatibility, strip .js from end
|
||||
// of IDs. Have to do this here, and not in nameToUrl
|
||||
// because node allows either .js or non .js to map
|
||||
// to same file.
|
||||
if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
|
||||
name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
|
||||
}
|
||||
|
||||
// Starts with a '.' so need the baseName
|
||||
if (name[0].charAt(0) === '.' && baseParts) {
|
||||
//Convert baseName to array, and lop off the last part,
|
||||
//so that . matches that 'directory' and not name of the baseName's
|
||||
//module. For instance, baseName of 'one/two/three', maps to
|
||||
//'one/two/three.js', but we want the directory, 'one/two' for
|
||||
//this normalization.
|
||||
normalizedBaseParts = baseParts.slice(0, baseParts.length - 1);
|
||||
name = normalizedBaseParts.concat(name);
|
||||
}
|
||||
|
||||
trimDots(name);
|
||||
name = name.join('/');
|
||||
}
|
||||
|
||||
//Apply map config if available.
|
||||
if (applyMap && (baseParts || starMap) && map) {
|
||||
if (applyMap && map && (baseParts || starMap)) {
|
||||
nameParts = name.split('/');
|
||||
|
||||
for (i = nameParts.length; i > 0; i -= 1) {
|
||||
outerLoop: for (i = nameParts.length; i > 0; i -= 1) {
|
||||
nameSegment = nameParts.slice(0, i).join('/');
|
||||
|
||||
if (baseParts) {
|
||||
@@ -315,16 +319,12 @@ var requirejs, require, define;
|
||||
//Match, update name to the new value.
|
||||
foundMap = mapValue;
|
||||
foundI = i;
|
||||
break;
|
||||
break outerLoop;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (foundMap) {
|
||||
break;
|
||||
}
|
||||
|
||||
//Check for a star map match, but just hold on to it,
|
||||
//if there is a shorter segment match later in a matching
|
||||
//config, then favor over this star map.
|
||||
@@ -345,7 +345,11 @@ var requirejs, require, define;
|
||||
}
|
||||
}
|
||||
|
||||
return name;
|
||||
// If the name points to a package's name, use
|
||||
// the package main instead.
|
||||
pkgMain = getOwn(config.pkgs, name);
|
||||
|
||||
return pkgMain ? pkgMain : name;
|
||||
}
|
||||
|
||||
function removeScript(name) {
|
||||
@@ -363,12 +367,17 @@ var requirejs, require, define;
|
||||
function hasPathFallback(id) {
|
||||
var pathConfig = getOwn(config.paths, id);
|
||||
if (pathConfig && isArray(pathConfig) && pathConfig.length > 1) {
|
||||
removeScript(id);
|
||||
//Pop off the first array value, since it failed, and
|
||||
//retry
|
||||
pathConfig.shift();
|
||||
context.require.undef(id);
|
||||
context.require([id]);
|
||||
|
||||
//Custom require that does not do map translation, since
|
||||
//ID is "absolute", already mapped/resolved.
|
||||
context.makeRequire(null, {
|
||||
skipMap: true
|
||||
})([id]);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -434,7 +443,16 @@ var requirejs, require, define;
|
||||
return normalize(name, parentName, applyMap);
|
||||
});
|
||||
} else {
|
||||
normalizedName = normalize(name, parentName, applyMap);
|
||||
// If nested plugin references, then do not try to
|
||||
// normalize, as it will not normalize correctly. This
|
||||
// places a restriction on resourceIds, and the longer
|
||||
// term solution is not to normalize until plugins are
|
||||
// loaded and all normalizations to allow for async
|
||||
// loading of a loader plugin. But for now, fixes the
|
||||
// common uses. Details in #1131
|
||||
normalizedName = name.indexOf('!') === -1 ?
|
||||
normalize(name, parentName, applyMap) :
|
||||
name;
|
||||
}
|
||||
} else {
|
||||
//A regular module.
|
||||
@@ -494,7 +512,12 @@ var requirejs, require, define;
|
||||
fn(defined[id]);
|
||||
}
|
||||
} else {
|
||||
getModule(depMap).on(name, fn);
|
||||
mod = getModule(depMap);
|
||||
if (mod.error && name === 'error') {
|
||||
fn(mod.error);
|
||||
} else {
|
||||
mod.on(name, fn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -530,11 +553,13 @@ var requirejs, require, define;
|
||||
function takeGlobalQueue() {
|
||||
//Push all the globalDefQueue items into the context's defQueue
|
||||
if (globalDefQueue.length) {
|
||||
//Array splice in the values since the context code has a
|
||||
//local var ref to defQueue, so cannot just reassign the one
|
||||
//on context.
|
||||
apsp.apply(defQueue,
|
||||
[defQueue.length - 1, 0].concat(globalDefQueue));
|
||||
each(globalDefQueue, function(queueItem) {
|
||||
var id = queueItem[0];
|
||||
if (typeof id === 'string') {
|
||||
context.defQueueMap[id] = true;
|
||||
}
|
||||
defQueue.push(queueItem);
|
||||
});
|
||||
globalDefQueue = [];
|
||||
}
|
||||
}
|
||||
@@ -551,7 +576,7 @@ var requirejs, require, define;
|
||||
mod.usingExports = true;
|
||||
if (mod.map.isDefine) {
|
||||
if (mod.exports) {
|
||||
return mod.exports;
|
||||
return (defined[mod.map.id] = mod.exports);
|
||||
} else {
|
||||
return (mod.exports = defined[mod.map.id] = {});
|
||||
}
|
||||
@@ -565,9 +590,9 @@ var requirejs, require, define;
|
||||
id: mod.map.id,
|
||||
uri: mod.map.url,
|
||||
config: function () {
|
||||
return (config.config && getOwn(config.config, mod.map.id)) || {};
|
||||
return getOwn(config.config, mod.map.id) || {};
|
||||
},
|
||||
exports: defined[mod.map.id]
|
||||
exports: mod.exports || (mod.exports = {})
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -576,6 +601,7 @@ var requirejs, require, define;
|
||||
function cleanRegistry(id) {
|
||||
//Clean up machinery used for waiting modules.
|
||||
delete registry[id];
|
||||
delete enabledRegistry[id];
|
||||
}
|
||||
|
||||
function breakCycle(mod, traced, processed) {
|
||||
@@ -607,7 +633,7 @@ var requirejs, require, define;
|
||||
}
|
||||
|
||||
function checkLoaded() {
|
||||
var map, modId, err, usingPathFallback,
|
||||
var err, usingPathFallback,
|
||||
waitInterval = config.waitSeconds * 1000,
|
||||
//It is possible to disable the wait interval by using waitSeconds of 0.
|
||||
expired = waitInterval && (context.startTime + waitInterval) < new Date().getTime(),
|
||||
@@ -624,9 +650,9 @@ var requirejs, require, define;
|
||||
inCheckLoaded = true;
|
||||
|
||||
//Figure out the state of all the modules.
|
||||
eachProp(registry, function (mod) {
|
||||
map = mod.map;
|
||||
modId = map.id;
|
||||
eachProp(enabledRegistry, function (mod) {
|
||||
var map = mod.map,
|
||||
modId = map.id;
|
||||
|
||||
//Skip things that are not enabled or in error state.
|
||||
if (!mod.enabled) {
|
||||
@@ -805,7 +831,7 @@ var requirejs, require, define;
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks is the module is ready to define itself, and if so,
|
||||
* Checks if the module is ready to define itself, and if so,
|
||||
* define it.
|
||||
*/
|
||||
check: function () {
|
||||
@@ -820,7 +846,10 @@ var requirejs, require, define;
|
||||
factory = this.factory;
|
||||
|
||||
if (!this.inited) {
|
||||
this.fetch();
|
||||
// Only fetch if not already in the defQueue.
|
||||
if (!hasProp(context.defQueueMap, id)) {
|
||||
this.fetch();
|
||||
}
|
||||
} else if (this.error) {
|
||||
this.emit('error', this.error);
|
||||
} else if (!this.defining) {
|
||||
@@ -833,8 +862,13 @@ var requirejs, require, define;
|
||||
if (this.depCount < 1 && !this.defined) {
|
||||
if (isFunction(factory)) {
|
||||
//If there is an error listener, favor passing
|
||||
//to that instead of throwing an error.
|
||||
if (this.events.error) {
|
||||
//to that instead of throwing an error. However,
|
||||
//only do it for define()'d modules. require
|
||||
//errbacks should not be called for failures in
|
||||
//their callbacks (#699). However if a global
|
||||
//onError is set, use that.
|
||||
if ((this.events.error && this.map.isDefine) ||
|
||||
req.onError !== defaultOnError) {
|
||||
try {
|
||||
exports = context.execCb(id, factory, depExports, exports);
|
||||
} catch (e) {
|
||||
@@ -844,17 +878,14 @@ var requirejs, require, define;
|
||||
exports = context.execCb(id, factory, depExports, exports);
|
||||
}
|
||||
|
||||
if (this.map.isDefine) {
|
||||
//If setting exports via 'module' is in play,
|
||||
//favor that over return value and exports. After that,
|
||||
//favor a non-undefined return value over exports use.
|
||||
// Favor return value over exports. If node/cjs in play,
|
||||
// then will not have a return value anyway. Favor
|
||||
// module.exports assignment over exports object.
|
||||
if (this.map.isDefine && exports === undefined) {
|
||||
cjsModule = this.module;
|
||||
if (cjsModule &&
|
||||
cjsModule.exports !== undefined &&
|
||||
//Make sure it is not already the exports value
|
||||
cjsModule.exports !== this.exports) {
|
||||
if (cjsModule) {
|
||||
exports = cjsModule.exports;
|
||||
} else if (exports === undefined && this.usingExports) {
|
||||
} else if (this.usingExports) {
|
||||
//exports already set the defined value.
|
||||
exports = this.exports;
|
||||
}
|
||||
@@ -862,8 +893,8 @@ var requirejs, require, define;
|
||||
|
||||
if (err) {
|
||||
err.requireMap = this.map;
|
||||
err.requireModules = [this.map.id];
|
||||
err.requireType = 'define';
|
||||
err.requireModules = this.map.isDefine ? [this.map.id] : null;
|
||||
err.requireType = this.map.isDefine ? 'define' : 'require';
|
||||
return onError((this.error = err));
|
||||
}
|
||||
|
||||
@@ -883,7 +914,7 @@ var requirejs, require, define;
|
||||
}
|
||||
|
||||
//Clean up
|
||||
delete registry[id];
|
||||
cleanRegistry(id);
|
||||
|
||||
this.defined = true;
|
||||
}
|
||||
@@ -914,6 +945,7 @@ var requirejs, require, define;
|
||||
|
||||
on(pluginMap, 'defined', bind(this, function (plugin) {
|
||||
var load, normalizedMap, normalizedMod,
|
||||
bundleId = getOwn(bundlesMap, this.map.id),
|
||||
name = this.map.name,
|
||||
parentName = this.map.parentMap ? this.map.parentMap.name : null,
|
||||
localRequire = context.makeRequire(map.parentMap, {
|
||||
@@ -959,6 +991,14 @@ var requirejs, require, define;
|
||||
return;
|
||||
}
|
||||
|
||||
//If a paths config, then just load that file instead to
|
||||
//resolve the plugin, as it is built into that paths layer.
|
||||
if (bundleId) {
|
||||
this.map.url = context.nameToUrl(bundleId);
|
||||
this.load();
|
||||
return;
|
||||
}
|
||||
|
||||
load = bind(this, function (value) {
|
||||
this.init([], function () { return value; }, null, {
|
||||
enabled: true
|
||||
@@ -1049,6 +1089,7 @@ var requirejs, require, define;
|
||||
},
|
||||
|
||||
enable: function () {
|
||||
enabledRegistry[this.map.id] = this;
|
||||
this.enabled = true;
|
||||
|
||||
//Set flag mentioning that the module is enabling,
|
||||
@@ -1080,12 +1121,22 @@ var requirejs, require, define;
|
||||
this.depCount += 1;
|
||||
|
||||
on(depMap, 'defined', bind(this, function (depExports) {
|
||||
if (this.undefed) {
|
||||
return;
|
||||
}
|
||||
this.defineDep(i, depExports);
|
||||
this.check();
|
||||
}));
|
||||
|
||||
if (this.errback) {
|
||||
on(depMap, 'error', this.errback);
|
||||
on(depMap, 'error', bind(this, this.errback));
|
||||
} else if (this.events.error) {
|
||||
// No direct errback on this module, but something
|
||||
// else is listening for errors, so be sure to
|
||||
// propagate the error correctly.
|
||||
on(depMap, 'error', bind(this, function(err) {
|
||||
this.emit('error', err);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1189,13 +1240,15 @@ var requirejs, require, define;
|
||||
while (defQueue.length) {
|
||||
args = defQueue.shift();
|
||||
if (args[0] === null) {
|
||||
return onError(makeError('mismatch', 'Mismatched anonymous define() module: ' + args[args.length - 1]));
|
||||
return onError(makeError('mismatch', 'Mismatched anonymous define() module: ' +
|
||||
args[args.length - 1]));
|
||||
} else {
|
||||
//args are id, deps, factory. Should be normalized by the
|
||||
//define() function.
|
||||
callGetModule(args);
|
||||
}
|
||||
}
|
||||
context.defQueueMap = {};
|
||||
}
|
||||
|
||||
context = {
|
||||
@@ -1205,9 +1258,11 @@ var requirejs, require, define;
|
||||
defined: defined,
|
||||
urlFetched: urlFetched,
|
||||
defQueue: defQueue,
|
||||
defQueueMap: {},
|
||||
Module: Module,
|
||||
makeModuleMap: makeModuleMap,
|
||||
nextTick: req.nextTick,
|
||||
onError: onError,
|
||||
|
||||
/**
|
||||
* Set a configuration for the context.
|
||||
@@ -1221,28 +1276,38 @@ var requirejs, require, define;
|
||||
}
|
||||
}
|
||||
|
||||
//Save off the paths and packages since they require special processing,
|
||||
//Save off the paths since they require special processing,
|
||||
//they are additive.
|
||||
var pkgs = config.pkgs,
|
||||
shim = config.shim,
|
||||
var shim = config.shim,
|
||||
objs = {
|
||||
paths: true,
|
||||
bundles: true,
|
||||
config: true,
|
||||
map: true
|
||||
};
|
||||
|
||||
eachProp(cfg, function (value, prop) {
|
||||
if (objs[prop]) {
|
||||
if (prop === 'map') {
|
||||
mixin(config[prop], value, true, true);
|
||||
} else {
|
||||
mixin(config[prop], value, true);
|
||||
if (!config[prop]) {
|
||||
config[prop] = {};
|
||||
}
|
||||
mixin(config[prop], value, true, true);
|
||||
} else {
|
||||
config[prop] = value;
|
||||
}
|
||||
});
|
||||
|
||||
//Reverse map the bundles
|
||||
if (cfg.bundles) {
|
||||
eachProp(cfg.bundles, function (value, prop) {
|
||||
each(value, function (v) {
|
||||
if (v !== prop) {
|
||||
bundlesMap[v] = prop;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//Merge shim
|
||||
if (cfg.shim) {
|
||||
eachProp(cfg.shim, function (value, id) {
|
||||
@@ -1263,29 +1328,25 @@ var requirejs, require, define;
|
||||
//Adjust packages if necessary.
|
||||
if (cfg.packages) {
|
||||
each(cfg.packages, function (pkgObj) {
|
||||
var location;
|
||||
var location, name;
|
||||
|
||||
pkgObj = typeof pkgObj === 'string' ? { name: pkgObj } : pkgObj;
|
||||
pkgObj = typeof pkgObj === 'string' ? {name: pkgObj} : pkgObj;
|
||||
|
||||
name = pkgObj.name;
|
||||
location = pkgObj.location;
|
||||
if (location) {
|
||||
config.paths[name] = pkgObj.location;
|
||||
}
|
||||
|
||||
//Create a brand new object on pkgs, since currentPackages can
|
||||
//be passed in again, and config.pkgs is the internal transformed
|
||||
//state for all package configs.
|
||||
pkgs[pkgObj.name] = {
|
||||
name: pkgObj.name,
|
||||
location: location || pkgObj.name,
|
||||
//Remove leading dot in main, so main paths are normalized,
|
||||
//and remove any trailing .js, since different package
|
||||
//envs have different conventions: some use a module name,
|
||||
//some use a file name.
|
||||
main: (pkgObj.main || 'main')
|
||||
.replace(currDirRegExp, '')
|
||||
.replace(jsSuffixRegExp, '')
|
||||
};
|
||||
//Save pointer to main module ID for pkg name.
|
||||
//Remove leading dot in main, so main paths are normalized,
|
||||
//and remove any trailing .js, since different package
|
||||
//envs have different conventions: some use a module name,
|
||||
//some use a file name.
|
||||
config.pkgs[name] = pkgObj.name + '/' + (pkgObj.main || 'main')
|
||||
.replace(currDirRegExp, '')
|
||||
.replace(jsSuffixRegExp, '');
|
||||
});
|
||||
|
||||
//Done with modifications, assing packages back to context config
|
||||
config.pkgs = pkgs;
|
||||
}
|
||||
|
||||
//If there are any "waiting to execute" modules in the registry,
|
||||
@@ -1296,7 +1357,7 @@ var requirejs, require, define;
|
||||
//late to modify them, and ignore unnormalized ones
|
||||
//since they are transient.
|
||||
if (!mod.inited && !mod.map.unnormalized) {
|
||||
mod.map = makeModuleMap(id);
|
||||
mod.map = makeModuleMap(id, null, true);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1345,7 +1406,7 @@ var requirejs, require, define;
|
||||
//Synchronous access to one module. If require.get is
|
||||
//available (as in the Node adapter), prefer that.
|
||||
if (req.get) {
|
||||
return req.get(context, deps, relMap);
|
||||
return req.get(context, deps, relMap, localRequire);
|
||||
}
|
||||
|
||||
//Normalize module name, if it contains . or ..
|
||||
@@ -1396,7 +1457,7 @@ var requirejs, require, define;
|
||||
* plain URLs like nameToUrl.
|
||||
*/
|
||||
toUrl: function (moduleNamePlusExt) {
|
||||
var ext, url,
|
||||
var ext,
|
||||
index = moduleNamePlusExt.lastIndexOf('.'),
|
||||
segment = moduleNamePlusExt.split('/')[0],
|
||||
isRelative = segment === '.' || segment === '..';
|
||||
@@ -1408,9 +1469,8 @@ var requirejs, require, define;
|
||||
moduleNamePlusExt = moduleNamePlusExt.substring(0, index);
|
||||
}
|
||||
|
||||
url = context.nameToUrl(normalize(moduleNamePlusExt,
|
||||
relMap && relMap.id, true), ext || '.fake');
|
||||
return ext ? url : url.substring(0, url.length - 5);
|
||||
return context.nameToUrl(normalize(moduleNamePlusExt,
|
||||
relMap && relMap.id, true), ext, true);
|
||||
},
|
||||
|
||||
defined: function (id) {
|
||||
@@ -1433,10 +1493,23 @@ var requirejs, require, define;
|
||||
var map = makeModuleMap(id, relMap, true),
|
||||
mod = getOwn(registry, id);
|
||||
|
||||
mod.undefed = true;
|
||||
removeScript(id);
|
||||
|
||||
delete defined[id];
|
||||
delete urlFetched[map.url];
|
||||
delete undefEvents[id];
|
||||
|
||||
//Clean queued defines too. Go backwards
|
||||
//in array so that the splices do not
|
||||
//mess up the iteration.
|
||||
eachReverse(defQueue, function(args, i) {
|
||||
if (args[0] === id) {
|
||||
defQueue.splice(i, 1);
|
||||
}
|
||||
});
|
||||
delete context.defQueueMap[id];
|
||||
|
||||
if (mod) {
|
||||
//Hold on to listeners in case the
|
||||
//module will be attempted to be reloaded
|
||||
@@ -1456,7 +1529,7 @@ var requirejs, require, define;
|
||||
/**
|
||||
* Called to enable a module if it is still in the registry
|
||||
* awaiting enablement. A second arg, parent, the parent module,
|
||||
* is passed in for context, when this method is overriden by
|
||||
* is passed in for context, when this method is overridden by
|
||||
* the optimizer. Not shown here to keep code compact.
|
||||
*/
|
||||
enable: function (depMap) {
|
||||
@@ -1497,6 +1570,7 @@ var requirejs, require, define;
|
||||
|
||||
callGetModule(args);
|
||||
}
|
||||
context.defQueueMap = {};
|
||||
|
||||
//Do this after the cycle of callGetModule in case the result
|
||||
//of those calls/init calls changes the registry.
|
||||
@@ -1529,9 +1603,20 @@ var requirejs, require, define;
|
||||
* it is assumed to have already been normalized. This is an
|
||||
* internal API, not a public one. Use toUrl for the public API.
|
||||
*/
|
||||
nameToUrl: function (moduleName, ext) {
|
||||
var paths, pkgs, pkg, pkgPath, syms, i, parentModule, url,
|
||||
parentPath;
|
||||
nameToUrl: function (moduleName, ext, skipExt) {
|
||||
var paths, syms, i, parentModule, url,
|
||||
parentPath, bundleId,
|
||||
pkgMain = getOwn(config.pkgs, moduleName);
|
||||
|
||||
if (pkgMain) {
|
||||
moduleName = pkgMain;
|
||||
}
|
||||
|
||||
bundleId = getOwn(bundlesMap, moduleName);
|
||||
|
||||
if (bundleId) {
|
||||
return context.nameToUrl(bundleId, ext, skipExt);
|
||||
}
|
||||
|
||||
//If a colon is in the URL, it indicates a protocol is used and it is just
|
||||
//an URL to a file, or if it starts with a slash, contains a query arg (i.e. ?)
|
||||
@@ -1545,7 +1630,6 @@ var requirejs, require, define;
|
||||
} else {
|
||||
//A module that needs to be converted to a path.
|
||||
paths = config.paths;
|
||||
pkgs = config.pkgs;
|
||||
|
||||
syms = moduleName.split('/');
|
||||
//For each module name segment, see if there is a path
|
||||
@@ -1553,7 +1637,7 @@ var requirejs, require, define;
|
||||
//and work up from it.
|
||||
for (i = syms.length; i > 0; i -= 1) {
|
||||
parentModule = syms.slice(0, i).join('/');
|
||||
pkg = getOwn(pkgs, parentModule);
|
||||
|
||||
parentPath = getOwn(paths, parentModule);
|
||||
if (parentPath) {
|
||||
//If an array, it means there are a few choices,
|
||||
@@ -1563,22 +1647,12 @@ var requirejs, require, define;
|
||||
}
|
||||
syms.splice(0, i, parentPath);
|
||||
break;
|
||||
} else if (pkg) {
|
||||
//If module name is just the package name, then looking
|
||||
//for the main module.
|
||||
if (moduleName === pkg.name) {
|
||||
pkgPath = pkg.location + '/' + pkg.main;
|
||||
} else {
|
||||
pkgPath = pkg.location;
|
||||
}
|
||||
syms.splice(0, i, pkgPath);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Join the path parts together, then figure out if baseUrl is needed.
|
||||
url = syms.join('/');
|
||||
url += (ext || (/\?/.test(url) ? '' : '.js'));
|
||||
url += (ext || (/^data\:|\?/.test(url) || skipExt ? '' : '.js'));
|
||||
url = (url.charAt(0) === '/' || url.match(/^[\w\+\.\-]+:/) ? '' : config.baseUrl) + url;
|
||||
}
|
||||
|
||||
@@ -1594,7 +1668,7 @@ var requirejs, require, define;
|
||||
},
|
||||
|
||||
/**
|
||||
* Executes a module callack function. Broken out as a separate function
|
||||
* Executes a module callback function. Broken out as a separate function
|
||||
* solely to allow the build system to sequence the files in the built
|
||||
* layer in the right sequence.
|
||||
*
|
||||
@@ -1632,7 +1706,7 @@ var requirejs, require, define;
|
||||
onScriptError: function (evt) {
|
||||
var data = getScriptData(evt);
|
||||
if (!hasPathFallback(data.id)) {
|
||||
return onError(makeError('scripterror', 'Script error', evt, [data.id]));
|
||||
return onError(makeError('scripterror', 'Script error for: ' + data.id, evt, [data.id]));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1761,8 +1835,19 @@ var requirejs, require, define;
|
||||
* function. Intercept/override it if you want custom error handling.
|
||||
* @param {Error} err the error object.
|
||||
*/
|
||||
req.onError = function (err) {
|
||||
throw err;
|
||||
req.onError = defaultOnError;
|
||||
|
||||
/**
|
||||
* Creates the node for the load command. Only used in browser envs.
|
||||
*/
|
||||
req.createNode = function (config, moduleName, url) {
|
||||
var node = config.xhtml ?
|
||||
document.createElementNS('http://www.w3.org/1999/xhtml', 'html:script') :
|
||||
document.createElement('script');
|
||||
node.type = config.scriptType || 'text/javascript';
|
||||
node.charset = 'utf-8';
|
||||
node.async = true;
|
||||
return node;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -1779,12 +1864,10 @@ var requirejs, require, define;
|
||||
node;
|
||||
if (isBrowser) {
|
||||
//In the browser so use a script tag
|
||||
node = config.xhtml ?
|
||||
document.createElementNS('http://www.w3.org/1999/xhtml', 'html:script') :
|
||||
document.createElement('script');
|
||||
node.type = config.scriptType || 'text/javascript';
|
||||
node.charset = 'utf-8';
|
||||
node.async = true;
|
||||
node = req.createNode(config, moduleName, url);
|
||||
if (config.onNodeCreated) {
|
||||
config.onNodeCreated(node, config, moduleName, url);
|
||||
}
|
||||
|
||||
node.setAttribute('data-requirecontext', context.contextName);
|
||||
node.setAttribute('data-requiremodule', moduleName);
|
||||
@@ -1817,7 +1900,7 @@ var requirejs, require, define;
|
||||
node.attachEvent('onreadystatechange', context.onScriptLoad);
|
||||
//It would be great to add an error handler here to catch
|
||||
//404s in IE9+. However, onreadystatechange will fire before
|
||||
//the error handler, so that does not help. If addEvenListener
|
||||
//the error handler, so that does not help. If addEventListener
|
||||
//is used, then IE will fire error before load, but we cannot
|
||||
//use that pathway given the connect.microsoft.com issue
|
||||
//mentioned above about not doing the 'script execute,
|
||||
@@ -1846,16 +1929,24 @@ var requirejs, require, define;
|
||||
|
||||
return node;
|
||||
} else if (isWebWorker) {
|
||||
//In a web worker, use importScripts. This is not a very
|
||||
//efficient use of importScripts, importScripts will block until
|
||||
//its script is downloaded and evaluated. However, if web workers
|
||||
//are in play, the expectation that a build has been done so that
|
||||
//only one script needs to be loaded anyway. This may need to be
|
||||
//reevaluated if other use cases become common.
|
||||
importScripts(url);
|
||||
try {
|
||||
//In a web worker, use importScripts. This is not a very
|
||||
//efficient use of importScripts, importScripts will block until
|
||||
//its script is downloaded and evaluated. However, if web workers
|
||||
//are in play, the expectation that a build has been done so that
|
||||
//only one script needs to be loaded anyway. This may need to be
|
||||
//reevaluated if other use cases become common.
|
||||
importScripts(url);
|
||||
|
||||
//Account for anonymous modules
|
||||
context.completeLoad(moduleName);
|
||||
//Account for anonymous modules
|
||||
context.completeLoad(moduleName);
|
||||
} catch (e) {
|
||||
context.onError(makeError('importscripts',
|
||||
'importScripts failed for ' +
|
||||
moduleName + ' at ' + url,
|
||||
e,
|
||||
[moduleName]));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1873,7 +1964,7 @@ var requirejs, require, define;
|
||||
}
|
||||
|
||||
//Look for a data-main script attribute, which could also adjust the baseUrl.
|
||||
if (isBrowser) {
|
||||
if (isBrowser && !cfg.skipDataMain) {
|
||||
//Figure out baseUrl. Get it from the script tag with require.js in it.
|
||||
eachReverse(scripts(), function (script) {
|
||||
//Set the 'head' where we can append children by
|
||||
@@ -1887,24 +1978,31 @@ var requirejs, require, define;
|
||||
//baseUrl, if it is not already set.
|
||||
dataMain = script.getAttribute('data-main');
|
||||
if (dataMain) {
|
||||
//Preserve dataMain in case it is a path (i.e. contains '?')
|
||||
mainScript = dataMain;
|
||||
|
||||
//Set final baseUrl if there is not already an explicit one.
|
||||
if (!cfg.baseUrl) {
|
||||
//Pull off the directory of data-main for use as the
|
||||
//baseUrl.
|
||||
src = dataMain.split('/');
|
||||
src = mainScript.split('/');
|
||||
mainScript = src.pop();
|
||||
subPath = src.length ? src.join('/') + '/' : './';
|
||||
|
||||
cfg.baseUrl = subPath;
|
||||
dataMain = mainScript;
|
||||
}
|
||||
|
||||
//Strip off any trailing .js since dataMain is now
|
||||
//Strip off any trailing .js since mainScript is now
|
||||
//like a module name.
|
||||
dataMain = dataMain.replace(jsSuffixRegExp, '');
|
||||
mainScript = mainScript.replace(jsSuffixRegExp, '');
|
||||
|
||||
//If mainScript is still a path, fall back to dataMain
|
||||
if (req.jsExtRegExp.test(mainScript)) {
|
||||
mainScript = dataMain;
|
||||
}
|
||||
|
||||
//Put the data-main script in the files to load.
|
||||
cfg.deps = cfg.deps ? cfg.deps.concat(dataMain) : [dataMain];
|
||||
cfg.deps = cfg.deps ? cfg.deps.concat(mainScript) : [mainScript];
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1932,12 +2030,13 @@ var requirejs, require, define;
|
||||
//This module may not have dependencies
|
||||
if (!isArray(deps)) {
|
||||
callback = deps;
|
||||
deps = [];
|
||||
deps = null;
|
||||
}
|
||||
|
||||
//If no name, and callback is a function, then figure out if it a
|
||||
//CommonJS thing with dependencies.
|
||||
if (!deps.length && isFunction(callback)) {
|
||||
if (!deps && isFunction(callback)) {
|
||||
deps = [];
|
||||
//Remove comments from the callback string,
|
||||
//look for require calls, and pull them into the dependencies,
|
||||
//but only if there are function args.
|
||||
@@ -1976,14 +2075,18 @@ var requirejs, require, define;
|
||||
//where the module name is not known until the script onload event
|
||||
//occurs. If no context, use the global queue, and get it processed
|
||||
//in the onscript load callback.
|
||||
(context ? context.defQueue : globalDefQueue).push([name, deps, callback]);
|
||||
if (context) {
|
||||
context.defQueue.push([name, deps, callback]);
|
||||
context.defQueueMap[name] = true;
|
||||
} else {
|
||||
globalDefQueue.push([name, deps, callback]);
|
||||
}
|
||||
};
|
||||
|
||||
define.amd = {
|
||||
jQuery: true
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Executes the text. Normally just uses eval, but can be modified
|
||||
* to use a better, environment-specific call. Only used for transpiling
|
||||
Vendored
-2
File diff suppressed because one or more lines are too long
+124
-82
@@ -1,17 +1,39 @@
|
||||
/*!
|
||||
* Reqwest! A general purpose XHR connection manager
|
||||
* license MIT (c) Dustin Diaz 2015
|
||||
* https://github.com/ded/reqwest
|
||||
*/
|
||||
|
||||
!function (name, context, definition) {
|
||||
if (typeof module != 'undefined' && module.exports) module.exports = definition()
|
||||
else if (typeof define == 'function' && define.amd) define(definition)
|
||||
else context[name] = definition()
|
||||
}('reqwest', this, function () {
|
||||
|
||||
var win = window
|
||||
, doc = document
|
||||
, twoHundo = /^20\d$/
|
||||
, byTag = 'getElementsByTagName'
|
||||
var context = this
|
||||
|
||||
if ('window' in context) {
|
||||
var doc = document
|
||||
, byTag = 'getElementsByTagName'
|
||||
, head = doc[byTag]('head')[0]
|
||||
} else {
|
||||
var XHR2
|
||||
try {
|
||||
// prevent browserify including xhr2
|
||||
var xhr2 = 'xhr2'
|
||||
XHR2 = require(xhr2)
|
||||
} catch (ex) {
|
||||
throw new Error('Peer dependency `xhr2` required! Please npm install xhr2')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var httpsRe = /^http/
|
||||
, protocolRe = /(^\w+):\/\//
|
||||
, twoHundo = /^(20\d|1223)$/ //http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request
|
||||
, readyState = 'readyState'
|
||||
, contentType = 'Content-Type'
|
||||
, requestedWith = 'X-Requested-With'
|
||||
, head = doc[byTag]('head')[0]
|
||||
, uniqid = 0
|
||||
, callbackPrefix = 'reqwest_' + (+new Date())
|
||||
, lastValue // data stored by the most recent JSONP callback
|
||||
@@ -26,31 +48,33 @@
|
||||
}
|
||||
|
||||
, defaultHeaders = {
|
||||
contentType: 'application/x-www-form-urlencoded'
|
||||
, requestedWith: xmlHttpRequest
|
||||
, accept: {
|
||||
'contentType': 'application/x-www-form-urlencoded'
|
||||
, 'requestedWith': xmlHttpRequest
|
||||
, 'accept': {
|
||||
'*': 'text/javascript, text/html, application/xml, text/xml, */*'
|
||||
, xml: 'application/xml, text/xml'
|
||||
, html: 'text/html'
|
||||
, text: 'text/plain'
|
||||
, json: 'application/json, text/javascript'
|
||||
, js: 'application/javascript, text/javascript'
|
||||
, 'xml': 'application/xml, text/xml'
|
||||
, 'html': 'text/html'
|
||||
, 'text': 'text/plain'
|
||||
, 'json': 'application/json, text/javascript'
|
||||
, 'js': 'application/javascript, text/javascript'
|
||||
}
|
||||
}
|
||||
|
||||
, xhr = function(o) {
|
||||
// is it x-domain
|
||||
if (o.crossOrigin === true) {
|
||||
var xhr = win[xmlHttpRequest] ? new XMLHttpRequest() : null
|
||||
if (o['crossOrigin'] === true) {
|
||||
var xhr = context[xmlHttpRequest] ? new XMLHttpRequest() : null
|
||||
if (xhr && 'withCredentials' in xhr) {
|
||||
return xhr
|
||||
} else if (win[xDomainRequest]) {
|
||||
} else if (context[xDomainRequest]) {
|
||||
return new XDomainRequest()
|
||||
} else {
|
||||
throw new Error('Browser does not support cross-origin requests')
|
||||
}
|
||||
} else if (win[xmlHttpRequest]) {
|
||||
} else if (context[xmlHttpRequest]) {
|
||||
return new XMLHttpRequest()
|
||||
} else if (XHR2) {
|
||||
return new XHR2()
|
||||
} else {
|
||||
return new ActiveXObject('Microsoft.XMLHTTP')
|
||||
}
|
||||
@@ -61,15 +85,21 @@
|
||||
}
|
||||
}
|
||||
|
||||
function succeed(r) {
|
||||
var protocol = protocolRe.exec(r.url)
|
||||
protocol = (protocol && protocol[1]) || context.location.protocol
|
||||
return httpsRe.test(protocol) ? twoHundo.test(r.request.status) : !!r.request.response
|
||||
}
|
||||
|
||||
function handleReadyState(r, success, error) {
|
||||
return function () {
|
||||
// use _aborted to mitigate against IE err c00c023f
|
||||
// (can't read props on aborted request objects)
|
||||
if (r._aborted) return error(r.request)
|
||||
if (r._timedOut) return error(r.request, 'Request is aborted: timeout')
|
||||
if (r.request && r.request[readyState] == 4) {
|
||||
r.request.onreadystatechange = noop
|
||||
if (twoHundo.test(r.request.status))
|
||||
success(r.request)
|
||||
if (succeed(r)) success(r.request)
|
||||
else
|
||||
error(r.request)
|
||||
}
|
||||
@@ -77,23 +107,24 @@
|
||||
}
|
||||
|
||||
function setHeaders(http, o) {
|
||||
var headers = o.headers || {}
|
||||
var headers = o['headers'] || {}
|
||||
, h
|
||||
|
||||
headers.Accept = headers.Accept
|
||||
|| defaultHeaders.accept[o.type]
|
||||
|| defaultHeaders.accept['*']
|
||||
headers['Accept'] = headers['Accept']
|
||||
|| defaultHeaders['accept'][o['type']]
|
||||
|| defaultHeaders['accept']['*']
|
||||
|
||||
var isAFormData = typeof FormData === 'function' && (o['data'] instanceof FormData);
|
||||
// breaks cross-origin requests with legacy browsers
|
||||
if (!o.crossOrigin && !headers[requestedWith]) headers[requestedWith] = defaultHeaders.requestedWith
|
||||
if (!headers[contentType]) headers[contentType] = o.contentType || defaultHeaders.contentType
|
||||
if (!o['crossOrigin'] && !headers[requestedWith]) headers[requestedWith] = defaultHeaders['requestedWith']
|
||||
if (!headers[contentType] && !isAFormData) headers[contentType] = o['contentType'] || defaultHeaders['contentType']
|
||||
for (h in headers)
|
||||
headers.hasOwnProperty(h) && 'setRequestHeader' in http && http.setRequestHeader(h, headers[h])
|
||||
}
|
||||
|
||||
function setCredentials(http, o) {
|
||||
if (typeof o.withCredentials !== 'undefined' && typeof http.withCredentials !== 'undefined') {
|
||||
http.withCredentials = !!o.withCredentials
|
||||
if (typeof o['withCredentials'] !== 'undefined' && typeof http.withCredentials !== 'undefined') {
|
||||
http.withCredentials = !!o['withCredentials']
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,9 +138,8 @@
|
||||
|
||||
function handleJsonp(o, fn, err, url) {
|
||||
var reqId = uniqid++
|
||||
, cbkey = o.jsonpCallback || 'callback' // the 'callback' key
|
||||
, cbval = o.jsonpCallbackName || reqwest.getcallbackPrefix(reqId)
|
||||
// , cbval = o.jsonpCallbackName || ('reqwest_' + reqId) // the 'callback' value
|
||||
, cbkey = o['jsonpCallback'] || 'callback' // the 'callback' key
|
||||
, cbval = o['jsonpCallbackName'] || reqwest.getcallbackPrefix(reqId)
|
||||
, cbreg = new RegExp('((^|\\?|&)' + cbkey + ')=([^&]+)')
|
||||
, match = url.match(cbreg)
|
||||
, script = doc.createElement('script')
|
||||
@@ -126,7 +156,7 @@
|
||||
url = urlappend(url, cbkey + '=' + cbval) // no callback details, add 'em
|
||||
}
|
||||
|
||||
win[cbval] = generalCallback
|
||||
context[cbval] = generalCallback
|
||||
|
||||
script.type = 'text/javascript'
|
||||
script.src = url
|
||||
@@ -135,9 +165,6 @@
|
||||
// need this for IE due to out-of-order onreadystatechange(), binding script
|
||||
// execution to an event listener gives us control over when the script
|
||||
// is executed. See http://jaubourg.net/2010/07/loading-script-as-onclick-handler-of.html
|
||||
//
|
||||
// if this hack is used in IE10 jsonp callback are never called
|
||||
script.event = 'onclick'
|
||||
script.htmlFor = script.id = '_reqwest_' + reqId
|
||||
}
|
||||
|
||||
@@ -171,29 +198,32 @@
|
||||
|
||||
function getRequest(fn, err) {
|
||||
var o = this.o
|
||||
, method = (o.method || 'GET').toUpperCase()
|
||||
, url = typeof o === 'string' ? o : o.url
|
||||
// convert non-string objects to query-string form unless o.processData is false
|
||||
, data = (o.processData !== false && o.data && typeof o.data !== 'string')
|
||||
? reqwest.toQueryString(o.data)
|
||||
: (o.data || null)
|
||||
, method = (o['method'] || 'GET').toUpperCase()
|
||||
, url = typeof o === 'string' ? o : o['url']
|
||||
// convert non-string objects to query-string form unless o['processData'] is false
|
||||
, data = (o['processData'] !== false && o['data'] && typeof o['data'] !== 'string')
|
||||
? reqwest.toQueryString(o['data'])
|
||||
: (o['data'] || null)
|
||||
, http
|
||||
, sendWait = false
|
||||
|
||||
// if we're working on a GET request and we have data then we should append
|
||||
// query string to end of URL and not post data
|
||||
if ((o.type == 'jsonp' || method == 'GET') && data) {
|
||||
if ((o['type'] == 'jsonp' || method == 'GET') && data) {
|
||||
url = urlappend(url, data)
|
||||
data = null
|
||||
}
|
||||
|
||||
if (o.type == 'jsonp') return handleJsonp(o, fn, err, url)
|
||||
if (o['type'] == 'jsonp') return handleJsonp(o, fn, err, url)
|
||||
|
||||
http = xhr(o)
|
||||
http.open(method, url, o.async === false ? false : true)
|
||||
// get the xhr from the factory if passed
|
||||
// if the factory returns null, fall-back to ours
|
||||
http = (o.xhr && o.xhr(o)) || xhr(o)
|
||||
|
||||
http.open(method, url, o['async'] === false ? false : true)
|
||||
setHeaders(http, o)
|
||||
setCredentials(http, o)
|
||||
if (win[xDomainRequest] && http instanceof win[xDomainRequest]) {
|
||||
if (context[xDomainRequest] && http instanceof context[xDomainRequest]) {
|
||||
http.onload = fn
|
||||
http.onerror = err
|
||||
// NOTE: see
|
||||
@@ -203,7 +233,7 @@
|
||||
} else {
|
||||
http.onreadystatechange = handleReadyState(this, fn, err)
|
||||
}
|
||||
o.before && o.before(http)
|
||||
o['before'] && o['before'](http)
|
||||
if (sendWait) {
|
||||
setTimeout(function () {
|
||||
http.send(data)
|
||||
@@ -221,14 +251,18 @@
|
||||
init.apply(this, arguments)
|
||||
}
|
||||
|
||||
function setType(url) {
|
||||
var m = url.match(/\.(json|jsonp|html|xml)(\?|$)/)
|
||||
return m ? m[1] : 'js'
|
||||
function setType(header) {
|
||||
// json, javascript, text/plain, text/html, xml
|
||||
if (header === null) return undefined; //In case of no content-type.
|
||||
if (header.match('json')) return 'json'
|
||||
if (header.match('javascript')) return 'js'
|
||||
if (header.match('text')) return 'html'
|
||||
if (header.match('xml')) return 'xml'
|
||||
}
|
||||
|
||||
function init(o, fn) {
|
||||
|
||||
this.url = typeof o == 'string' ? o : o.url
|
||||
this.url = typeof o == 'string' ? o : o['url']
|
||||
this.timeout = null
|
||||
|
||||
// whether request has been fulfilled for purpose
|
||||
@@ -245,36 +279,35 @@
|
||||
this._responseArgs = {}
|
||||
|
||||
var self = this
|
||||
, type = o.type || setType(this.url)
|
||||
|
||||
fn = fn || function () {}
|
||||
|
||||
if (o.timeout) {
|
||||
if (o['timeout']) {
|
||||
this.timeout = setTimeout(function () {
|
||||
self.abort()
|
||||
}, o.timeout)
|
||||
timedOut()
|
||||
}, o['timeout'])
|
||||
}
|
||||
|
||||
if (o.success) {
|
||||
if (o['success']) {
|
||||
this._successHandler = function () {
|
||||
o.success.apply(o, arguments)
|
||||
o['success'].apply(o, arguments)
|
||||
}
|
||||
}
|
||||
|
||||
if (o.error) {
|
||||
if (o['error']) {
|
||||
this._errorHandlers.push(function () {
|
||||
o.error.apply(o, arguments)
|
||||
o['error'].apply(o, arguments)
|
||||
})
|
||||
}
|
||||
|
||||
if (o.complete) {
|
||||
if (o['complete']) {
|
||||
this._completeHandlers.push(function () {
|
||||
o.complete.apply(o, arguments)
|
||||
o['complete'].apply(o, arguments)
|
||||
})
|
||||
}
|
||||
|
||||
function complete (resp) {
|
||||
o.timeout && clearTimeout(self.timeout)
|
||||
o['timeout'] && clearTimeout(self.timeout)
|
||||
self.timeout = null
|
||||
while (self._completeHandlers.length > 0) {
|
||||
self._completeHandlers.shift()(resp)
|
||||
@@ -282,6 +315,7 @@
|
||||
}
|
||||
|
||||
function success (resp) {
|
||||
var type = o['type'] || resp && setType(resp.getResponseHeader('Content-Type')) // resp can be undefined in IE
|
||||
resp = (type !== 'jsonp') ? self.request : resp
|
||||
// use global data filter on response text
|
||||
var filteredResponse = globalSetupOptions.dataFilter(resp.responseText, type)
|
||||
@@ -295,7 +329,7 @@
|
||||
switch (type) {
|
||||
case 'json':
|
||||
try {
|
||||
resp = win.JSON ? win.JSON.parse(r) : eval('(' + r + ')')
|
||||
resp = context.JSON ? context.JSON.parse(r) : eval('(' + r + ')')
|
||||
} catch (err) {
|
||||
return error(resp, 'Could not parse JSON in response', err)
|
||||
}
|
||||
@@ -328,6 +362,11 @@
|
||||
complete(resp)
|
||||
}
|
||||
|
||||
function timedOut() {
|
||||
self._timedOut = true
|
||||
self.request.abort()
|
||||
}
|
||||
|
||||
function error(resp, msg, t) {
|
||||
resp = self.request
|
||||
self._responseArgs.resp = resp
|
||||
@@ -398,6 +437,9 @@
|
||||
}
|
||||
return this
|
||||
}
|
||||
, 'catch': function (fn) {
|
||||
return this.fail(fn)
|
||||
}
|
||||
}
|
||||
|
||||
function reqwest(o, fn) {
|
||||
@@ -415,8 +457,8 @@
|
||||
, optCb = function (o) {
|
||||
// IE gives value="" even where there is no value attribute
|
||||
// 'specified' ref: http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-862529273
|
||||
if (o && !o.disabled)
|
||||
cb(n, normalize(o.attributes.value && o.attributes.value.specified ? o.value : o.text))
|
||||
if (o && !o['disabled'])
|
||||
cb(n, normalize(o['attributes']['value'] && o['attributes']['value']['specified'] ? o['value'] : o['text']))
|
||||
}
|
||||
, ch, ra, val, i
|
||||
|
||||
@@ -523,12 +565,12 @@
|
||||
}
|
||||
// If an array was passed in, assume that it is an array of form elements.
|
||||
if (isArray(o)) {
|
||||
for (i = 0; o && i < o.length; i++) add(o[i].name, o[i].value)
|
||||
for (i = 0; o && i < o.length; i++) add(o[i]['name'], o[i]['value'])
|
||||
} else {
|
||||
// If traditional, encode the "old" way (the way 1.3.2 or older
|
||||
// did it), otherwise encode params recursively.
|
||||
for (prefix in o) {
|
||||
buildParams(prefix, o[prefix], traditional, add)
|
||||
if (o.hasOwnProperty(prefix)) buildParams(prefix, o[prefix], traditional, add)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -569,22 +611,22 @@
|
||||
|
||||
// jQuery and Zepto compatibility, differences can be remapped here so you can call
|
||||
// .ajax.compat(options, callback)
|
||||
reqwest.compat = function (o, fn) {
|
||||
if (o) {
|
||||
o.type && (o.method = o.type) && delete o.type
|
||||
o.dataType && (o.type = o.dataType)
|
||||
o.jsonpCallback && (o.jsonpCallbackName = o.jsonpCallback) && delete o.jsonpCallback
|
||||
o.jsonp && (o.jsonpCallback = o.jsonp)
|
||||
}
|
||||
return new Reqwest(o, fn)
|
||||
}
|
||||
// reqwest.compat = function (o, fn) {
|
||||
// if (o) {
|
||||
// o['type'] && (o['method'] = o['type']) && delete o['type']
|
||||
// o['dataType'] && (o['type'] = o['dataType'])
|
||||
// o['jsonpCallback'] && (o['jsonpCallbackName'] = o['jsonpCallback']) && delete o['jsonpCallback']
|
||||
// o['jsonp'] && (o['jsonpCallback'] = o['jsonp'])
|
||||
// }
|
||||
// return new Reqwest(o, fn)
|
||||
// }
|
||||
|
||||
reqwest.ajaxSetup = function (options) {
|
||||
options = options || {}
|
||||
for (var k in options) {
|
||||
globalSetupOptions[k] = options[k]
|
||||
}
|
||||
}
|
||||
// reqwest.ajaxSetup = function (options) {
|
||||
// options = options || {}
|
||||
// for (var k in options) {
|
||||
// globalSetupOptions[k] = options[k]
|
||||
// }
|
||||
// }
|
||||
|
||||
return reqwest
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,445 +0,0 @@
|
||||
/*jslint onevar:true, undef:true, newcap:true, regexp:true, bitwise:true, maxerr:50, indent:4, white:false, nomen:false, plusplus:false */
|
||||
/*global define:false, require:false, exports:false, module:false, signals:false */
|
||||
|
||||
/** @license
|
||||
* JS Signals <http://millermedeiros.github.com/js-signals/>
|
||||
* Released under the MIT license
|
||||
* Author: Miller Medeiros
|
||||
* Version: 1.0.0 - Build: 268 (2012/11/29 05:48 PM)
|
||||
*/
|
||||
|
||||
(function(global){
|
||||
|
||||
// SignalBinding -------------------------------------------------
|
||||
//================================================================
|
||||
|
||||
/**
|
||||
* Object that represents a binding between a Signal and a listener function.
|
||||
* <br />- <strong>This is an internal constructor and shouldn't be called by regular users.</strong>
|
||||
* <br />- inspired by Joa Ebert AS3 SignalBinding and Robert Penner's Slot classes.
|
||||
* @author Miller Medeiros
|
||||
* @constructor
|
||||
* @internal
|
||||
* @name SignalBinding
|
||||
* @param {Signal} signal Reference to Signal object that listener is currently bound to.
|
||||
* @param {Function} listener Handler function bound to the signal.
|
||||
* @param {boolean} isOnce If binding should be executed just once.
|
||||
* @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
|
||||
* @param {Number} [priority] The priority level of the event listener. (default = 0).
|
||||
*/
|
||||
function SignalBinding(signal, listener, isOnce, listenerContext, priority) {
|
||||
|
||||
/**
|
||||
* Handler function bound to the signal.
|
||||
* @type Function
|
||||
* @private
|
||||
*/
|
||||
this._listener = listener;
|
||||
|
||||
/**
|
||||
* If binding should be executed just once.
|
||||
* @type boolean
|
||||
* @private
|
||||
*/
|
||||
this._isOnce = isOnce;
|
||||
|
||||
/**
|
||||
* Context on which listener will be executed (object that should represent the `this` variable inside listener function).
|
||||
* @memberOf SignalBinding.prototype
|
||||
* @name context
|
||||
* @type Object|undefined|null
|
||||
*/
|
||||
this.context = listenerContext;
|
||||
|
||||
/**
|
||||
* Reference to Signal object that listener is currently bound to.
|
||||
* @type Signal
|
||||
* @private
|
||||
*/
|
||||
this._signal = signal;
|
||||
|
||||
/**
|
||||
* Listener priority
|
||||
* @type Number
|
||||
* @private
|
||||
*/
|
||||
this._priority = priority || 0;
|
||||
}
|
||||
|
||||
SignalBinding.prototype = {
|
||||
|
||||
/**
|
||||
* If binding is active and should be executed.
|
||||
* @type boolean
|
||||
*/
|
||||
active : true,
|
||||
|
||||
/**
|
||||
* Default parameters passed to listener during `Signal.dispatch` and `SignalBinding.execute`. (curried parameters)
|
||||
* @type Array|null
|
||||
*/
|
||||
params : null,
|
||||
|
||||
/**
|
||||
* Call listener passing arbitrary parameters.
|
||||
* <p>If binding was added using `Signal.addOnce()` it will be automatically removed from signal dispatch queue, this method is used internally for the signal dispatch.</p>
|
||||
* @param {Array} [paramsArr] Array of parameters that should be passed to the listener
|
||||
* @return {*} Value returned by the listener.
|
||||
*/
|
||||
execute : function (paramsArr) {
|
||||
var handlerReturn, params;
|
||||
if (this.active && !!this._listener) {
|
||||
params = this.params? this.params.concat(paramsArr) : paramsArr;
|
||||
handlerReturn = this._listener.apply(this.context, params);
|
||||
if (this._isOnce) {
|
||||
this.detach();
|
||||
}
|
||||
}
|
||||
return handlerReturn;
|
||||
},
|
||||
|
||||
/**
|
||||
* Detach binding from signal.
|
||||
* - alias to: mySignal.remove(myBinding.getListener());
|
||||
* @return {Function|null} Handler function bound to the signal or `null` if binding was previously detached.
|
||||
*/
|
||||
detach : function () {
|
||||
return this.isBound()? this._signal.remove(this._listener, this.context) : null;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {Boolean} `true` if binding is still bound to the signal and have a listener.
|
||||
*/
|
||||
isBound : function () {
|
||||
return (!!this._signal && !!this._listener);
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {boolean} If SignalBinding will only be executed once.
|
||||
*/
|
||||
isOnce : function () {
|
||||
return this._isOnce;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {Function} Handler function bound to the signal.
|
||||
*/
|
||||
getListener : function () {
|
||||
return this._listener;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {Signal} Signal that listener is currently bound to.
|
||||
*/
|
||||
getSignal : function () {
|
||||
return this._signal;
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete instance properties
|
||||
* @private
|
||||
*/
|
||||
_destroy : function () {
|
||||
delete this._signal;
|
||||
delete this._listener;
|
||||
delete this.context;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {string} String representation of the object.
|
||||
*/
|
||||
toString : function () {
|
||||
return '[SignalBinding isOnce:' + this._isOnce +', isBound:'+ this.isBound() +', active:' + this.active + ']';
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/*global SignalBinding:false*/
|
||||
|
||||
// Signal --------------------------------------------------------
|
||||
//================================================================
|
||||
|
||||
function validateListener(listener, fnName) {
|
||||
if (typeof listener !== 'function') {
|
||||
throw new Error( 'listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom event broadcaster
|
||||
* <br />- inspired by Robert Penner's AS3 Signals.
|
||||
* @name Signal
|
||||
* @author Miller Medeiros
|
||||
* @constructor
|
||||
*/
|
||||
function Signal() {
|
||||
/**
|
||||
* @type Array.<SignalBinding>
|
||||
* @private
|
||||
*/
|
||||
this._bindings = [];
|
||||
this._prevParams = null;
|
||||
|
||||
// enforce dispatch to aways work on same context (#47)
|
||||
var self = this;
|
||||
this.dispatch = function(){
|
||||
Signal.prototype.dispatch.apply(self, arguments);
|
||||
};
|
||||
}
|
||||
|
||||
Signal.prototype = {
|
||||
|
||||
/**
|
||||
* Signals Version Number
|
||||
* @type String
|
||||
* @const
|
||||
*/
|
||||
VERSION : '1.0.0',
|
||||
|
||||
/**
|
||||
* If Signal should keep record of previously dispatched parameters and
|
||||
* automatically execute listener during `add()`/`addOnce()` if Signal was
|
||||
* already dispatched before.
|
||||
* @type boolean
|
||||
*/
|
||||
memorize : false,
|
||||
|
||||
/**
|
||||
* @type boolean
|
||||
* @private
|
||||
*/
|
||||
_shouldPropagate : true,
|
||||
|
||||
/**
|
||||
* If Signal is active and should broadcast events.
|
||||
* <p><strong>IMPORTANT:</strong> Setting this property during a dispatch will only affect the next dispatch, if you want to stop the propagation of a signal use `halt()` instead.</p>
|
||||
* @type boolean
|
||||
*/
|
||||
active : true,
|
||||
|
||||
/**
|
||||
* @param {Function} listener
|
||||
* @param {boolean} isOnce
|
||||
* @param {Object} [listenerContext]
|
||||
* @param {Number} [priority]
|
||||
* @return {SignalBinding}
|
||||
* @private
|
||||
*/
|
||||
_registerListener : function (listener, isOnce, listenerContext, priority) {
|
||||
|
||||
var prevIndex = this._indexOfListener(listener, listenerContext),
|
||||
binding;
|
||||
|
||||
if (prevIndex !== -1) {
|
||||
binding = this._bindings[prevIndex];
|
||||
if (binding.isOnce() !== isOnce) {
|
||||
throw new Error('You cannot add'+ (isOnce? '' : 'Once') +'() then add'+ (!isOnce? '' : 'Once') +'() the same listener without removing the relationship first.');
|
||||
}
|
||||
} else {
|
||||
binding = new SignalBinding(this, listener, isOnce, listenerContext, priority);
|
||||
this._addBinding(binding);
|
||||
}
|
||||
|
||||
if(this.memorize && this._prevParams){
|
||||
binding.execute(this._prevParams);
|
||||
}
|
||||
|
||||
return binding;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {SignalBinding} binding
|
||||
* @private
|
||||
*/
|
||||
_addBinding : function (binding) {
|
||||
//simplified insertion sort
|
||||
var n = this._bindings.length;
|
||||
do { --n; } while (this._bindings[n] && binding._priority <= this._bindings[n]._priority);
|
||||
this._bindings.splice(n + 1, 0, binding);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Function} listener
|
||||
* @return {number}
|
||||
* @private
|
||||
*/
|
||||
_indexOfListener : function (listener, context) {
|
||||
var n = this._bindings.length,
|
||||
cur;
|
||||
while (n--) {
|
||||
cur = this._bindings[n];
|
||||
if (cur._listener === listener && cur.context === context) {
|
||||
return n;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if listener was attached to Signal.
|
||||
* @param {Function} listener
|
||||
* @param {Object} [context]
|
||||
* @return {boolean} if Signal has the specified listener.
|
||||
*/
|
||||
has : function (listener, context) {
|
||||
return this._indexOfListener(listener, context) !== -1;
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a listener to the signal.
|
||||
* @param {Function} listener Signal handler function.
|
||||
* @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
|
||||
* @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0)
|
||||
* @return {SignalBinding} An Object representing the binding between the Signal and listener.
|
||||
*/
|
||||
add : function (listener, listenerContext, priority) {
|
||||
validateListener(listener, 'add');
|
||||
return this._registerListener(listener, false, listenerContext, priority);
|
||||
},
|
||||
|
||||
/**
|
||||
* Add listener to the signal that should be removed after first execution (will be executed only once).
|
||||
* @param {Function} listener Signal handler function.
|
||||
* @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
|
||||
* @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0)
|
||||
* @return {SignalBinding} An Object representing the binding between the Signal and listener.
|
||||
*/
|
||||
addOnce : function (listener, listenerContext, priority) {
|
||||
validateListener(listener, 'addOnce');
|
||||
return this._registerListener(listener, true, listenerContext, priority);
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove a single listener from the dispatch queue.
|
||||
* @param {Function} listener Handler function that should be removed.
|
||||
* @param {Object} [context] Execution context (since you can add the same handler multiple times if executing in a different context).
|
||||
* @return {Function} Listener handler function.
|
||||
*/
|
||||
remove : function (listener, context) {
|
||||
validateListener(listener, 'remove');
|
||||
|
||||
var i = this._indexOfListener(listener, context);
|
||||
if (i !== -1) {
|
||||
this._bindings[i]._destroy(); //no reason to a SignalBinding exist if it isn't attached to a signal
|
||||
this._bindings.splice(i, 1);
|
||||
}
|
||||
return listener;
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove all listeners from the Signal.
|
||||
*/
|
||||
removeAll : function () {
|
||||
var n = this._bindings.length;
|
||||
while (n--) {
|
||||
this._bindings[n]._destroy();
|
||||
}
|
||||
this._bindings.length = 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {number} Number of listeners attached to the Signal.
|
||||
*/
|
||||
getNumListeners : function () {
|
||||
return this._bindings.length;
|
||||
},
|
||||
|
||||
/**
|
||||
* Stop propagation of the event, blocking the dispatch to next listeners on the queue.
|
||||
* <p><strong>IMPORTANT:</strong> should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.</p>
|
||||
* @see Signal.prototype.disable
|
||||
*/
|
||||
halt : function () {
|
||||
this._shouldPropagate = false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Dispatch/Broadcast Signal to all listeners added to the queue.
|
||||
* @param {...*} [params] Parameters that should be passed to each handler.
|
||||
*/
|
||||
dispatch : function (params) {
|
||||
if (! this.active) {
|
||||
return;
|
||||
}
|
||||
|
||||
var paramsArr = Array.prototype.slice.call(arguments),
|
||||
n = this._bindings.length,
|
||||
bindings;
|
||||
|
||||
if (this.memorize) {
|
||||
this._prevParams = paramsArr;
|
||||
}
|
||||
|
||||
if (! n) {
|
||||
//should come after memorize
|
||||
return;
|
||||
}
|
||||
|
||||
bindings = this._bindings.slice(); //clone array in case add/remove items during dispatch
|
||||
this._shouldPropagate = true; //in case `halt` was called before dispatch or during the previous dispatch.
|
||||
|
||||
//execute all callbacks until end of the list or until a callback returns `false` or stops propagation
|
||||
//reverse loop since listeners with higher priority will be added at the end of the list
|
||||
do { n--; } while (bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false);
|
||||
},
|
||||
|
||||
/**
|
||||
* Forget memorized arguments.
|
||||
* @see Signal.memorize
|
||||
*/
|
||||
forget : function(){
|
||||
this._prevParams = null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove all bindings from signal and destroy any reference to external objects (destroy Signal object).
|
||||
* <p><strong>IMPORTANT:</strong> calling any method on the signal instance after calling dispose will throw errors.</p>
|
||||
*/
|
||||
dispose : function () {
|
||||
this.removeAll();
|
||||
delete this._bindings;
|
||||
delete this._prevParams;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {string} String representation of the object.
|
||||
*/
|
||||
toString : function () {
|
||||
return '[Signal active:'+ this.active +' numListeners:'+ this.getNumListeners() +']';
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
// Namespace -----------------------------------------------------
|
||||
//================================================================
|
||||
|
||||
/**
|
||||
* Signals namespace
|
||||
* @namespace
|
||||
* @name signals
|
||||
*/
|
||||
var signals = Signal;
|
||||
|
||||
/**
|
||||
* Custom event broadcaster
|
||||
* @see Signal
|
||||
*/
|
||||
// alias for backwards compatibility (see #gh-44)
|
||||
signals.Signal = Signal;
|
||||
|
||||
|
||||
|
||||
//exports to multiple environments
|
||||
if(typeof define === 'function' && define.amd){ //AMD
|
||||
define(function () { return signals; });
|
||||
} else if (typeof module !== 'undefined' && module.exports){ //node
|
||||
module.exports = signals;
|
||||
} else { //browser
|
||||
//use string because of Google closure compiler ADVANCED_MODE
|
||||
/*jslint sub:true */
|
||||
global['signals'] = signals;
|
||||
}
|
||||
|
||||
}(this));
|
||||
Reference in New Issue
Block a user