-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjquery.pluginloader.js
More file actions
45 lines (34 loc) · 1.09 KB
/
jquery.pluginloader.js
File metadata and controls
45 lines (34 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*!
* jQuery Plugin Loader
* Copyright(c) 2012 Eirikur Nilsson <eirikur@nilsson.is>
* MIT Licensed
*/
(function($) {
$.fn.loadPlugins = function() {
// Pre-initialize jQuery object to iterate quicker
var $this = $([1]);
this.find('*[data-plugin]').add(this).each(function() {
$this.context = $this[0] = this;
var key, value, args
, plugins = $this.data('plugin') || ""
, isMap = plugins.indexOf(':') > -1;
if (!plugins.length) { return; }
if (!isMap) {
plugins += ": [null]";
}
plugins = "({" + plugins + "})";
plugins = eval(plugins);
for (key in plugins) {
if (plugins.hasOwnProperty(key) && key in $.fn) {
value = plugins[key];
args = $.isArray(value) ? value : [value];
$.fn[key].apply($this, args);
}
}
});
return this;
};
$(function() {
$(document.body).loadPlugins();
});
})(jQuery);