1 2/** 3 * Plugin for linking multiple owl instances 4 * @version 1.0.0 5 * @author David Deutsch 6 * @license The MIT License (MIT) 7 */ 8;(function($, window, document, undefined) { 9 /** 10 * Creates the Linked plugin. 11 * @class The Linked Plugin 12 * @param {Owl} carousel - The Owl Carousel 13 */ 14 var Linked = function(carousel) { 15 /** 16 * Reference to the core. 17 * @protected 18 * @type {Owl} 19 */ 20 this._core = carousel; 21 22 /** 23 * All event handlers. 24 * @protected 25 * @type {Object} 26 */ 27 this._handlers = { 28 'dragged.owl.carousel changed.owl.carousel': $.proxy(function(e) { 29 if (e.namespace && this._core.settings.linked) { 30 this.update(e); 31 } 32 }, this), 33 'linked.to.owl.carousel': $.proxy(function(e, index, speed, standard, propagate) { 34 if (e.namespace && this._core.settings.linked) { 35 this.toSlide(index, speed, propagate); 36 } 37 }, this) 38 }; 39 40 // register event handlers 41 this._core.$element.on(this._handlers); 42 43 // set default options 44 this._core.options = $.extend({}, Linked.Defaults, this._core.options); 45 }; 46 47 /** 48 * Default options. 49 * @public 50 */ 51 Linked.Defaults = { 52 linked: false 53 }; 54 55 /** 56 * Updated linked instances 57 */ 58 Linked.prototype.update = function(e) { 59 this.toSlide( e.relatedTarget.relative(e.item.index) ); 60 }; 61 62 /** 63 * Carry out the to.owl.carousel proxy function 64 * @param {int} index 65 * @param {int} speed 66 * @param {bool} propagate 67 */ 68 Linked.prototype.toSlide = function(index, speed, propagate) { 69 var id = this._core.$element.attr('id'), 70 linked = typeof(this._core.settings.linked) === 'string' ? this._core.settings.linked.split(',') : this._core.settings.linked; 71 72 if ( typeof propagate == 'undefined' ) { 73 propagate = true; 74 } 75 76 index = index || 0; 77 78 if ( propagate ) { 79 $.each(linked, function(i, el){ 80 $(el).trigger('linked.to.owl.carousel', [index, 300, true, false]); 81 }); 82 } else { 83 this._core.$element.trigger('to.owl.carousel', [index, 300, true]); 84 85 if ( this._core.settings.current ) { 86 this._core._plugins.current.switchTo(index); 87 } 88 } 89 }; 90 91 /** 92 * Destroys the plugin. 93 * @protected 94 */ 95 Linked.prototype.destroy = function() { 96 var handler, property; 97 98 for (handler in this._handlers) { 99 this.$element.off(handler, this._handlers[handler]); 100 } 101 for (property in Object.getOwnPropertyNames(this)) { 102 typeof this[property] != 'function' && (this[property] = null); 103 } 104 }; 105 106 $.fn.owlCarousel.Constructor.Plugins.linked = Linked; 107 108})(window.Zepto || window.jQuery, window, document);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.