From: Milos Sakovic Date: Thu, 20 Oct 2016 23:30:38 +0000 (+0200) Subject: [Orbit] Detaches events on reInit X-Git-Tag: v6.3-rc1~41^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2fb528a29836d69cb57712d37925918ffd746a99;p=thirdparty%2Ffoundation%2Ffoundation-sites.git [Orbit] Detaches events on reInit --- diff --git a/js/foundation.orbit.js b/js/foundation.orbit.js index e02724c1d..dd663a6a7 100644 --- a/js/foundation.orbit.js +++ b/js/foundation.orbit.js @@ -43,6 +43,8 @@ class Orbit { * @private */ _init() { + this._detachEvents(); + this.$wrapper = this.$element.find(`.${this.options.containerClass}`); this.$slides = this.$element.find(`.${this.options.slideClass}`); var $images = this.$element.find('img'), @@ -216,7 +218,7 @@ class Orbit { _this.changeSlide(ltr, $slide, idx); }); } - + if (this.options.accessible) { this.$wrapper.add(this.$bullets).on('keydown.zf.orbit', function(e) { // handle keyboard event with keyboard util @@ -238,6 +240,44 @@ class Orbit { } } + /** + * Detaches event listeners + */ + _detachEvents() { + // Don't do anything if there are no slides (first run) + if (typeof this.$slides == "undefined") { + return; + } + + if (this.$slides.length > 1) { + // Remove old events + this.$element.off('.zf.orbit').find('*').off('.zf.orbit') + + // Restart timer if autoPlay is enabled + if (this.options.autoPlay) { + this.timer.restart(); + } + + // Reset all sliddes + this.$slides.each(function(el) { + $(el).removeClass('is-active is-active is-in') + .removeAttr('aria-live') + .hide(); + }); + + // Show the first slide + this.$slides.first().addClass('is-active').show(); + + // Triggers when the slide has finished animating + this.$element.trigger('slidechange.zf.orbit', [this.$slides.first()]); + + // Select first bullet if bullets are present + if (this.options.bullets) { + this._updateBullets(0); + } + } + } + /** * Changes the current slide to a new one. * @function @@ -273,7 +313,7 @@ class Orbit { * @event Orbit#beforeslidechange */ this.$element.trigger('beforeslidechange.zf.orbit', [$curSlide, $newSlide]); - + if (this.options.bullets) { idx = idx || this.$slides.index($newSlide); //grab index to update bullets this._updateBullets(idx);