Skip to content

Commit

Permalink
Totally destroy swiper
Browse files Browse the repository at this point in the history
  • Loading branch information
nolimits4web committed Sep 19, 2014
1 parent e28fe4c commit 970f696
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/idangerous.swiper.js
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ var Swiper = function (selector, params) {
}

//Remove Event Listeners
_this.destroy = function () {
_this.destroy = function (removeStyles) {
var unbind = _this.h.removeEventListener;
var eventTarget = params.eventTarget === 'wrapper' ? _this.wrapper : _this.container;
//Touch Events
Expand Down Expand Up @@ -1011,8 +1011,24 @@ var Swiper = function (selector, params) {
if (params.autoplay) {
_this.stopAutoplay();
}
// Remove styles
if (removeStyles) {
_this.wrapper.removeAttribute('style');
for (var i = 0; i < _this.slides.length; i++) {
_this.slides[i].removeAttribute('style');
}
}
// Plugins
_this.callPlugins('onDestroy');

// Check jQuery/Zepto data
if (window.jQuery && window.jQuery(_this.container).data('swiper')) {
window.jQuery(_this.container).removeData('swiper');
}
if (window.Zepto && window.Zepto(_this.container).data('swiper')) {
window.Zepto(_this.container).removeData('swiper');
}

//Destroy variable
_this = null;
};
Expand Down Expand Up @@ -2824,11 +2840,9 @@ if (window.jQuery || window.Zepto) {
var firstInstance;
this.each(function (i) {
var that = $(this);
if (!that.data('swiper')) {
var s = new Swiper(that[0], params);
if (!i) firstInstance = s;
that.data('swiper', s);
}
var s = new Swiper(that[0], params);
if (!i) firstInstance = s;
that.data('swiper', s);
});
return firstInstance;
};
Expand Down

0 comments on commit 970f696

Please sign in to comment.