Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bhikandeshmukh
GitHub Repository: bhikandeshmukh/shark
Path: blob/master/phs/tiktok/vendor/animsition/js/animsition.js
996 views
1
/*!
2
* animsition v4.0.2
3
* A simple and easy jQuery plugin for CSS animated page transitions.
4
* http://blivesta.github.io/animsition
5
* License : MIT
6
* Author : blivesta (http://blivesta.com/)
7
*/
8
;(function (factory) {
9
'use strict';
10
if (typeof define === 'function' && define.amd) {
11
define(['jquery'], factory);
12
} else if (typeof exports === 'object') {
13
module.exports = factory(require('jquery'));
14
} else {
15
factory(jQuery);
16
}
17
}(function ($) {
18
'use strict';
19
var namespace = 'animsition';
20
var __ = {
21
init: function(options){
22
options = $.extend({
23
inClass : 'fade-in',
24
outClass : 'fade-out',
25
inDuration : 1500,
26
outDuration : 800,
27
linkElement : '.animsition-link',
28
// e.g. linkElement : 'a:not([target="_blank"]):not([href^="#"])'
29
loading : true,
30
loadingParentElement : 'body', //animsition wrapper element
31
loadingClass : 'animsition-loading',
32
loadingInner : '', // e.g '<img src="loading.svg" />'
33
timeout : false,
34
timeoutCountdown : 5000,
35
onLoadEvent : true,
36
browser : [ 'animation-duration', '-webkit-animation-duration'],
37
// "browser" option allows you to disable the "animsition" in case the css property in the array is not supported by your browser.
38
// The default setting is to disable the "animsition" in a browser that does not support "animation-duration".
39
overlay : false,
40
overlayClass : 'animsition-overlay-slide',
41
overlayParentElement : 'body',
42
transition : function(url){ window.location.href = url; }
43
}, options);
44
45
__.settings = {
46
timer: false,
47
data: {
48
inClass: 'animsition-in-class',
49
inDuration: 'animsition-in-duration',
50
outClass: 'animsition-out-class',
51
outDuration: 'animsition-out-duration',
52
overlay: 'animsition-overlay'
53
},
54
events: {
55
inStart: 'animsition.inStart',
56
inEnd: 'animsition.inEnd',
57
outStart: 'animsition.outStart',
58
outEnd: 'animsition.outEnd'
59
}
60
};
61
62
// Remove the "Animsition" in a browser
63
// that does not support the "animaition-duration".
64
var support = __.supportCheck.call(this, options);
65
66
if(!support && options.browser.length > 0){
67
if(!support || !this.length){
68
// If do not have a console object to object window
69
if (!('console' in window)) {
70
window.console = {};
71
window.console.log = function(str){ return str; };
72
}
73
if(!this.length) console.log('Animsition: Element does not exist on page.');
74
if(!support) console.log('Animsition: Does not support this browser.');
75
return __.destroy.call(this);
76
}
77
}
78
79
var overlayMode = __.optionCheck.call(this, options);
80
81
if (overlayMode && $('.' + options.overlayClass).length <= 0) {
82
__.addOverlay.call(this, options);
83
}
84
85
if (options.loading && $('.' + options.loadingClass).length <= 0) {
86
__.addLoading.call(this, options);
87
}
88
89
return this.each(function(){
90
var _this = this;
91
var $this = $(this);
92
var $window = $(window);
93
var $document = $(document);
94
var data = $this.data(namespace);
95
96
if (!data) {
97
options = $.extend({}, options);
98
99
$this.data(namespace, { options: options });
100
101
if(options.timeout) __.addTimer.call(_this);
102
103
if(options.onLoadEvent) {
104
$window.on('load.' + namespace, function() {
105
if(__.settings.timer) clearTimeout(__.settings.timer);
106
__.in.call(_this);
107
});
108
}
109
110
$window.on('pageshow.' + namespace, function(event) {
111
if(event.originalEvent.persisted) __.in.call(_this);
112
});
113
114
// Firefox back button issue #4
115
$window.on('unload.' + namespace, function() { });
116
117
$document.on('click.' + namespace, options.linkElement, function(event) {
118
event.preventDefault();
119
var $self = $(this);
120
var url = $self.attr('href');
121
122
// middle mouse button issue #24
123
// if(middle mouse button || command key || shift key || win control key)
124
if (event.which === 2 || event.metaKey || event.shiftKey || navigator.platform.toUpperCase().indexOf('WIN') !== -1 && event.ctrlKey) {
125
window.open(url, '_blank');
126
} else {
127
__.out.call(_this, $self, url);
128
}
129
130
});
131
}
132
}); // end each
133
},
134
135
addOverlay: function(options){
136
$(options.overlayParentElement)
137
.prepend('<div class="' + options.overlayClass + '"></div>');
138
},
139
140
addLoading: function(options){
141
$(options.loadingParentElement)
142
.append('<div class="' + options.loadingClass + '">' + options.loadingInner + '</div>');
143
},
144
145
removeLoading: function(){
146
var $this = $(this);
147
var options = $this.data(namespace).options;
148
var $loading = $(options.loadingParentElement).children('.' + options.loadingClass);
149
150
$loading.fadeOut().remove();
151
},
152
153
addTimer: function(){
154
var _this = this;
155
var $this = $(this);
156
var options = $this.data(namespace).options;
157
158
__.settings.timer = setTimeout(function(){
159
__.in.call(_this);
160
$(window).off('load.' + namespace);
161
}, options.timeoutCountdown);
162
},
163
164
supportCheck: function(options){
165
var $this = $(this);
166
var props = options.browser;
167
var propsNum = props.length;
168
var support = false;
169
170
if (propsNum === 0) {
171
support = true;
172
}
173
for (var i = 0; i < propsNum; i++) {
174
if (typeof $this.css(props[i]) === 'string') {
175
support = true;
176
break;
177
}
178
}
179
return support;
180
},
181
182
optionCheck: function(options){
183
var $this = $(this);
184
var overlayMode;
185
if(options.overlay || $this.data(__.settings.data.overlay)){
186
overlayMode = true;
187
} else {
188
overlayMode = false;
189
}
190
return overlayMode;
191
},
192
193
animationCheck : function(data, stateClass, stateIn){
194
var $this = $(this);
195
var options = $this.data(namespace).options;
196
var dataType = typeof data;
197
var dataDuration = !stateClass && dataType === 'number';
198
var dataClass = stateClass && dataType === 'string' && data.length > 0;
199
200
if(dataDuration || dataClass){
201
data = data;
202
} else if(stateClass && stateIn) {
203
data = options.inClass;
204
} else if(!stateClass && stateIn) {
205
data = options.inDuration;
206
} else if(stateClass && !stateIn) {
207
data = options.outClass;
208
} else if(!stateClass && !stateIn) {
209
data = options.outDuration;
210
}
211
return data;
212
},
213
214
in: function(){
215
var _this = this;
216
var $this = $(this);
217
var options = $this.data(namespace).options;
218
var thisInDuration = $this.data(__.settings.data.inDuration);
219
var thisInClass = $this.data(__.settings.data.inClass);
220
var inDuration = __.animationCheck.call(_this, thisInDuration, false, true);
221
var inClass = __.animationCheck.call(_this, thisInClass, true, true);
222
var overlayMode = __.optionCheck.call(_this, options);
223
var outClass = $this.data(namespace).outClass;
224
225
if(options.loading) __.removeLoading.call(_this);
226
227
if(outClass) $this.removeClass(outClass);
228
229
if(overlayMode) {
230
__.inOverlay.call(_this, inClass, inDuration);
231
} else {
232
__.inDefault.call(_this, inClass, inDuration);
233
}
234
},
235
236
inDefault: function(inClass, inDuration){
237
var $this = $(this);
238
239
$this
240
.css({ 'animation-duration' : inDuration + 'ms' })
241
.addClass(inClass)
242
.trigger(__.settings.events.inStart)
243
.animateCallback(function(){
244
$this
245
.removeClass(inClass)
246
.css({ 'opacity' : 1 })
247
.trigger(__.settings.events.inEnd);
248
});
249
},
250
251
inOverlay: function(inClass, inDuration){
252
var $this = $(this);
253
var options = $this.data(namespace).options;
254
255
$this
256
.css({ 'opacity' : 1 })
257
.trigger(__.settings.events.inStart);
258
259
$(options.overlayParentElement)
260
.children('.' + options.overlayClass)
261
.css({ 'animation-duration' : inDuration + 'ms' })
262
.addClass(inClass)
263
.animateCallback(function(){
264
$this
265
.trigger(__.settings.events.inEnd);
266
});
267
},
268
269
out: function($self, url){
270
var _this = this;
271
var $this = $(this);
272
var options = $this.data(namespace).options;
273
var selfOutClass = $self.data(__.settings.data.outClass);
274
var thisOutClass = $this.data(__.settings.data.outClass);
275
var selfOutDuration = $self.data(__.settings.data.outDuration);
276
var thisOutDuration = $this.data(__.settings.data.outDuration);
277
var isOutClass = selfOutClass ? selfOutClass : thisOutClass;
278
var isOutDuration = selfOutDuration ? selfOutDuration : thisOutDuration;
279
var outClass = __.animationCheck.call(_this, isOutClass, true, false);
280
var outDuration = __.animationCheck.call(_this, isOutDuration, false, false);
281
var overlayMode = __.optionCheck.call(_this, options);
282
283
$this.data(namespace).outClass = outClass;
284
285
if(overlayMode) {
286
__.outOverlay.call(_this, outClass, outDuration, url);
287
} else {
288
__.outDefault.call(_this, outClass, outDuration, url);
289
}
290
},
291
292
outDefault: function(outClass, outDuration, url){
293
var $this = $(this);
294
var options = $this.data(namespace).options;
295
296
// (outDuration + 1) | #55 outDuration: 0 crashes on Safari only
297
$this
298
.css({ 'animation-duration' : (outDuration + 1) + 'ms' })
299
.addClass(outClass)
300
.trigger(__.settings.events.outStart)
301
.animateCallback(function(){
302
$this.trigger(__.settings.events.outEnd);
303
options.transition(url);
304
});
305
},
306
307
308
outOverlay: function(outClass, outDuration, url){
309
var _this = this;
310
var $this = $(this);
311
var options = $this.data(namespace).options;
312
var thisInClass = $this.data(__.settings.data.inClass);
313
var inClass = __.animationCheck.call(_this, thisInClass, true, true);
314
315
// (outDuration + 1) | #55 outDuration: 0 crashes animsition on Safari only
316
$(options.overlayParentElement)
317
.children('.' + options.overlayClass)
318
.css({ 'animation-duration' : (outDuration + 1) + 'ms' })
319
.removeClass(inClass)
320
.addClass(outClass)
321
.trigger(__.settings.events.outStart)
322
.animateCallback(function(){
323
$this.trigger(__.settings.events.outEnd);
324
options.transition(url);
325
});
326
},
327
328
destroy: function(){
329
return this.each(function(){
330
var $this = $(this);
331
$(window).off('.'+ namespace);
332
$this
333
.css({'opacity': 1})
334
.removeData(namespace);
335
});
336
}
337
338
};
339
340
$.fn.animateCallback = function(callback){
341
var end = 'animationend webkitAnimationEnd';
342
return this.each(function() {
343
var $this = $(this);
344
$this.on(end, function(){
345
$this.off(end);
346
return callback.call(this);
347
});
348
});
349
};
350
351
$.fn.animsition = function(method){
352
if ( __[method] ) {
353
return __[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
354
} else if ( typeof method === 'object' || ! method ) {
355
return __.init.apply( this, arguments );
356
} else {
357
$.error( 'Method ' + method + ' does not exist on jQuery.'+namespace);
358
}
359
};
360
361
}));
362
363