-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.cohitre.js
41 lines (37 loc) · 1004 Bytes
/
jquery.cohitre.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
(function ($) {
/*
* Calls the callback on a jQuery object when
* the page has loaded.
* $.initialize(selector, callback, args...);
*/
$.initialize = function (selector) {
var args = $.makeArray(arguments).slice(1);
$(function () {
$.fn.doOnce.apply($(selector), args);
});
};
/*
* An easy way to create jQuery plugins without polluting
* the jQuery namespace.
* $(selector).doOnce(someFunction, arg1, arg2, ....);
*/
$.fn.doOnce = function (callback) {
var args = $.makeArray(arguments).slice(1);
this.length && callback.apply(this, args);
return this;
};
/*
* Empties the collection if the condition is not true.
* An alternative to conditionals.
* $(selector).iff(a === 2)....;
* $(selector).iff(function () {
* return this.is(".happy");
* }).....;
*/
$.fn.iff = function (condition) {
if ($.isFunction(condition)) {
condition = condition.apply(this, $.makeArray(arguments).slice(1));
}
return this.pushStack(condition ? this : []);
};
})(jQuery);