Created
October 13, 2016 18:42
-
-
Save ghorvat/68ca991b202584a394638045b0dbef6e 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
;(function($, window, document, undefined) { | |
/** | |
* Creates the auto height plugin. | |
* @class The Auto Height Plugin | |
* @param {Owl} carousel - The Owl Carousel | |
*/ | |
var HeightAuto = function(carousel) { | |
/** | |
* Reference to the core. | |
* @protected | |
* @type {Owl} | |
*/ | |
this._core = carousel; | |
/** | |
* All event handlers. | |
* @protected | |
* @type {Object} | |
*/ | |
this._handlers = { | |
'initialized.owl.carousel': $.proxy(function() { | |
if (this._core.settings.heightAuto) { | |
this.update(); | |
} | |
}, this), | |
'changed.owl.carousel': $.proxy(function(e) { | |
if (this._core.settings.heightAuto && e.property.name == 'position'){ | |
this.update(); | |
} | |
}, this), | |
'resized.owl.carousel': $.proxy(function(e) { | |
if (this._core.settings.heightAuto) { | |
this.update(); | |
} | |
}, this), | |
'loaded.owl.lazy': $.proxy(function(e) { | |
if (this._core.settings.heightAuto && e.element.closest('.' + this._core.settings.itemClass) | |
=== this._core.$stage.children().eq(this._core.current())) { | |
this.update(); | |
} | |
}, this) | |
}; | |
// set default options | |
this._core.options = $.extend({}, HeightAuto.Defaults, this._core.options); | |
// register event handlers | |
this._core.$element.on(this._handlers); | |
}; | |
/** | |
* Default options. | |
* @public | |
*/ | |
HeightAuto.Defaults = { | |
heightAuto: false, | |
heightAutoClass: 'owl-height' | |
}; | |
/** | |
* Updates the view. | |
*/ | |
HeightAuto.prototype.update = function() { | |
this._core.$stage.parent() | |
.height(this._core.$stage.children().eq(this._core.current()).height()) | |
.addClass(this._core.settings.heightAutoClass); | |
}; | |
HeightAuto.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.HeightAuto = HeightAuto; | |
})(window.Zepto || window.jQuery, window, document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment