Skip to content

Instantly share code, notes, and snippets.

@lotsofcode
Forked from gnarf/jQuery.ajaxQueue.min.js
Created October 11, 2012 16:04

Revisions

  1. @gnarf gnarf revised this gist Aug 15, 2012. 2 changed files with 3 additions and 3 deletions.
    2 changes: 1 addition & 1 deletion jQuery.ajaxQueue.min.js
    Original file line number Diff line number Diff line change
    @@ -6,4 +6,4 @@
    *
    * Requires jQuery 1.5+
    */
    (function(a){var b=a({});a.ajaxQueue=function(c){function g(b){d=a.ajax(c).then(b,b).done(e.resolve).fail(e.reject)}var d,e=a.Deferred(),f=e.promise();b.queue(g),f.abort=function(h){if(d)return d.abort(h);var i=b.queue(),j=a.inArray(g,i);j>-1&&i.splice(j,1),e.rejectWith(c.context||c,[f,h,""]);return f};return f}})(jQuery)
    (function(a){var b=a({});a.ajaxQueue=function(c){function g(b){d=a.ajax(c).done(e.resolve).fail(e.reject).then(b,b)}var d,e=a.Deferred(),f=e.promise();b.queue(g),f.abort=function(h){if(d)return d.abort(h);var i=b.queue(),j=a.inArray(g,i);j>-1&&i.splice(j,1),e.rejectWith(c.context||c,[f,h,""]);return f};return f}})(jQuery)
    4 changes: 2 additions & 2 deletions jquery.ajaxQueue.js
    Original file line number Diff line number Diff line change
    @@ -43,9 +43,9 @@ $.ajaxQueue = function( ajaxOpts ) {
    // run the actual query
    function doRequest( next ) {
    jqXHR = $.ajax( ajaxOpts )
    .then( next, next )
    .done( dfd.resolve )
    .fail( dfd.reject );
    .fail( dfd.reject )
    .then( next, next );
    }

    return promise;
  2. @gnarf gnarf revised this gist Jun 22, 2011. 1 changed file with 44 additions and 44 deletions.
    88 changes: 44 additions & 44 deletions jquery.ajaxQueue.js
    Original file line number Diff line number Diff line change
    @@ -1,54 +1,54 @@
    /*
    * jQuery.ajaxQueue - A queue for ajax requests
    *
    * (c) 2011 Corey Frang
    * Dual licensed under the MIT and GPL licenses.
    *
    * Requires jQuery 1.5+
    */
    * jQuery.ajaxQueue - A queue for ajax requests
    *
    * (c) 2011 Corey Frang
    * Dual licensed under the MIT and GPL licenses.
    *
    * Requires jQuery 1.5+
    */
    (function($) {

    // jQuery on an empty object, we are going to use this as our Queue
    var ajaxQueue = $({});

    $.ajaxQueue = function( ajaxOpts ) {
    var jqXHR,
    dfd = $.Deferred(),
    promise = dfd.promise();

    // queue our ajax request
    ajaxQueue.queue( doRequest );

    // add the abort method
    promise.abort = function( statusText ) {

    // proxy abort to the jqXHR if it is active
    if ( jqXHR ) {
    return jqXHR.abort( statusText );
    }

    // if there wasn't already a jqXHR we need to remove from queue
    var queue = ajaxQueue.queue(),
    index = $.inArray( doRequest, queue );

    if ( index > -1 ) {
    queue.splice( index, 1 );
    }

    // and then reject the deferred
    dfd.rejectWith( ajaxOpts.context || ajaxOpts, [ promise, statusText, "" ] );
    return promise;
    };

    // run the actual query
    function doRequest( next ) {
    jqXHR = $.ajax( ajaxOpts )
    .then( next, next )
    .done( dfd.resolve )
    .fail( dfd.reject );
    }

    return promise;
    var jqXHR,
    dfd = $.Deferred(),
    promise = dfd.promise();

    // queue our ajax request
    ajaxQueue.queue( doRequest );

    // add the abort method
    promise.abort = function( statusText ) {

    // proxy abort to the jqXHR if it is active
    if ( jqXHR ) {
    return jqXHR.abort( statusText );
    }

    // if there wasn't already a jqXHR we need to remove from queue
    var queue = ajaxQueue.queue(),
    index = $.inArray( doRequest, queue );

    if ( index > -1 ) {
    queue.splice( index, 1 );
    }

    // and then reject the deferred
    dfd.rejectWith( ajaxOpts.context || ajaxOpts, [ promise, statusText, "" ] );
    return promise;
    };

    // run the actual query
    function doRequest( next ) {
    jqXHR = $.ajax( ajaxOpts )
    .then( next, next )
    .done( dfd.resolve )
    .fail( dfd.reject );
    }

    return promise;
    };

    })(jQuery);
  3. @gnarf gnarf revised this gist Jun 21, 2011. 2 changed files with 4 additions and 4 deletions.
    4 changes: 2 additions & 2 deletions jQuery.ajaxQueue.min.js
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,6 @@
    * (c) 2011 Corey Frang
    * Dual licensed under the MIT and GPL licenses.
    *
    * Requires jQuery 1.6+
    * Requires jQuery 1.5+
    */
    (function(a){var b=a({});a.ajaxQueue=function(c){function g(b){d=a.ajax(c).always(b).done(e.resolve).fail(e.reject)}var d,e=a.Deferred(),f=e.promise();b.queue(g),f.abort=function(h){if(d)return d.abort(h);var i=b.queue(),j=a.inArray(g,i);j>-1&&i.splice(j,1),e.rejectWith(c.context||c,[f,h,""]);return f};return f}})(jQuery)
    (function(a){var b=a({});a.ajaxQueue=function(c){function g(b){d=a.ajax(c).then(b,b).done(e.resolve).fail(e.reject)}var d,e=a.Deferred(),f=e.promise();b.queue(g),f.abort=function(h){if(d)return d.abort(h);var i=b.queue(),j=a.inArray(g,i);j>-1&&i.splice(j,1),e.rejectWith(c.context||c,[f,h,""]);return f};return f}})(jQuery)
    4 changes: 2 additions & 2 deletions jquery.ajaxQueue.js
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    * (c) 2011 Corey Frang
    * Dual licensed under the MIT and GPL licenses.
    *
    * Requires jQuery 1.6+
    * Requires jQuery 1.5+
    */
    (function($) {

    @@ -43,7 +43,7 @@ $.ajaxQueue = function( ajaxOpts ) {
    // run the actual query
    function doRequest( next ) {
    jqXHR = $.ajax( ajaxOpts )
    .always( next )
    .then( next, next )
    .done( dfd.resolve )
    .fail( dfd.reject );
    }
  4. @gnarf gnarf created this gist Jun 21, 2011.
    9 changes: 9 additions & 0 deletions jQuery.ajaxQueue.min.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    /*
    * jQuery.ajaxQueue - A queue for ajax requests
    *
    * (c) 2011 Corey Frang
    * Dual licensed under the MIT and GPL licenses.
    *
    * Requires jQuery 1.6+
    */
    (function(a){var b=a({});a.ajaxQueue=function(c){function g(b){d=a.ajax(c).always(b).done(e.resolve).fail(e.reject)}var d,e=a.Deferred(),f=e.promise();b.queue(g),f.abort=function(h){if(d)return d.abort(h);var i=b.queue(),j=a.inArray(g,i);j>-1&&i.splice(j,1),e.rejectWith(c.context||c,[f,h,""]);return f};return f}})(jQuery)
    54 changes: 54 additions & 0 deletions jquery.ajaxQueue.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    /*
    * jQuery.ajaxQueue - A queue for ajax requests
    *
    * (c) 2011 Corey Frang
    * Dual licensed under the MIT and GPL licenses.
    *
    * Requires jQuery 1.6+
    */
    (function($) {

    // jQuery on an empty object, we are going to use this as our Queue
    var ajaxQueue = $({});

    $.ajaxQueue = function( ajaxOpts ) {
    var jqXHR,
    dfd = $.Deferred(),
    promise = dfd.promise();

    // queue our ajax request
    ajaxQueue.queue( doRequest );

    // add the abort method
    promise.abort = function( statusText ) {

    // proxy abort to the jqXHR if it is active
    if ( jqXHR ) {
    return jqXHR.abort( statusText );
    }

    // if there wasn't already a jqXHR we need to remove from queue
    var queue = ajaxQueue.queue(),
    index = $.inArray( doRequest, queue );

    if ( index > -1 ) {
    queue.splice( index, 1 );
    }

    // and then reject the deferred
    dfd.rejectWith( ajaxOpts.context || ajaxOpts, [ promise, statusText, "" ] );
    return promise;
    };

    // run the actual query
    function doRequest( next ) {
    jqXHR = $.ajax( ajaxOpts )
    .always( next )
    .done( dfd.resolve )
    .fail( dfd.reject );
    }

    return promise;
    };

    })(jQuery);