Created
September 10, 2013 16:18
-
-
Save spiralx/6511813 to your computer and use it in GitHub Desktop.
Creates jQuery instance methods for returning data from each item selected e.g. $el.attrs(), $.texts()
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
(function($) { | |
$.fn.batch = function(method, args) { | |
var func = $.fn[method], results = []; | |
this.each(function() { | |
results.push(func.apply(this, args)); | |
}); | |
return results; | |
}; | |
var funcs = "attr css=styles prop html text val offset width height".split(" "); | |
$.each(funcs, function(i, v) { | |
var names = v.indexOf("=") == -1 ? [v, v + "s"] : v.split("="), | |
cur_method = names[0], batch_method = names[1]; | |
if ($.fn[cur_method] && !$.fn[batch_method]) { | |
$.fn[batch_method] = function() { | |
return this.batch(cur_method, arguments); | |
} | |
} | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment