-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathowl.sync.js
106 lines (94 loc) · 2.35 KB
/
owl.sync.js
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
/**
* Sync Plugin
* @version 2.1.0
* @author Emanuele parisio
* @license The MIT License (MIT)
*/
;(function($, window, document, undefined) {
'use strict';
/**
* Creates the sync plugin.
* @class The sync Plugin
* @param {Owl} carousel - The Owl Carousel.
*/
var Sync = function(carousel) {
/**
* Reference to the core.
* @protected
* @type {Owl}
*/
this._core = carousel;
/**
* The carousel element.
* @type {jQuery}
*/
this.$element = this._core.$element;
/**
* All event handlers.
* @protected
* @type {Object}
*/
this._handlers = {
'change.owl.carousel': $.proxy(function(e) {
if (e.namespace && e.property.name == 'position') {
this.createEvent(e,'syncBefore');
}
}, this),
'changed.owl.carousel': $.proxy(function(e) {
if (e.namespace && e.property.name == 'position') {
this.update(e.item.index);
this.createEvent(e,'syncAfter');
}
}, this),
};
/* set default options */
this._core.options = $.extend({}, Sync.Defaults, this._core.options);
/* register event handlers */
this.$element.on(this._handlers);
};
/**
* Default options.
* @public
*/
Sync.Defaults = {
syncTarget : false
};
/**
* Updates target carousel state.
* @protected
*/
Sync.prototype.update = function(position) {
var settings = this._core.settings;
$(settings.syncTarget).trigger('to.owl.carousel', [position, settings.navSpeed, true]);
};
/**
* create event fof to sync callback
* @param {object} e carousel
* @param {string} event event name
*/
Sync.prototype.createEvent = function(e,event) {
var settings = this._core.settings,
targetData;
this._core.trigger(event, {
syncTarget: {
name: settings.syncTarget,
elements: $(settings.syncTarget),
position: e.item.index,
},
});
};
/**
* Destroys the plugin.
* @protected
*/
Sync.prototype.destroy = function() {
var handler, property;
for (handler in this._handlers) {
this.$element.off(handler, this._handlers[handler]);
}
for (property in Object.getOwnPropertyNames(this)) {
typeof this[property] != 'function' && (this[property] = null);
}
};
$.fn.owlCarousel.Constructor.Plugins.Sync = Sync;
})(window.Zepto || window.jQuery, window, document);