Skip to content

Commit

Permalink
Added destroy method..
Browse files Browse the repository at this point in the history
Fixed autoplay bug..
  • Loading branch information
sachinchoolur committed Oct 27, 2015
1 parent 5867234 commit 05d67bc
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 30 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lightslider",
"version": "1.1.3",
"version": "1.1.4",
"homepage": "https://github.com/sachinchoolur/lightslider",
"authors": [
"Sachin N <[email protected]>"
Expand Down
4 changes: 2 additions & 2 deletions dist/css/lightslider.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! lightslider - v1.1.3 - 2015-07-18
/*! lightslider - v1.1.4 - 2015-10-27
* https://github.com/sachinchoolur/lightslider
* Copyright (c) 2015 Sachin N; Licensed MIT */
/*! lightslider - v1.1.3 - 2015-04-14
Expand Down Expand Up @@ -159,7 +159,7 @@
background-image: url('../img/controls.png');
cursor: pointer;
position: absolute;
z-index: 9999;
z-index: 99;
margin-top: -16px;
opacity: 0.5;
-webkit-transition: opacity 0.35s linear 0s;
Expand Down
2 changes: 1 addition & 1 deletion dist/css/lightslider.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 53 additions & 11 deletions dist/js/lightslider.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! lightslider - v1.1.3 - 2015-07-18
/*! lightslider - v1.1.4 - 2015-10-27
* https://github.com/sachinchoolur/lightslider
* Copyright (c) 2015 Sachin N; Licensed MIT */
(function ($, undefined) {
Expand All @@ -15,6 +15,7 @@
easing: 'linear', //'for jquery animation',//
speed: 400, //ms'
auto: false,
pauseOnHover: false,
loop: false,
slideEndAnimation: true,
pause: 2000,
Expand Down Expand Up @@ -175,10 +176,8 @@
}
if (e.keyCode === 37) {
$el.goToPrevSlide();
clearInterval(interval);
} else if (e.keyCode === 39) {
$el.goToNextSlide();
clearInterval(interval);
}
}
});
Expand Down Expand Up @@ -207,7 +206,6 @@
} else {
$el.goToNextSlide();
}
clearInterval(interval);
return false;
});
}
Expand Down Expand Up @@ -411,7 +409,6 @@
if (settings.gallery === true) {
$this.slideThumb();
}
clearInterval(interval);
return false;
});
};
Expand Down Expand Up @@ -647,12 +644,28 @@
},
auto: function () {
if (settings.auto) {
clearInterval(interval);
interval = setInterval(function () {
$el.goToNextSlide();
}, settings.pause);
}
},

pauseOnHover: function(){
var $this = this;
if (settings.auto && settings.pauseOnHover) {
$slide.on('mouseenter', function(){
$(this).addClass('ls-hover');
$el.pause();
settings.auto = true;
});
$slide.on('mouseleave',function(){
$(this).removeClass('ls-hover');
if (!$slide.find('.lightSlider').hasClass('lsGrabbing')) {
$this.auto();
}
});
}
},
touchMove: function (endCoords, startCoords) {
$slide.css('transition-duration', '0ms');
if (settings.mode === 'slide') {
Expand All @@ -679,7 +692,6 @@

touchEnd: function (distance) {
$slide.css('transition-duration', settings.speed + 'ms');
clearInterval(interval);
if (settings.mode === 'slide') {
var mxVal = false;
var _next = true;
Expand Down Expand Up @@ -865,6 +877,7 @@
}
}
$this.pager();
$this.pauseOnHover();
$this.controls();
$this.keyPress();
}
Expand Down Expand Up @@ -1025,6 +1038,9 @@
} else {
plugin.fade();
}
if (!$slide.hasClass('ls-hover')) {
plugin.auto();
}
setTimeout(function () {
if (!_touch) {
settings.onAfterSlide.call(this, $el, scene);
Expand All @@ -1033,13 +1049,12 @@
on = true;
};
$el.play = function () {
clearInterval(interval);
$el.goToNextSlide();
interval = setInterval(function () {
$el.goToNextSlide();
}, settings.pause);
settings.auto = true;
plugin.auto();
};
$el.pause = function () {
settings.auto = false;
clearInterval(interval);
};
$el.refresh = function () {
Expand Down Expand Up @@ -1074,6 +1089,33 @@
plugin.slideThumb();
}
};
$el.destroy = function () {
if ($el.lightSlider) {
$el.goToPrevSlide = function(){};
$el.goToNextSlide = function(){};
$el.mode = function(){};
$el.play = function(){};
$el.pause = function(){};
$el.refresh = function(){};
$el.getCurrentSlideCount = function(){};
$el.getTotalSlideCount = function(){};
$el.goToSlide = function(){};
$el.lightSlider = null;

This comment has been minimized.

Copy link
@nicotsou

nicotsou Nov 4, 2015

I noticed you remove the reference to lightSlider. After we call the destroy method now we can't reinitialize the plugin because is says lightSlider is not defined. What is the best way to initialize the plugin after we destroy it?

refresh = {
init : function(){}
};
$el.parent().parent().find('.lSAction, .lSPager').remove();
$el.removeClass('lightSlider lSFade lSSlide lsGrab lsGrabbing leftEnd right').removeAttr('style').unwrap().unwrap();
$el.children().removeAttr('style');
$children.removeClass('lslide active');
$el.find('.clone').remove();
$children = null;
interval = null;
on = false;
scene = 0;
}

};
setTimeout(function () {
settings.onSliderLoad.call(this, $el);
}, 10);
Expand Down
Loading

0 comments on commit 05d67bc

Please sign in to comment.