-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimation.js
More file actions
142 lines (117 loc) · 3.98 KB
/
animation.js
File metadata and controls
142 lines (117 loc) · 3.98 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
/*
* Animation.js v1.0.1 Copyright (c) 2013
* License: MIT
* Author: Roll
* http://github.com/rollRoll/Animation.js
*/
;(function($, window, document, undefined) { "use strict";
var
Animation,
_ieVersion,
_isIEBrowser,
_div = document.createElement( 'div' ),
_hasRnBFramework = !! ( window.R && window.RnB && R.Util );
Animation = {
timeCls: 'animated',
/**
* Get the major version of IE
* @return [integer]
* @reference James Padolsey <https://gist.github.com/527683>
*/
isIE: ( _hasRnBFramework )? R.Util.isIE : function() {
var self = Animation.isIE;
self.version = ( self.version !== undefined )? self.version
: (function(){
var
v = 3, div, all,
isIE10 = /Mozilla\/5.0 \(compatible\; MSIE 10(.+)/.test( window.navigator.userAgent );
if ( isIE10 ) return 10;
div = document.createElement('div'),
all = div.getElementsByTagName('i');
while (
div.innerHTML = '<!--[if gt IE ' + ( ++v ) + ']><i></i><![endif]-->',
all[0]
){;}
return ( v > 4 )? v : false;
}());
return self.version;
},
getVendorPrefix: function( cssName ) {
cssName = cssName || 'Animation';
var
self = Animation.getVendorPrefix,
defaults = cssName.toLowerCase();
self.prefix = ( self.prefix !== undefined )? self.prefix
: (function(){
var
prefixes = [defaults, "Moz" + cssName, "Webkit" + cssName, "ms" + cssName, "O" + cssName],
reg = new RegExp('(.+)' + defaults, 'i'),
i = 0, len = prefixes.length,
matchs, defaultPrefix = "";
for ( ; i < len; i++ ) {
if ( _div.style[ prefixes[ i ] ] !== undefined ) {
matchs = prefixes[ i ].match( reg );
return ( matchs )? matchs[1].toLowerCase() : defaultPrefix;
}
}
return false;
}());
return self.prefix;
},
prefixed: function( cssName ) {
var vendorPrefix = Animation.getVendorPrefix();
return ( vendorPrefix )? vendorPrefix + cssName : cssName.toLowerCase();
},
on: function($dom, eventName, eventFn) {
var vendorEventName = Animation.prefixed( eventName );
$dom.one(vendorEventName, eventFn);
( _isIEBrowser ) && $dom.trigger( vendorEventName );
},
off: function($dom, eventName, stop) {
var vendorEventName = Animation.prefixed( eventName );
( stop ) && $dom.trigger( vendorEventName );
$dom.off( vendorEventName );
},
animateIn: function($dom, animateCls, callback, timeCls, removeClass) {
var cls = ( timeCls === null? '' : timeCls || Animation.timeCls ) + ' ' + animateCls;
$dom.offAnimationEnd( true );
$dom.show().addClass( cls );
$dom.onAnimationEnd(function( e ) {
( removeClass !== false ) && $dom.removeClass( cls );
( callback ) && callback( e );
});
return $dom;
},
animateOut: function($dom, animateCls, callback, timeCls) {
var cls = ( timeCls === null? '' : timeCls || Animation.timeCls ) + ' ' + animateCls;
$dom.addClass( cls );
$dom.onAnimationEnd(function( e ) {
$dom.hide().removeClass( cls );
( callback ) && callback( e );
});
return $dom;
},
animate: function(action, $dom, animateCls, args) {
var animateArgs = [$dom, animateCls].concat( Array.prototype.slice.call( args ) );
return this[ ( action === 'in' )? 'animateIn' : 'animateOut' ].apply(this, animateArgs);
}
};
_ieVersion = Animation.isIE(),
_isIEBrowser = ( _ieVersion && _ieVersion < 10 );
$.fn.extend({
onAnimationEnd: function( callback ) {
return Animation.on(this, 'AnimationEnd', callback);
},
offAnimationEnd: function( stop ) {
return Animation.off(this, 'AnimationEnd', stop);
}
});
// Expose Animation to the global object
window.Animation = Animation;
// Expose Animation as an AMD module
if ( $.isFunction( window.define ) && define.amd ) {
define("Animation", [], function() {
return Animation;
});
}
})($, this, this.document);