|
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 (elem[event] != null) { |
| 51 | + return elem[event](); |
| 52 | + } else if (elem['on' + event] != 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 | + return this.util().emitEvent(box, this.wowEvent); |
276 | 311 | };
|
277 | 312 |
|
278 | 313 | WOW.prototype.applyStyle = function(box, hidden) {
|
|
300 | 335 | })();
|
301 | 336 |
|
302 | 337 | 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'); |
309 |
| - } |
310 |
| - return _results; |
| 338 | + var box, j, len, ref, results; |
| 339 | + ref = this.boxes; |
| 340 | + results = []; |
| 341 | + for (j = 0, len = ref.length; j < len; j++) { |
| 342 | + box = ref[j]; |
| 343 | + results.push(box.style.visibility = 'visible'); |
| 344 | + } |
| 345 | + return results; |
311 | 346 | };
|
312 | 347 |
|
313 | 348 | WOW.prototype.customStyle = function(box, hidden, duration, delay, iteration) {
|
|
339 | 374 | WOW.prototype.vendors = ["moz", "webkit"];
|
340 | 375 |
|
341 | 376 | WOW.prototype.vendorSet = function(elem, properties) {
|
342 |
| - var name, value, vendor, _results; |
343 |
| - _results = []; |
| 377 | + var name, results, value, vendor; |
| 378 | + results = []; |
344 | 379 | for (name in properties) {
|
345 | 380 | value = properties[name];
|
346 | 381 | 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); |
| 382 | + results.push((function() { |
| 383 | + var j, len, ref, results1; |
| 384 | + ref = this.vendors; |
| 385 | + results1 = []; |
| 386 | + for (j = 0, len = ref.length; j < len; j++) { |
| 387 | + vendor = ref[j]; |
| 388 | + results1.push(elem["" + vendor + (name.charAt(0).toUpperCase()) + (name.substr(1))] = value); |
354 | 389 | }
|
355 |
| - return _results1; |
| 390 | + return results1; |
356 | 391 | }).call(this));
|
357 | 392 | }
|
358 |
| - return _results; |
| 393 | + return results; |
359 | 394 | };
|
360 | 395 |
|
361 | 396 | WOW.prototype.vendorCSS = function(elem, property) {
|
362 |
| - var result, style, vendor, _i, _len, _ref; |
| 397 | + var j, len, ref, result, style, vendor; |
363 | 398 | style = getComputedStyle(elem);
|
364 | 399 | result = style.getPropertyCSSValue(property);
|
365 |
| - _ref = this.vendors; |
366 |
| - for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
367 |
| - vendor = _ref[_i]; |
| 400 | + ref = this.vendors; |
| 401 | + for (j = 0, len = ref.length; j < len; j++) { |
| 402 | + vendor = ref[j]; |
368 | 403 | result = result || style.getPropertyCSSValue("-" + vendor + "-" + property);
|
369 | 404 | }
|
370 | 405 | return result;
|
|
401 | 436 | if (this.scrolled) {
|
402 | 437 | this.scrolled = false;
|
403 | 438 | 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]; |
| 439 | + var j, len, ref, results; |
| 440 | + ref = this.boxes; |
| 441 | + results = []; |
| 442 | + for (j = 0, len = ref.length; j < len; j++) { |
| 443 | + box = ref[j]; |
409 | 444 | if (!(box)) {
|
410 | 445 | continue;
|
411 | 446 | }
|
412 | 447 | if (this.isVisible(box)) {
|
413 | 448 | this.show(box);
|
414 | 449 | continue;
|
415 | 450 | }
|
416 |
| - _results.push(box); |
| 451 | + results.push(box); |
417 | 452 | }
|
418 |
| - return _results; |
| 453 | + return results; |
419 | 454 | }).call(this);
|
420 | 455 | if (!(this.boxes.length || this.config.live)) {
|
421 | 456 | return this.stop();
|
|
0 commit comments