PageSourceSearch

https://www.jhrl.com/sites/all/libraries/ajaxq/ajaxq.js?tlse4v

js jhrl.com collected 2026-10-06 13:17:45 UTC 4,143 bytes, 146 lines download raw bytes

vendor: 4,143 bytes, lines 1-146
1// AjaxQ jQuery Plugin
2// Copyright (c) 2012 Foliotek Inc.
3// MIT License
4// https://github.com/Foliotek/ajaxq
5
6(function($) {
7
8  var queues = {};
9  var activeReqs = {};
10
11  // Register an $.ajaxq function, which follows the $.ajax interface, but allows a queue name which will force only one request per queue to fire.
12  $.ajaxq = function(qname, opts) {
13
14    if (typeof opts === "undefined") {
15      throw ("AjaxQ: queue name is not provided");
16    }
17
18    // Will return a Deferred promise object extended with success/error/callback, so that this function matches the interface of $.ajax
19    var deferred = $.Deferred(),
20      promise = deferred.promise();
21
22    promise.success = promise.done;
23    promise.error = promise.fail;
24    promise.complete = promise.always;
25
26    // Create a deep copy of the arguments, and enqueue this request.
27    var clonedOptions = $.extend(true, {}, opts);
28    enqueue(function() {
29      // Send off the ajax request now that the item has been removed from the queue
30      var jqXHR = $.ajax.apply(window, [clonedOptions]);
31
32      // Notify the returned deferred object with the correct context when the jqXHR is done or fails
33      // Note that 'always' will automatically be fired once one of these are called: http://api.jquery.com/category/deferred-object/.
34      jqXHR.done(function() {
35        deferred.resolve.apply(this, arguments);
36      });
37      jqXHR.fail(function() {
38        deferred.reject.apply(this, arguments);
39      });
40
41      jqXHR.always(dequeue); // make sure to dequeue the next request AFTER the done and fail callbacks are fired
42      return jqXHR;
43    });
44
45    return promise;
46
47
48    // If there is no queue, create an empty one and instantly process this item.
49    // Otherwise, just add this item onto it for later processing.
50    function enqueue(cb) {
51      if (!queues[qname]) {
52        queues[qname] = [];
53        var xhr = cb();
54        activeReqs[qname] = xhr;
55      }
56      else {
57        queues[qname].push(cb);
58      }
59    }
60
61    // Remove the next callback from the queue and fire it off.
62    // If the queue was empty (this was the last item), delete it from memory so the next one can be instantly processed.
63    function dequeue() {
64      if (!queues[qname]) {
65        return;
66      }
67      var nextCallback = queues[qname].shift();
68      if (nextCallback) {
69        var xhr = nextCallback();
70        activeReqs[qname] = xhr;
71      }
72      else {
73        delete queues[qname];
74        delete activeReqs[qname];
75      }
76    }
77  };
78
79  // Register a $.postq and $.getq method to provide shortcuts for $.get and $.post
80  // Copied from jQuery source to make sure the functions share the same defaults as $.get and $.post.
81  $.each( [ "getq", "postq" ], function( i, method ) {
82    $[ method ] = function( qname, url, data, callback, type ) {
83
84      if ( $.isFunction( data ) ) {
85        type = type || callback;
86        callback = data;
87        data = undefined;
88      }
89
90      return $.ajaxq(qname, {
91        type: method === "postq" ? "post" : "get",
92        url: url,
93        data: data,
94        success: callback,
95        dataType: type
96      });
97    };
98  });
99
100  var isQueueRunning = function(qname) {
101    return queues.hasOwnProperty(qname);
102  };
103
104  var isAnyQueueRunning = function() {
105    for (var i in queues) {
106      if (isQueueRunning(i)) return true;
107    }
108    return false;
109  };
110
111  $.ajaxq.isRunning = function(qname) {
112    if (qname) return isQueueRunning(qname);
113    else return isAnyQueueRunning();
114  };
115
116  $.ajaxq.getActiveRequest = function(qname) {
117    if (!qname) throw ("AjaxQ: queue name is required");
118
119    return activeReqs[qname];
120  };
121
122  $.ajaxq.abort = function(qname) {
123    if (!qname) throw ("AjaxQ: queue name is required");
124
125    var current = $.ajaxq.getActiveRequest(qname);
126    delete queues[qname];
127    delete activeReqs[qname];
128    if (current) current.abort();
129  };
130
131  $.ajaxq.clear = function(qname) {
132    if (!qname) {
133      for (var i in queues) {
134        if (queues.hasOwnProperty(i)) {
135          queues[i] = [];
136        }
137      }
138    }
139    else {
140      if (queues[qname]) {
141        queues[qname] = [];
142      }
143    }
144  };
145
146})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.