This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.ajaxSettings.xhr = (function() { | |
var xhrFactory = $.ajaxSettings.xhr(); | |
return function() { | |
var xhr = xhrFactory(); | |
var send = xhr.send; | |
xhr.send = function() { | |
var onload = xhr.onload; | |
xhr.onload = function() { | |
if ((xhr.responseType || 'text' ) !== 'text') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function promiseReduce( entries, reducer, initialValue ) { | |
return new Promise(function( resolve, reject ) { | |
(function next( i, memo ) { | |
Promise.resolve( reducer( memo, entries[ i ], i, entries ) ).then(function( returnValue ) { | |
if ( i === entries.length - 1 ) { | |
resolve( returnValue ); | |
} else { | |
next( i + 1, returnValue ); | |
} | |
}).catch( reject ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function decorateExpressionBindings( binding, scope, attrs ) { | |
var delegate = $parse( attrs[ binding ] ).$$watchDelegate, | |
actualBinding = scope[ binding ]; | |
if ( parsed.$$watchDelegate ) { | |
actualBinding.$$watchDelegate = function( scope, listener, objectEquality, parsedExpression ) { | |
return delegate( scope.$parent, listener, objectEquality, parsedExpression ); | |
}; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.ajax( '/foo' ).then(function( success ) { | |
throw new Error( "NOPE" ); | |
}).then( null, function( fail ) { | |
// fail.message === "NOPE"; | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function unfinishedOrderLookup( orderId ) { | |
return request.server.methods.callApi("/orders/" + orderId ).then(function(res ) { | |
return res.order; | |
}); | |
} | |
function lookupOrdersByUid( uid ) { | |
return request.server.methods.callApi("/users/" + uid + "/orders?status=0"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.ajaxPrefilter( "+", function( options, originalOptions, jqXHR ) { | |
jqXHR.then( null, function( jqXHR, textStatus, errorThrown ) { | |
var args = arguments; | |
return $.Deferred( dfr ) { | |
if ( jqXHR.status === 422 ) { | |
dfr.resolveWith( this, [ $.parseJSON( jqXHR.responseText ), textStatus, errorThrown ]); | |
} else { | |
dfr.resolveWith( this, args ) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.ajaxPrefilter(function( options ) { | |
if ( options.dataTypes.indexOf( "crossdomainrouter" ) === 0 ) { | |
options.dataTypes.shift(); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function extractOriginalEvent( handler ) { | |
return function( event ) { | |
if ( event.originalEvent ) { | |
event = event.originalEvent; | |
} | |
return handler.apply( this, [ event ].concat( Array.prototype.slice.call( arguments, 1 ) ) ); | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ( !Object.create ) { | |
Object.create = function( parentProto ) { | |
function F() {} | |
F.prototype = parentProto; | |
return new F(); | |
} | |
} | |
function Animal() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
// Override RequireJS's global error handler | |
requirejs.onError = (function(errback) { | |
return function require$customOnError(err) { | |
console.log('RequireJS error!\nType: ' + err.requireType + '\nModules: ' + JSON.stringify(err.requireModules)); | |
// Delegate the rest of the errors | |
if (typeof errback === 'function') { | |
errback(err); |