Created
December 23, 2016 23:02
-
-
Save koohz/c6634f5a4de8fa50b6cf76ceb7104c0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* TrueCurrent for Owl Carousel | |
* @since 2.0.2 | |
*/ | |
;(function($, window, document, undefined) { | |
'use strict'; | |
var TrueCurrent = function(carousel) { | |
var current = 0; | |
var itemsCount = 0; | |
/** | |
* Reference to the core. | |
* @protected | |
* @type {Owl} | |
*/ | |
this._core = carousel; | |
/** | |
* The carousel element. | |
* @type {jQuery} | |
*/ | |
this.$element = this._core.$element; | |
/** | |
* The carousel true current index. | |
* @type {Number} | |
*/ | |
this._trueCurrent = 0; | |
/** | |
* Changed event handler. | |
* @protected | |
* @type {Object} | |
*/ | |
this._handlers = { | |
'changed.owl.carousel': $.proxy(function (e) { | |
current = (e.item.index + 1) - e.relatedTarget._clones.length / 2; | |
itemsCount = e.item.count; | |
if (current > itemsCount || current == 0) { | |
current = itemsCount - (current % itemsCount); | |
} | |
this._trueCurrent = current; | |
e.item._trueCurrent = current; | |
}, this) | |
}; | |
// register event handlers | |
this.$element.on(this._handlers); | |
}; | |
/** | |
* Destroys the plugin. | |
* @protected | |
*/ | |
TrueCurrent.prototype.destroy = function() { | |
var handler, control, property, override; | |
for (handler in this._handlers) { | |
this.$element.off(handler, this._handlers[handler]); | |
} | |
for (control in this._controls) { | |
this._controls[control].remove(); | |
} | |
for (override in this.overides) { | |
this._core[override] = this._overrides[override]; | |
} | |
for (property in Object.getOwnPropertyNames(this)) { | |
typeof this[property] != 'function' && (this[property] = null); | |
} | |
}; | |
$.fn.owlCarousel.Constructor.Plugins.TrueCurrent = TrueCurrent; | |
})(window.Zepto || window.jQuery, window, document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment