* @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'),
_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
}
}
+ /**
+ * 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
* @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);