[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 /* 2 * jQuery AjaxQ - AJAX request queueing for jQuery 3 * 4 * Version: 0.0.1 5 * Date: July 22, 2008 6 * 7 * Copyright (c) 2008 Oleg Podolsky ([email protected]) 8 * Licensed under the MIT (MIT-LICENSE.txt) license. 9 * 10 * http://plugins.jquery.com/project/ajaxq 11 * http://code.google.com/p/jquery-ajaxq/ 12 */ 13 14 jQuery.ajaxq = function (queue, options) 15 { 16 // Initialize storage for request queues if it's not initialized yet 17 if (typeof document.ajaxq == "undefined") document.ajaxq = {q:{}, r:null}; 18 19 // Initialize current queue if it's not initialized yet 20 if (typeof document.ajaxq.q[queue] == "undefined") document.ajaxq.q[queue] = []; 21 22 if (typeof options != "undefined") // Request settings are given, enqueue the new request 23 { 24 // Copy the original options, because options.complete is going to be overridden 25 26 var optionsCopy = {}; 27 for (var o in options) optionsCopy[o] = options[o]; 28 options = optionsCopy; 29 30 // Override the original callback 31 32 var originalCompleteCallback = options.complete; 33 34 options.complete = function (request, status) 35 { 36 // Dequeue the current request 37 document.ajaxq.q[queue].shift (); 38 document.ajaxq.r = null; 39 40 // Run the original callback 41 if (originalCompleteCallback) originalCompleteCallback (request, status); 42 43 // Run the next request from the queue 44 if (document.ajaxq.q[queue].length > 0) document.ajaxq.r = jQuery.ajax (document.ajaxq.q[queue][0]); 45 }; 46 47 // Enqueue the request 48 document.ajaxq.q[queue].push (options); 49 50 // Also, if no request is currently running, start it 51 if (document.ajaxq.q[queue].length == 1) document.ajaxq.r = jQuery.ajax (options); 52 } 53 else // No request settings are given, stop current request and clear the queue 54 { 55 if (document.ajaxq.r) 56 { 57 document.ajaxq.r.abort (); 58 document.ajaxq.r = null; 59 } 60 61 document.ajaxq.q[queue] = []; 62 } 63 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |