Skip to content

Instantly share code, notes, and snippets.

$.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') {
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 )
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 );
};
}
}
$.ajax( '/foo' ).then(function( success ) {
throw new Error( "NOPE" );
}).then( null, function( fail ) {
// fail.message === "NOPE";
})
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");
}
$.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 )
}
$.ajaxPrefilter(function( options ) {
if ( options.dataTypes.indexOf( "crossdomainrouter" ) === 0 ) {
options.dataTypes.shift();
}
});
function extractOriginalEvent( handler ) {
return function( event ) {
if ( event.originalEvent ) {
event = event.originalEvent;
}
return handler.apply( this, [ event ].concat( Array.prototype.slice.call( arguments, 1 ) ) );
};
}
if ( !Object.create ) {
Object.create = function( parentProto ) {
function F() {}
F.prototype = parentProto;
return new F();
}
}
function Animal() {}
(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);