-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.foo.js
87 lines (69 loc) · 2.06 KB
/
jquery.foo.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*!
Copyright (c) 2012 Astrata Software
Written by José Carlos Nieto <[email protected]>
Licensed under the MIT License
Redistributions of files must retain the above copyright notice.
*/
(
function($) {
$.foo = function() {
$.foo.pull.apply($.foo, arguments);
};
/* $.foo.pull(script1, script2, ...) */
$.foo.pull = function() {
var names = [];
for (var i = 0; i < arguments.length; i++) {
names.push(arguments[i]);
};
var url = $.foo.root + '?load='+names.join(',');
$.holdReady(true);
$.ajaxSetup({cache: true});
$.getScript(url, function() {
$.holdReady(false);
});
$.ajaxSetup({cache: false});
};
/* $.foo.styles(style1, style2, ...) */
$.foo.styles = function() {
for (var i = 0; i < arguments.length; i++) {
$('head').prepend($('<link />', {
'type': 'text/css',
'rel': 'stylesheet',
'href': $.foo.root + arguments[i]
}));
};
}
/* directly taken from http://docs.jquery.com/Plugins/Authoring */
$.foo.plugin = function(name, methods) {
$.fn[name] = function(method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method '+method+' does not exist on jQuery.'+name);
};
};
};
/* startup */
$.foo.start = function() {
var scripts = $('head script');
for (var i = 0; i < scripts.length; i++) {
var src = $(scripts[i]).attr('src');
var match = src.match(/^(.*)jquery\.foo\.js$/);
if (match) {
if (!$.foo.root) {
$.foo.root = match[1] || '/';
};
$.foo.parent = scripts[i];
};
};
};
/* alias for $.foo.pull */
if (typeof $.pull == 'undefined') {
$.pull = $.foo.pull;
};
/* starting up */
$.foo.start();
}
)(jQuery);