You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

507 lines
18 KiB

2 years ago
  1. (function () {
  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; };
  5. Util = (function () {
  6. function Util() { }
  7. Util.prototype.extend = function (custom, defaults) {
  8. var key, value;
  9. for (key in defaults) {
  10. value = defaults[key];
  11. if (custom[key] == null) {
  12. custom[key] = value;
  13. }
  14. }
  15. return custom;
  16. };
  17. Util.prototype.isMobile = function (agent) {
  18. return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(agent);
  19. };
  20. Util.prototype.createEvent = function (event, bubble, cancel, detail) {
  21. var customEvent;
  22. if (bubble == null) {
  23. bubble = false;
  24. }
  25. if (cancel == null) {
  26. cancel = false;
  27. }
  28. if (detail == null) {
  29. detail = null;
  30. }
  31. if (document.createEvent != null) {
  32. customEvent = document.createEvent('CustomEvent');
  33. customEvent.initCustomEvent(event, bubble, cancel, detail);
  34. } else if (document.createEventObject != null) {
  35. customEvent = document.createEventObject();
  36. customEvent.eventType = event;
  37. } else {
  38. customEvent.eventName = event;
  39. }
  40. return customEvent;
  41. };
  42. Util.prototype.emitEvent = function (elem, event) {
  43. if (elem.dispatchEvent != null) {
  44. return elem.dispatchEvent(event);
  45. } else if (event in (elem != null)) {
  46. return elem[event]();
  47. } else if (("on" + event) in (elem != null)) {
  48. return elem["on" + event]();
  49. }
  50. };
  51. Util.prototype.addEvent = function (elem, event, fn) {
  52. if (elem.addEventListener != null) {
  53. return elem.addEventListener(event, fn, false);
  54. } else if (elem.attachEvent != null) {
  55. return elem.attachEvent("on" + event, fn);
  56. } else {
  57. return elem[event] = fn;
  58. }
  59. };
  60. Util.prototype.removeEvent = function (elem, event, fn) {
  61. if (elem.removeEventListener != null) {
  62. return elem.removeEventListener(event, fn, false);
  63. } else if (elem.detachEvent != null) {
  64. return elem.detachEvent("on" + event, fn);
  65. } else {
  66. return delete elem[event];
  67. }
  68. };
  69. Util.prototype.innerHeight = function () {
  70. if ('innerHeight' in window) {
  71. return window.innerHeight;
  72. } else {
  73. return document.documentElement.clientHeight;
  74. }
  75. };
  76. return Util;
  77. })();
  78. WeakMap = this.WeakMap || this.MozWeakMap || (WeakMap = (function () {
  79. function WeakMap() {
  80. this.keys = [];
  81. this.values = [];
  82. }
  83. WeakMap.prototype.get = function (key) {
  84. var i, item, j, len, ref;
  85. ref = this.keys;
  86. for (i = j = 0, len = ref.length; j < len; i = ++j) {
  87. item = ref[i];
  88. if (item === key) {
  89. return this.values[i];
  90. }
  91. }
  92. };
  93. WeakMap.prototype.set = function (key, value) {
  94. var i, item, j, len, ref;
  95. ref = this.keys;
  96. for (i = j = 0, len = ref.length; j < len; i = ++j) {
  97. item = ref[i];
  98. if (item === key) {
  99. this.values[i] = value;
  100. return;
  101. }
  102. }
  103. this.keys.push(key);
  104. return this.values.push(value);
  105. };
  106. return WeakMap;
  107. })());
  108. MutationObserver = this.MutationObserver || this.WebkitMutationObserver || this.MozMutationObserver || (MutationObserver = (function () {
  109. function MutationObserver() {
  110. if (typeof console !== "undefined" && console !== null) {
  111. console.warn('MutationObserver is not supported by your browser.');
  112. }
  113. if (typeof console !== "undefined" && console !== null) {
  114. console.warn('WOW.js cannot detect dom mutations, please call .sync() after loading new content.');
  115. }
  116. }
  117. MutationObserver.notSupported = true;
  118. MutationObserver.prototype.observe = function () { };
  119. return MutationObserver;
  120. })());
  121. getComputedStyle = this.getComputedStyle || function (el, pseudo) {
  122. this.getPropertyValue = function (prop) {
  123. var ref;
  124. if (prop === 'float') {
  125. prop = 'styleFloat';
  126. }
  127. if (getComputedStyleRX.test(prop)) {
  128. prop.replace(getComputedStyleRX, function (_, _char) {
  129. return _char.toUpperCase();
  130. });
  131. }
  132. return ((ref = el.currentStyle) != null ? ref[prop] : void 0) || null;
  133. };
  134. return this;
  135. };
  136. getComputedStyleRX = /(\-([a-z]){1})/g;
  137. this.WOW = (function () {
  138. WOW.prototype.defaults = {
  139. boxClass: 'wow',
  140. animateClass: 'animated',
  141. offset: 0,
  142. mobile: true,
  143. live: true,
  144. callback: null,
  145. scrollContainer: null
  146. };
  147. function WOW(options) {
  148. if (options == null) {
  149. options = {};
  150. }
  151. this.scrollCallback = bind(this.scrollCallback, this);
  152. this.scrollHandler = bind(this.scrollHandler, this);
  153. this.resetAnimation = bind(this.resetAnimation, this);
  154. this.start = bind(this.start, this);
  155. this.scrolled = true;
  156. this.config = this.util().extend(options, this.defaults);
  157. if (options.scrollContainer != null) {
  158. this.config.scrollContainer = document.querySelector(options.scrollContainer);
  159. }
  160. this.animationNameCache = new WeakMap();
  161. this.wowEvent = this.util().createEvent(this.config.boxClass);
  162. }
  163. WOW.prototype.init = function () {
  164. var ref;
  165. this.element = window.document.documentElement;
  166. if ((ref = document.readyState) === "interactive" || ref === "complete") {
  167. this.start();
  168. } else {
  169. this.util().addEvent(document, 'DOMContentLoaded', this.start);
  170. }
  171. return this.finished = [];
  172. };
  173. WOW.prototype.start = function () {
  174. var box, j, len, ref;
  175. this.stopped = false;
  176. this.boxes = (function () {
  177. var j, len, ref, results;
  178. ref = this.element.querySelectorAll("." + this.config.boxClass);
  179. results = [];
  180. for (j = 0, len = ref.length; j < len; j++) {
  181. box = ref[j];
  182. results.push(box);
  183. }
  184. return results;
  185. }).call(this);
  186. this.all = (function () {
  187. var j, len, ref, results;
  188. ref = this.boxes;
  189. results = [];
  190. for (j = 0, len = ref.length; j < len; j++) {
  191. box = ref[j];
  192. results.push(box);
  193. }
  194. return results;
  195. }).call(this);
  196. if (this.boxes.length) {
  197. if (this.disabled()) {
  198. this.resetStyle();
  199. } else {
  200. ref = this.boxes;
  201. for (j = 0, len = ref.length; j < len; j++) {
  202. box = ref[j];
  203. this.applyStyle(box, true);
  204. }
  205. }
  206. }
  207. if (!this.disabled()) {
  208. this.util().addEvent(this.config.scrollContainer || window, 'scroll', this.scrollHandler);
  209. this.util().addEvent(window, 'resize', this.scrollHandler);
  210. this.interval = setInterval(this.scrollCallback, 50);
  211. }
  212. if (this.config.live) {
  213. return new MutationObserver((function (_this) {
  214. return function (records) {
  215. var k, len1, node, record, results;
  216. results = [];
  217. for (k = 0, len1 = records.length; k < len1; k++) {
  218. record = records[k];
  219. results.push((function () {
  220. var l, len2, ref1, results1;
  221. ref1 = record.addedNodes || [];
  222. results1 = [];
  223. for (l = 0, len2 = ref1.length; l < len2; l++) {
  224. node = ref1[l];
  225. results1.push(this.doSync(node));
  226. }
  227. return results1;
  228. }).call(_this));
  229. }
  230. return results;
  231. };
  232. })(this)).observe(document.body, {
  233. childList: true,
  234. subtree: true
  235. });
  236. }
  237. };
  238. WOW.prototype.stop = function () {
  239. this.stopped = true;
  240. this.util().removeEvent(this.config.scrollContainer || window, 'scroll', this.scrollHandler);
  241. this.util().removeEvent(window, 'resize', this.scrollHandler);
  242. if (this.interval != null) {
  243. return clearInterval(this.interval);
  244. }
  245. };
  246. WOW.prototype.sync = function (element) {
  247. if (MutationObserver.notSupported) {
  248. return this.doSync(this.element);
  249. }
  250. };
  251. WOW.prototype.doSync = function (element) {
  252. var box, j, len, ref, results;
  253. if (element == null) {
  254. element = this.element;
  255. }
  256. if (element.nodeType !== 1) {
  257. return;
  258. }
  259. element = element.parentNode || element;
  260. ref = element.querySelectorAll("." + this.config.boxClass);
  261. results = [];
  262. for (j = 0, len = ref.length; j < len; j++) {
  263. box = ref[j];
  264. if (indexOf.call(this.all, box) < 0) {
  265. this.boxes.push(box);
  266. this.all.push(box);
  267. if (this.stopped || this.disabled()) {
  268. this.resetStyle();
  269. } else {
  270. this.applyStyle(box, true);
  271. }
  272. results.push(this.scrolled = true);
  273. } else {
  274. results.push(void 0);
  275. }
  276. }
  277. return results;
  278. };
  279. WOW.prototype.show = function (box) {
  280. this.applyStyle(box);
  281. box.className = box.className + " " + this.config.animateClass;
  282. if (this.config.callback != null) {
  283. this.config.callback(box);
  284. }
  285. this.util().emitEvent(box, this.wowEvent);
  286. this.util().addEvent(box, 'animationend', this.resetAnimation);
  287. this.util().addEvent(box, 'oanimationend', this.resetAnimation);
  288. this.util().addEvent(box, 'webkitAnimationEnd', this.resetAnimation);
  289. this.util().addEvent(box, 'MSAnimationEnd', this.resetAnimation);
  290. return box;
  291. };
  292. WOW.prototype.applyStyle = function (box, hidden) {
  293. var delay, duration, iteration;
  294. duration = box.getAttribute('data-wow-duration');
  295. delay = box.getAttribute('data-wow-delay');
  296. iteration = box.getAttribute('data-wow-iteration');
  297. return this.animate((function (_this) {
  298. return function () {
  299. return _this.customStyle(box, hidden, duration, delay, iteration);
  300. };
  301. })(this));
  302. };
  303. WOW.prototype.animate = (function () {
  304. if ('requestAnimationFrame' in window) {
  305. return function (callback) {
  306. return window.requestAnimationFrame(callback);
  307. };
  308. } else {
  309. return function (callback) {
  310. return callback();
  311. };
  312. }
  313. })();
  314. WOW.prototype.resetStyle = function () {
  315. var box, j, len, ref, results;
  316. ref = this.boxes;
  317. results = [];
  318. for (j = 0, len = ref.length; j < len; j++) {
  319. box = ref[j];
  320. results.push(box.style.visibility = 'visible');
  321. }
  322. return results;
  323. };
  324. WOW.prototype.resetAnimation = function (event) {
  325. var target;
  326. if (event.type.toLowerCase().indexOf('animationend') >= 0) {
  327. target = event.target || event.srcElement;
  328. return target.className = target.className.replace(this.config.animateClass, '').trim();
  329. }
  330. };
  331. WOW.prototype.customStyle = function (box, hidden, duration, delay, iteration) {
  332. if (hidden) {
  333. this.cacheAnimationName(box);
  334. }
  335. box.style.visibility = hidden ? 'hidden' : 'visible';
  336. if (duration) {
  337. this.vendorSet(box.style, {
  338. animationDuration: duration
  339. });
  340. }
  341. if (delay) {
  342. this.vendorSet(box.style, {
  343. animationDelay: delay
  344. });
  345. }
  346. if (iteration) {
  347. this.vendorSet(box.style, {
  348. animationIterationCount: iteration
  349. });
  350. }
  351. this.vendorSet(box.style, {
  352. animationName: hidden ? 'none' : this.cachedAnimationName(box)
  353. });
  354. return box;
  355. };
  356. WOW.prototype.vendors = ["moz", "webkit"];
  357. WOW.prototype.vendorSet = function (elem, properties) {
  358. var name, results, value, vendor;
  359. results = [];
  360. for (name in properties) {
  361. value = properties[name];
  362. elem["" + name] = value;
  363. results.push((function () {
  364. var j, len, ref, results1;
  365. ref = this.vendors;
  366. results1 = [];
  367. for (j = 0, len = ref.length; j < len; j++) {
  368. vendor = ref[j];
  369. results1.push(elem["" + vendor + (name.charAt(0).toUpperCase()) + (name.substr(1))] = value);
  370. }
  371. return results1;
  372. }).call(this));
  373. }
  374. return results;
  375. };
  376. WOW.prototype.vendorCSS = function (elem, property) {
  377. var j, len, ref, result, style, vendor;
  378. style = getComputedStyle(elem);
  379. result = style.getPropertyCSSValue(property);
  380. ref = this.vendors;
  381. for (j = 0, len = ref.length; j < len; j++) {
  382. vendor = ref[j];
  383. result = result || style.getPropertyCSSValue("-" + vendor + "-" + property);
  384. }
  385. return result;
  386. };
  387. WOW.prototype.animationName = function (box) {
  388. var animationName, error;
  389. try {
  390. animationName = this.vendorCSS(box, 'animation-name').cssText;
  391. } catch (error) {
  392. animationName = getComputedStyle(box).getPropertyValue('animation-name');
  393. }
  394. if (animationName === 'none') {
  395. return '';
  396. } else {
  397. return animationName;
  398. }
  399. };
  400. WOW.prototype.cacheAnimationName = function (box) {
  401. return this.animationNameCache.set(box, this.animationName(box));
  402. };
  403. WOW.prototype.cachedAnimationName = function (box) {
  404. return this.animationNameCache.get(box);
  405. };
  406. WOW.prototype.scrollHandler = function () {
  407. return this.scrolled = true;
  408. };
  409. WOW.prototype.scrollCallback = function () {
  410. var box;
  411. if (this.scrolled) {
  412. this.scrolled = false;
  413. this.boxes = (function () {
  414. var j, len, ref, results;
  415. ref = this.boxes;
  416. results = [];
  417. for (j = 0, len = ref.length; j < len; j++) {
  418. box = ref[j];
  419. if (!(box)) {
  420. continue;
  421. }
  422. if (this.isVisible(box)) {
  423. this.show(box);
  424. continue;
  425. }
  426. results.push(box);
  427. }
  428. return results;
  429. }).call(this);
  430. if (!(this.boxes.length || this.config.live)) {
  431. return this.stop();
  432. }
  433. }
  434. };
  435. WOW.prototype.offsetTop = function (element) {
  436. var top;
  437. while (element.offsetTop === void 0) {
  438. element = element.parentNode;
  439. }
  440. top = element.offsetTop;
  441. while (element = element.offsetParent) {
  442. top += element.offsetTop;
  443. }
  444. return top;
  445. };
  446. WOW.prototype.isVisible = function (box) {
  447. var bottom, offset, top, viewBottom, viewTop;
  448. offset = box.getAttribute('data-wow-offset') || this.config.offset;
  449. viewTop = (this.config.scrollContainer && this.config.scrollContainer.scrollTop) || window.pageYOffset;
  450. viewBottom = viewTop + Math.min(this.element.clientHeight, this.util().innerHeight()) - offset;
  451. top = this.offsetTop(box);
  452. bottom = top + box.clientHeight;
  453. return top <= viewBottom && bottom >= viewTop;
  454. };
  455. WOW.prototype.util = function () {
  456. return this._util != null ? this._util : this._util = new Util();
  457. };
  458. WOW.prototype.disabled = function () {
  459. return !this.config.mobile && this.util().isMobile(navigator.userAgent);
  460. };
  461. return WOW;
  462. })();
  463. }).call(this);