forked from dciccale/ki.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathki.js
85 lines (77 loc) · 1.85 KB
/
ki.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
/*
* ki.js - jQuery-like super-tiny JavaScript library
* Copyright (c) 2012 Denis Ciccale (@tdecs)
* Released under MIT license
*/
!function (b, c, d, f, h, e) {
/*
* $ main method
* a = css selector, dom object, or function
* returns instance
*/
this.$ = function (a) {
return new $[d].i(a)
};
// ki prototype
e = {
// default length
length: 0,
/*
* init method (internal use)
* a = selector, dom element or function
* (t = internal use)
*/
i: function (a) {
c.push.apply(this, a && a.nodeType ? [a] : "" + a === a ? c.slice.call(b.querySelectorAll(a)) : /^f/.test(typeof a) ? $(b).r(a) : null)
},
/*
* ready method
* Smallest DOMReady code, ever
* http://www.dustindiaz.com/smallest-domready-ever
* a = function to call when dom is ready
* return this
*/
r: function (a) {
/c/.test(b.readyState) ? a() : $(b).on("DOMContentLoaded", a);
return this
},
/*
* on method
* a = string event type i.e 'click'
* g = function
* return this
*/
on: function (a, g) {
return this.each(function (b) {
b["add" + f](a, g)
})
},
/*
* off method
* a = string event type i.e 'click'
* b = function
* return this
*/
off: function (a, b) {
return this.each(function (c) {
c["remove" + f](a, b)
})
},
/*
* each method
* use native forEach to iterate collection
* a = the function to call each loop
* (b = internal use)
* return this
*/
each: function (a, b) {
c.forEach.call(b = this, a);
return b
},
// for some reason is needed to get an array-like
// representation instead of an object
splice: c.splice
};
// set prototypes
$[d] = e.i[d] = e
}(document, [], "prototype", "EventListener");