-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathanimateCss.bundle.js
More file actions
152 lines (128 loc) · 4.44 KB
/
animateCss.bundle.js
File metadata and controls
152 lines (128 loc) · 4.44 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.animateCss = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
/**
* Set the css animationDuration on an element (el). Leave duration undefined to reset;
* @private
*
* @param {Element} el
* @param {number} [duration] in ms
*/
var setAnimationDuration = function (el, duration) {
var durationMs = duration ? duration + 'ms' : '';
el.style['-webkit-animation-duration'] = durationMs;
el.style['animation-duration'] = durationMs;
};
/**
* Add or remove the 'animated' class and the animation type class.
* @private
*
* @param {Element} el
* @param {String} animationName
* @param {Boolean} [doAdd=true] - set to false to remove the classes
*/
var setAnimateCssClasses = function (el, animationName, doAdd) {
['animated', animationName].forEach(function (str) {
el.classList[doAdd !== false ? 'add' : 'remove'](str);
});
};
//https://jonsuh.com/blog/detect-the-end-of-css-animations-and-transitions-with-javascript/
var whichAnimationEvent = function () {
var el = document.createElement('fakeelement'), t;
var animations = {
'animation': 'animationend',
'OAnimation': 'oAnimationEnd',
'MozAnimation': 'animationend',
'WebkitAnimation': 'webkitAnimationEnd'
};
for (t in animations) {
if (el.style[t] !== undefined) {
return animations[t];
}
}
};
/**
*
* @param {Element} el
* @param {object} opts
* @property {string} opts.animationName
* @property {number} [opts.duration]
* @param {function[]} [opts.callbacks=[]]
*/
var animate = function (el, opts) {
opts.callbacks = opts.callbacks || [];
var animationEventName = whichAnimationEvent();
if (opts.duration) {
setAnimationDuration(el, opts.duration);
}
setAnimateCssClasses(el, opts.animationName);
el.addEventListener(animationEventName, animEnd);
function animEnd() {
el.removeEventListener(animationEventName, animEnd);
//remove the animate.css classes
setAnimateCssClasses(el, opts.animationName, false);
if (opts.duration) {
//reset animationDuration
setAnimationDuration(el);
}
// call the callbacks
opts.callbacks.forEach(function (cb) {
cb();
});
opts.callbacks = [];
}
};
/**
*
* @param {Element} el
* @param {object} [opts]
* @property {string} [opts.animationName='slideInDown']
* @property {number} [opts.duration=300]
* @param {function[]} [opts.callbacks]
*/
var show = function (el, opts) {
opts = opts || {};
opts.animationName = opts.animationName || 'slideInDown';
opts.duration = opts.duration || 350;
el.classList.remove('hidden');
animate(el, opts);
};
/**
*
* @param {Element} el
* @param {object} [opts]
* @property {string} [opts.animationName='slideInDown']
* @property {number} [opts.duration=300]
* @param {function[]} [opts.callbacks]
*/
var hide = function (el, opts) {
opts = opts || {};
opts.animationName = opts.animationName || 'slideOutUp';
opts.duration = opts.duration || 300;
opts.callbacks = opts.callbacks || [];
//if the element is already hidden
if (el.classList.contains('hidden')) {
//call the callbacks directly
opts.callbacks.forEach(function (cb) {
cb();
});
//and get out
return;
}
opts.callbacks.push(function () {
el.classList.add('hidden');
});
animate(el, opts);
};
/**
* API
*
* @type {{animateCSS: Function, show: Function, hide: Function}}
*/
var animations = {
animate: animate,
// show and hide convenience functions
show: show,
hide: hide
};
module.exports = animations;
},{}]},{},[1])(1)
});