|
1 | 1 | (function() { |
2 | 2 | var MutationObserver, Util, WeakMap, getComputedStyle, getComputedStyleRX, |
3 | | - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, |
4 | | - __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; |
| 3 | + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, |
| 4 | + indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; |
5 | 5 |
|
6 | 6 | Util = (function() { |
7 | 7 | function Util() {} |
|
21 | 21 | return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(agent); |
22 | 22 | }; |
23 | 23 |
|
| 24 | + Util.prototype.createEvent = function(event, bubble, cancel, detail) { |
| 25 | + var customEvent; |
| 26 | + if (bubble == null) { |
| 27 | + bubble = false; |
| 28 | + } |
| 29 | + if (cancel == null) { |
| 30 | + cancel = false; |
| 31 | + } |
| 32 | + if (detail == null) { |
| 33 | + detail = null; |
| 34 | + } |
| 35 | + if (document.createEvent != null) { |
| 36 | + customEvent = document.createEvent('CustomEvent'); |
| 37 | + customEvent.initCustomEvent(event, bubble, cancel, detail); |
| 38 | + } else if (document.createEventObject != null) { |
| 39 | + customEvent = document.createEventObject(); |
| 40 | + customEvent.eventType = event; |
| 41 | + } else { |
| 42 | + customEvent.eventName = event; |
| 43 | + } |
| 44 | + return customEvent; |
| 45 | + }; |
| 46 | + |
| 47 | + Util.prototype.emitEvent = function(elem, event) { |
| 48 | + if (elem.dispatchEvent != null) { |
| 49 | + return elem.dispatchEvent(event); |
| 50 | + } else if (event in (elem != null)) { |
| 51 | + return elem[event](); |
| 52 | + } else if (("on" + event) in (elem != null)) { |
| 53 | + return elem["on" + event](); |
| 54 | + } |
| 55 | + }; |
| 56 | + |
24 | 57 | Util.prototype.addEvent = function(elem, event, fn) { |
25 | 58 | if (elem.addEventListener != null) { |
26 | 59 | return elem.addEventListener(event, fn, false); |
|
60 | 93 | } |
61 | 94 |
|
62 | 95 | WeakMap.prototype.get = function(key) { |
63 | | - var i, item, _i, _len, _ref; |
64 | | - _ref = this.keys; |
65 | | - for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { |
66 | | - item = _ref[i]; |
| 96 | + var i, item, j, len, ref; |
| 97 | + ref = this.keys; |
| 98 | + for (i = j = 0, len = ref.length; j < len; i = ++j) { |
| 99 | + item = ref[i]; |
67 | 100 | if (item === key) { |
68 | 101 | return this.values[i]; |
69 | 102 | } |
70 | 103 | } |
71 | 104 | }; |
72 | 105 |
|
73 | 106 | WeakMap.prototype.set = function(key, value) { |
74 | | - var i, item, _i, _len, _ref; |
75 | | - _ref = this.keys; |
76 | | - for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { |
77 | | - item = _ref[i]; |
| 107 | + var i, item, j, len, ref; |
| 108 | + ref = this.keys; |
| 109 | + for (i = j = 0, len = ref.length; j < len; i = ++j) { |
| 110 | + item = ref[i]; |
78 | 111 | if (item === key) { |
79 | 112 | this.values[i] = value; |
80 | 113 | return; |
|
108 | 141 |
|
109 | 142 | getComputedStyle = this.getComputedStyle || function(el, pseudo) { |
110 | 143 | this.getPropertyValue = function(prop) { |
111 | | - var _ref; |
| 144 | + var ref; |
112 | 145 | if (prop === 'float') { |
113 | 146 | prop = 'styleFloat'; |
114 | 147 | } |
|
117 | 150 | return _char.toUpperCase(); |
118 | 151 | }); |
119 | 152 | } |
120 | | - return ((_ref = el.currentStyle) != null ? _ref[prop] : void 0) || null; |
| 153 | + return ((ref = el.currentStyle) != null ? ref[prop] : void 0) || null; |
121 | 154 | }; |
122 | 155 | return this; |
123 | 156 | }; |
|
138 | 171 | if (options == null) { |
139 | 172 | options = {}; |
140 | 173 | } |
141 | | - this.scrollCallback = __bind(this.scrollCallback, this); |
142 | | - this.scrollHandler = __bind(this.scrollHandler, this); |
143 | | - this.start = __bind(this.start, this); |
| 174 | + this.scrollCallback = bind(this.scrollCallback, this); |
| 175 | + this.scrollHandler = bind(this.scrollHandler, this); |
| 176 | + this.start = bind(this.start, this); |
144 | 177 | this.scrolled = true; |
145 | 178 | this.config = this.util().extend(options, this.defaults); |
146 | 179 | this.animationNameCache = new WeakMap(); |
| 180 | + this.wowEvent = this.util().createEvent(this.config.boxClass); |
147 | 181 | } |
148 | 182 |
|
149 | 183 | WOW.prototype.init = function() { |
150 | | - var _ref; |
| 184 | + var ref; |
151 | 185 | this.element = window.document.documentElement; |
152 | | - if ((_ref = document.readyState) === "interactive" || _ref === "complete") { |
| 186 | + if ((ref = document.readyState) === "interactive" || ref === "complete") { |
153 | 187 | this.start(); |
154 | 188 | } else { |
155 | 189 | this.util().addEvent(document, 'DOMContentLoaded', this.start); |
|
158 | 192 | }; |
159 | 193 |
|
160 | 194 | WOW.prototype.start = function() { |
161 | | - var box, _i, _len, _ref; |
| 195 | + var box, j, len, ref; |
162 | 196 | this.stopped = false; |
163 | 197 | this.boxes = (function() { |
164 | | - var _i, _len, _ref, _results; |
165 | | - _ref = this.element.querySelectorAll("." + this.config.boxClass); |
166 | | - _results = []; |
167 | | - for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
168 | | - box = _ref[_i]; |
169 | | - _results.push(box); |
| 198 | + var j, len, ref, results; |
| 199 | + ref = this.element.querySelectorAll("." + this.config.boxClass); |
| 200 | + results = []; |
| 201 | + for (j = 0, len = ref.length; j < len; j++) { |
| 202 | + box = ref[j]; |
| 203 | + results.push(box); |
170 | 204 | } |
171 | | - return _results; |
| 205 | + return results; |
172 | 206 | }).call(this); |
173 | 207 | this.all = (function() { |
174 | | - var _i, _len, _ref, _results; |
175 | | - _ref = this.boxes; |
176 | | - _results = []; |
177 | | - for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
178 | | - box = _ref[_i]; |
179 | | - _results.push(box); |
| 208 | + var j, len, ref, results; |
| 209 | + ref = this.boxes; |
| 210 | + results = []; |
| 211 | + for (j = 0, len = ref.length; j < len; j++) { |
| 212 | + box = ref[j]; |
| 213 | + results.push(box); |
180 | 214 | } |
181 | | - return _results; |
| 215 | + return results; |
182 | 216 | }).call(this); |
183 | 217 | if (this.boxes.length) { |
184 | 218 | if (this.disabled()) { |
185 | 219 | this.resetStyle(); |
186 | 220 | } else { |
187 | | - _ref = this.boxes; |
188 | | - for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
189 | | - box = _ref[_i]; |
| 221 | + ref = this.boxes; |
| 222 | + for (j = 0, len = ref.length; j < len; j++) { |
| 223 | + box = ref[j]; |
190 | 224 | this.applyStyle(box, true); |
191 | 225 | } |
192 | 226 | } |
|
199 | 233 | if (this.config.live) { |
200 | 234 | return new MutationObserver((function(_this) { |
201 | 235 | return function(records) { |
202 | | - var node, record, _j, _len1, _results; |
203 | | - _results = []; |
204 | | - for (_j = 0, _len1 = records.length; _j < _len1; _j++) { |
205 | | - record = records[_j]; |
206 | | - _results.push((function() { |
207 | | - var _k, _len2, _ref1, _results1; |
208 | | - _ref1 = record.addedNodes || []; |
209 | | - _results1 = []; |
210 | | - for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) { |
211 | | - node = _ref1[_k]; |
212 | | - _results1.push(this.doSync(node)); |
| 236 | + var k, len1, node, record, results; |
| 237 | + results = []; |
| 238 | + for (k = 0, len1 = records.length; k < len1; k++) { |
| 239 | + record = records[k]; |
| 240 | + results.push((function() { |
| 241 | + var l, len2, ref1, results1; |
| 242 | + ref1 = record.addedNodes || []; |
| 243 | + results1 = []; |
| 244 | + for (l = 0, len2 = ref1.length; l < len2; l++) { |
| 245 | + node = ref1[l]; |
| 246 | + results1.push(this.doSync(node)); |
213 | 247 | } |
214 | | - return _results1; |
| 248 | + return results1; |
215 | 249 | }).call(_this)); |
216 | 250 | } |
217 | | - return _results; |
| 251 | + return results; |
218 | 252 | }; |
219 | 253 | })(this)).observe(document.body, { |
220 | 254 | childList: true, |
|
239 | 273 | }; |
240 | 274 |
|
241 | 275 | WOW.prototype.doSync = function(element) { |
242 | | - var box, _i, _len, _ref, _results; |
| 276 | + var box, j, len, ref, results; |
243 | 277 | if (element == null) { |
244 | 278 | element = this.element; |
245 | 279 | } |
246 | 280 | if (element.nodeType !== 1) { |
247 | 281 | return; |
248 | 282 | } |
249 | 283 | element = element.parentNode || element; |
250 | | - _ref = element.querySelectorAll("." + this.config.boxClass); |
251 | | - _results = []; |
252 | | - for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
253 | | - box = _ref[_i]; |
254 | | - if (__indexOf.call(this.all, box) < 0) { |
| 284 | + ref = element.querySelectorAll("." + this.config.boxClass); |
| 285 | + results = []; |
| 286 | + for (j = 0, len = ref.length; j < len; j++) { |
| 287 | + box = ref[j]; |
| 288 | + if (indexOf.call(this.all, box) < 0) { |
255 | 289 | this.boxes.push(box); |
256 | 290 | this.all.push(box); |
257 | 291 | if (this.stopped || this.disabled()) { |
258 | 292 | this.resetStyle(); |
259 | 293 | } else { |
260 | 294 | this.applyStyle(box, true); |
261 | 295 | } |
262 | | - _results.push(this.scrolled = true); |
| 296 | + results.push(this.scrolled = true); |
263 | 297 | } else { |
264 | | - _results.push(void 0); |
| 298 | + results.push(void 0); |
265 | 299 | } |
266 | 300 | } |
267 | | - return _results; |
| 301 | + return results; |
268 | 302 | }; |
269 | 303 |
|
270 | 304 | WOW.prototype.show = function(box) { |
271 | 305 | this.applyStyle(box); |
272 | | - box.className = "" + box.className + " " + this.config.animateClass; |
| 306 | + box.className = box.className + " " + this.config.animateClass; |
273 | 307 | if (this.config.callback != null) { |
274 | | - return this.config.callback(box); |
| 308 | + this.config.callback(box); |
275 | 309 | } |
| 310 | + this.util().emitEvent(box, this.wowEvent); |
| 311 | + this.util().addEvent(box, 'animationend', this.resetAnimation); |
| 312 | + this.util().addEvent(box, 'oanimationend', this.resetAnimation); |
| 313 | + this.util().addEvent(box, 'webkitAnimationEnd', this.resetAnimation); |
| 314 | + this.util().addEvent(box, 'MSAnimationEnd', this.resetAnimation); |
| 315 | + return box; |
276 | 316 | }; |
277 | 317 |
|
278 | 318 | WOW.prototype.applyStyle = function(box, hidden) { |
|
300 | 340 | })(); |
301 | 341 |
|
302 | 342 | WOW.prototype.resetStyle = function() { |
303 | | - var box, _i, _len, _ref, _results; |
304 | | - _ref = this.boxes; |
305 | | - _results = []; |
306 | | - for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
307 | | - box = _ref[_i]; |
308 | | - _results.push(box.style.visibility = 'visible'); |
| 343 | + var box, j, len, ref, results; |
| 344 | + ref = this.boxes; |
| 345 | + results = []; |
| 346 | + for (j = 0, len = ref.length; j < len; j++) { |
| 347 | + box = ref[j]; |
| 348 | + results.push(box.style.visibility = 'visible'); |
| 349 | + } |
| 350 | + return results; |
| 351 | + }; |
| 352 | + |
| 353 | + WOW.prototype.resetAnimation = function(event) { |
| 354 | + var target; |
| 355 | + if (event.type.toLowerCase().indexOf('animationend') >= 0) { |
| 356 | + target = event.target || event.srcElement; |
| 357 | + return target.className = target.className.replace(config.animateClass, '').trim(); |
309 | 358 | } |
310 | | - return _results; |
311 | 359 | }; |
312 | 360 |
|
313 | 361 | WOW.prototype.customStyle = function(box, hidden, duration, delay, iteration) { |
|
339 | 387 | WOW.prototype.vendors = ["moz", "webkit"]; |
340 | 388 |
|
341 | 389 | WOW.prototype.vendorSet = function(elem, properties) { |
342 | | - var name, value, vendor, _results; |
343 | | - _results = []; |
| 390 | + var name, results, value, vendor; |
| 391 | + results = []; |
344 | 392 | for (name in properties) { |
345 | 393 | value = properties[name]; |
346 | 394 | elem["" + name] = value; |
347 | | - _results.push((function() { |
348 | | - var _i, _len, _ref, _results1; |
349 | | - _ref = this.vendors; |
350 | | - _results1 = []; |
351 | | - for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
352 | | - vendor = _ref[_i]; |
353 | | - _results1.push(elem["" + vendor + (name.charAt(0).toUpperCase()) + (name.substr(1))] = value); |
| 395 | + results.push((function() { |
| 396 | + var j, len, ref, results1; |
| 397 | + ref = this.vendors; |
| 398 | + results1 = []; |
| 399 | + for (j = 0, len = ref.length; j < len; j++) { |
| 400 | + vendor = ref[j]; |
| 401 | + results1.push(elem["" + vendor + (name.charAt(0).toUpperCase()) + (name.substr(1))] = value); |
354 | 402 | } |
355 | | - return _results1; |
| 403 | + return results1; |
356 | 404 | }).call(this)); |
357 | 405 | } |
358 | | - return _results; |
| 406 | + return results; |
359 | 407 | }; |
360 | 408 |
|
361 | 409 | WOW.prototype.vendorCSS = function(elem, property) { |
362 | | - var result, style, vendor, _i, _len, _ref; |
| 410 | + var j, len, ref, result, style, vendor; |
363 | 411 | style = getComputedStyle(elem); |
364 | 412 | result = style.getPropertyCSSValue(property); |
365 | | - _ref = this.vendors; |
366 | | - for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
367 | | - vendor = _ref[_i]; |
| 413 | + ref = this.vendors; |
| 414 | + for (j = 0, len = ref.length; j < len; j++) { |
| 415 | + vendor = ref[j]; |
368 | 416 | result = result || style.getPropertyCSSValue("-" + vendor + "-" + property); |
369 | 417 | } |
370 | 418 | return result; |
|
401 | 449 | if (this.scrolled) { |
402 | 450 | this.scrolled = false; |
403 | 451 | this.boxes = (function() { |
404 | | - var _i, _len, _ref, _results; |
405 | | - _ref = this.boxes; |
406 | | - _results = []; |
407 | | - for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
408 | | - box = _ref[_i]; |
| 452 | + var j, len, ref, results; |
| 453 | + ref = this.boxes; |
| 454 | + results = []; |
| 455 | + for (j = 0, len = ref.length; j < len; j++) { |
| 456 | + box = ref[j]; |
409 | 457 | if (!(box)) { |
410 | 458 | continue; |
411 | 459 | } |
412 | 460 | if (this.isVisible(box)) { |
413 | 461 | this.show(box); |
414 | 462 | continue; |
415 | 463 | } |
416 | | - _results.push(box); |
| 464 | + results.push(box); |
417 | 465 | } |
418 | | - return _results; |
| 466 | + return results; |
419 | 467 | }).call(this); |
420 | 468 | if (!(this.boxes.length || this.config.live)) { |
421 | 469 | return this.stop(); |
|
0 commit comments