Blame view

frontend/web/js/new-owl/owl.animate.js 2.94 KB
b60a88b8   Anastasia   - main page
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
  /**
   * Animate Plugin
   * @version 2.1.0
   * @author Bartosz Wojciechowski
   * @author David Deutsch
   * @license The MIT License (MIT)
   */
  ;(function($, window, document, undefined) {
  
  	/**
  	 * Creates the animate plugin.
  	 * @class The Navigation Plugin
  	 * @param {Owl} scope - The Owl Carousel
  	 */
  	var Animate = function(scope) {
  		this.core = scope;
  		this.core.options = $.extend({}, Animate.Defaults, this.core.options);
  		this.swapping = true;
  		this.previous = undefined;
  		this.next = undefined;
  
  		this.handlers = {
  			'change.owl.carousel': $.proxy(function(e) {
  				if (e.namespace && e.property.name == 'position') {
  					this.previous = this.core.current();
  					this.next = e.property.value;
  				}
  			}, this),
  			'drag.owl.carousel dragged.owl.carousel translated.owl.carousel': $.proxy(function(e) {
  				if (e.namespace) {
  					this.swapping = e.type == 'translated';
  				}
  			}, this),
  			'translate.owl.carousel': $.proxy(function(e) {
  				if (e.namespace && this.swapping && (this.core.options.animateOut || this.core.options.animateIn)) {
  					this.swap();
  				}
  			}, this)
  		};
  
  		this.core.$element.on(this.handlers);
  	};
  
  	/**
  	 * Default options.
  	 * @public
  	 */
  	Animate.Defaults = {
  		animateOut: false,
  		animateIn: false
  	};
  
  	/**
  	 * Toggles the animation classes whenever an translations starts.
  	 * @protected
  	 * @returns {Boolean|undefined}
  	 */
  	Animate.prototype.swap = function() {
  
  		if (this.core.settings.items !== 1) {
  			return;
  		}
  
  		if (!$.support.animation || !$.support.transition) {
  			return;
  		}
  
  		this.core.speed(0);
  
  		var left,
  			clear = $.proxy(this.clear, this),
  			previous = this.core.$stage.children().eq(this.previous),
  			next = this.core.$stage.children().eq(this.next),
  			incoming = this.core.settings.animateIn,
  			outgoing = this.core.settings.animateOut;
  
  		if (this.core.current() === this.previous) {
  			return;
  		}
  
  		if (outgoing) {
  			left = this.core.coordinates(this.previous) - this.core.coordinates(this.next);
  			previous.one($.support.animation.end, clear)
  				.css( { 'left': left + 'px' } )
  				.addClass('animated owl-animated-out')
  				.addClass(outgoing);
  		}
  
  		if (incoming) {
  			next.one($.support.animation.end, clear)
  				.addClass('animated owl-animated-in')
  				.addClass(incoming);
  		}
  	};
  
  	Animate.prototype.clear = function(e) {
  		$(e.target).css( { 'left': '' } )
  			.removeClass('animated owl-animated-out owl-animated-in')
  			.removeClass(this.core.settings.animateIn)
  			.removeClass(this.core.settings.animateOut);
  		this.core.onTransitionEnd();
  	};
  
  	/**
  	 * Destroys the plugin.
  	 * @public
  	 */
  	Animate.prototype.destroy = function() {
  		var handler, property;
  
  		for (handler in this.handlers) {
  			this.core.$element.off(handler, this.handlers[handler]);
  		}
  		for (property in Object.getOwnPropertyNames(this)) {
  			typeof this[property] != 'function' && (this[property] = null);
  		}
  	};
  
  	$.fn.owlCarousel.Constructor.Plugins.Animate = Animate;
  
  })(window.Zepto || window.jQuery, window, document);