Created
December 5, 2011 06:18
-
-
Save sj26/1432538 to your computer and use it in GitHub Desktop.
Modified TrafficCop for jQuery 1.5+: http://freshbrewedcode.com/jimcowart/2011/11/25/traffic-cop/
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
/* | |
TrafficCop | |
Author: Jim Cowart | |
License: Dual licensed MIT (http://www.opensource.org/licenses/mit-license) & GPL (http://www.opensource.org/licenses/gpl-license) | |
Version 0.1.0 | |
*/ | |
(function($, undefined) { | |
var inProgress = {}; | |
$.trafficCop = function(url, options) { | |
var reqOptions = url, key; | |
if(arguments.length === 2) { | |
reqOptions = $.extend(true, options, { url: url }); | |
} | |
key = JSON.stringify(reqOptions); | |
if (key in inProgress) { | |
for (i in {success: 1, error: 1, complete: 1}) { | |
inProgress[key][i](reqOptions[i]); | |
} | |
} else { | |
inProgress[key] = $.ajax(reqOptions).always(function () { delete inProgress[key]; }) | |
} | |
return inProgress[key]; | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment