Created
April 5, 2011 20:34
-
-
Save ehynds/904483 to your computer and use it in GitHub Desktop.
This file contains 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
// inspired by http://www.dustindiaz.com/async-method-queues/ | |
// (don't actually use this gist; there are better ways) | |
(function($) { | |
$.fetch = function(url) { | |
if (!(this instanceof $.fetch)) { | |
return new $.fetch(url); | |
} | |
var q = this.q = $({}), | |
self = this; | |
$.get(url, function(resp){ | |
self.collection = resp; | |
q.dequeue('async'); | |
}); | |
return this; | |
}; | |
for (var method in $.fn) { | |
(function(m) { | |
$.fetch.prototype[m] = function() { | |
var self = this, | |
args = arguments; | |
self.q.queue('async', function(next) { | |
self.collection = jQuery.fn[m].apply(self.collection, args); | |
next(); | |
}); | |
return self; | |
}; | |
})(method) | |
} | |
})(jQuery); | |
// then... | |
var queue = $.fetch('/some/html/').appendTo('#foo'); // etc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment