forked from dciccale/ki.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathki.ie8.js
More file actions
124 lines (112 loc) · 2.92 KB
/
ki.ie8.js
File metadata and controls
124 lines (112 loc) · 2.92 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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* ki.js - jQuery-like API super-tiny JavaScript library
* This version gives support for IE8+ and modern browsers
* Copyright (c) 2012 Denis Ciccale (@tdecs)
* Released under MIT license
*/
!function (b, c, d, f, h, i) {
/*
* (internal use)
* ie8 workaround to convert NodeList to an array
* a = NodeList
* b = placeholder for each node
* c = index
* d = empty array
* returns array of dom nodes
*/
h = function (a, b, c, d) {
c = -1
d = []
while (b = a[++c]) d[c] = b
return d
}
/*
* (internal use)
* Cross-browser super-type event handler https://gist.github.com/dciccale/5521816
* action = 'on' or 'off'
* type = event type (i.e. 'click')
* element = the element to add the event
* callback = function to execute when event is triggered
* method = placeholder for the native method to call (internal use)
*/
i = function (action, type, element, callback, method) {
method = {on: 'addEventListener', off: 'removeEventListener'}[action]
try {
element[method](type, callback, false)
} catch (e) {
method = {on: 'attachEvent', off: 'detachEvent'}[action]
element[method](action + type, function () { callback.apply(element, arguments) })
}
}
/*
* $ main method
* a = css selector, dom object, or function
* returns instance
*/
this.$ = function (a) {
return new $[d].i(a)
}
// ki prototype
f = {
// default length
length: 0,
/*
* init method (internal use)
* a = selector, dom element or function
*/
i: function (a) {
c.push.apply(this, a && a.nodeType ? [a] : "" + a === a ? h(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'
* b = function
* return this
*/
on: function (a, b) {
return this.each(function (c) {
i('on', a, this, b)
})
},
/*
* off method
* a = string event type i.e 'click'
* b = function
* return this
*/
off: function (a, b) {
return this.each(function (c) {
i('off', a, this, 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, d) {
for (b=this,c=0,d=b.length;c<d;++c) {
a.call(b[c],b[c],c,b)
}
return b
},
// for some reason is needed to get an array-like
// representation instead of an object
splice: c.splice
}
// set prototypes
$[d] = f.i[d] = f
}(document, [], 'prototype');