(function ($, undefined) {
'use strict';
var defaults = {
item: 3,
autowidth: false,
slidemove: 1,
slidemargin: 10,
addclass: '',
mode: 'slide',
usecss: true,
csseasing: 'ease', //'cubic-bezier(0.25, 0, 0.25, 1)',
easing: 'linear', //'for jquery animation',//
speed: 400, //ms'
auto: false,
pauseonhover: false,
loop: false,
slideendanimation: true,
pause: 2000,
keypress: false,
controls: true,
prevhtml: '',
nexthtml: '',
rtl: false,
adaptiveheight: false,
vertical: false,
verticalheight: 500,
vthumbwidth: 100,
thumbitem: 10,
pager: true,
gallery: false,
gallerymargin: 5,
thumbmargin: 5,
currentpagerposition: 'middle',
enabletouch: true,
enabledrag: true,
freemove: true,
swipethreshold: 40,
responsive: [],
/* jshint ignore:start */
onbeforestart: function ($el) {},
onsliderload: function ($el) {},
onbeforeslide: function ($el, scene) {},
onafterslide: function ($el, scene) {},
onbeforenextslide: function ($el, scene) {},
onbeforeprevslide: function ($el, scene) {}
/* jshint ignore:end */
};
$.fn.lightslider = function (options) {
if (this.length === 0) {
return this;
}
if (this.length > 1) {
this.each(function () {
$(this).lightslider(options);
});
return this;
}
var plugin = {},
settings = $.extend(true, {}, defaults, options),
settingstemp = {},
$el = this;
plugin.$el = this;
if (settings.mode === 'fade') {
settings.vertical = false;
}
var $children = $el.children(),
windoww = $(window).width(),
breakpoint = null,
resposiveobj = null,
length = 0,
w = 0,
on = false,
elsize = 0,
$slide = '',
scene = 0,
property = (settings.vertical === true) ? 'height' : 'width',
gutter = (settings.vertical === true) ? 'margin-bottom' : 'margin-right',
slidevalue = 0,
pagerwidth = 0,
slidewidth = 0,
thumbwidth = 0,
interval = null,
istouch = ('ontouchstart' in document.documentelement);
var refresh = {};
refresh.chbreakpoint = function () {
windoww = $(window).width();
if (settings.responsive.length) {
var item;
if (settings.autowidth === false) {
item = settings.item;
}
if (windoww < settings.responsive[0].breakpoint) {
for (var i = 0; i < settings.responsive.length; i++) {
if (windoww < settings.responsive[i].breakpoint) {
breakpoint = settings.responsive[i].breakpoint;
resposiveobj = settings.responsive[i];
}
}
}
if (typeof resposiveobj !== 'undefined' && resposiveobj !== null) {
for (var j in resposiveobj.settings) {
if (resposiveobj.settings.hasownproperty(j)) {
if (typeof settingstemp[j] === 'undefined' || settingstemp[j] === null) {
settingstemp[j] = settings[j];
}
settings[j] = resposiveobj.settings[j];
}
}
}
if (!$.isemptyobject(settingstemp) && windoww > settings.responsive[0].breakpoint) {
for (var k in settingstemp) {
if (settingstemp.hasownproperty(k)) {
settings[k] = settingstemp[k];
}
}
}
if (settings.autowidth === false) {
if (slidevalue > 0 && slidewidth > 0) {
if (item !== settings.item) {
scene = math.round(slidevalue / ((slidewidth + settings.slidemargin) * settings.slidemove));
}
}
}
}
};
refresh.calsw = function () {
if (settings.autowidth === false) {
slidewidth = (elsize - ((settings.item * (settings.slidemargin)) - settings.slidemargin)) / settings.item;
}
};
refresh.calwidth = function (cln) {
var ln = cln === true ? $slide.find('.lslide').length : $children.length;
if (settings.autowidth === false) {
w = ln * (slidewidth + settings.slidemargin);
} else {
w = 0;
for (var i = 0; i < ln; i++) {
w += (parseint($children.eq(i).width()) + settings.slidemargin);
}
}
return w;
};
plugin = {
docss: function () {
var support = function () {
var transition = ['transition', 'moztransition', 'webkittransition', 'otransition', 'mstransition', 'khtmltransition'];
var root = document.documentelement;
for (var i = 0; i < transition.length; i++) {
if (transition[i] in root.style) {
return true;
}
}
};
if (settings.usecss && support()) {
return true;
}
return false;
},
keypress: function () {
if (settings.keypress) {
$(document).on('keyup.lightslider', function (e) {
if (!$(':focus').is('input, textarea')) {
if (e.preventdefault) {
e.preventdefault();
} else {
e.returnvalue = false;
}
if (e.keycode === 37) {
$el.gotoprevslide();
} else if (e.keycode === 39) {
$el.gotonextslide();
}
}
});
}
},
controls: function () {
if (settings.controls) {
/* $el.after('
');*/
if (!settings.autowidth) {
if (length <= settings.item) {
$slide.find('.lsaction').hide();
}
} else {
if (refresh.calwidth(false) < elsize) {
$slide.find('.lsaction').hide();
}
}
$slide.parents('.item').find('.lsaction a').on('click', function (e) {
if (e.preventdefault) {
e.preventdefault();
} else {
e.returnvalue = false;
}
if ($(this).attr('class') === 'lsprev') {
$el.gotoprevslide();
} else {
$el.gotonextslide();
}
return false;
});
}
},
initialstyle: function () {
var $this = this;
if (settings.mode === 'fade') {
settings.autowidth = false;
settings.slideendanimation = false;
}
if (settings.auto) {
settings.slideendanimation = false;
}
if (settings.autowidth) {
settings.slidemove = 1;
settings.item = 1;
}
if (settings.loop) {
settings.slidemove = 1;
settings.freemove = false;
}
settings.onbeforestart.call(this, $el);
refresh.chbreakpoint();
$el.addclass('lightslider').wrap('');
$slide = $el.parent('.lsslidewrapper');
if (settings.rtl === true) {
$slide.parent().addclass('lsrtl');
}
if (settings.vertical) {
$slide.parent().addclass('vertical');
elsize = settings.verticalheight;
$slide.css('height', elsize + 'px');
} else {
elsize = $el.outerwidth();
}
$children.addclass('lslide');
if (settings.loop === true && settings.mode === 'slide') {
refresh.calsw();
refresh.clone = function () {
if (refresh.calwidth(true) > elsize) {
/**/
var twr = 0,
ti = 0;
for (var k = 0; k < $children.length; k++) {
twr += (parseint($el.find('.lslide').eq(k).width()) + settings.slidemargin);
ti++;
if (twr >= (elsize + settings.slidemargin)) {
break;
}
}
var titem = settings.autowidth === true ? ti : settings.item;
/**/
if (titem < $el.find('.clone.left').length) {
for (var i = 0; i < $el.find('.clone.left').length - titem; i++) {
$children.eq(i).remove();
}
}
if (titem < $el.find('.clone.right').length) {
for (var j = $children.length - 1; j > ($children.length - 1 - $el.find('.clone.right').length); j--) {
scene--;
$children.eq(j).remove();
}
}
/**/
for (var n = $el.find('.clone.right').length; n < titem; n++) {
$el.find('.lslide').eq(n).clone().removeclass('lslide').addclass('clone right').appendto($el);
scene++;
}
for (var m = $el.find('.lslide').length - $el.find('.clone.left').length; m > ($el.find('.lslide').length - titem); m--) {
$el.find('.lslide').eq(m - 1).clone().removeclass('lslide').addclass('clone left').prependto($el);
}
$children = $el.children();
} else {
if ($children.hasclass('clone')) {
$el.find('.clone').remove();
$this.move($el, 0);
}
}
};
refresh.clone();
}
refresh.ssw = function () {
length = $children.length;
if (settings.rtl === true && settings.vertical === false) {
gutter = 'margin-left';
}
if (settings.autowidth === false) {
$children.css(property, slidewidth + 'px');
}
$children.css(gutter, settings.slidemargin + 'px');
w = refresh.calwidth(false);
$el.css(property, w + 'px');
if (settings.loop === true && settings.mode === 'slide') {
if (on === false) {
scene = $el.find('.clone.left').length;
}
}
};
refresh.call = function () {
$children = $el.children();
length = $children.length;
};
if (this.docss()) {
$slide.addclass('usingcss');
}
refresh.call();
if (settings.mode === 'slide') {
refresh.calsw();
refresh.ssw();
if (settings.loop === true) {
slidevalue = $this.slidevalue();
this.move($el, slidevalue);
}
if (settings.vertical === false) {
this.setheight($el, false);
}
} else {
this.setheight($el, true);
$el.addclass('lsfade');
if (!this.docss()) {
$children.fadeout(0);
$children.eq(scene).fadein(0);
}
}
if (settings.loop === true && settings.mode === 'slide') {
$children.eq(scene).addclass('active');
} else {
$children.first().addclass('active');
}
},
pager: function () {
var $this = this;
refresh.createpager = function () {
thumbwidth = (elsize - ((settings.thumbitem * (settings.thumbmargin)) - settings.thumbmargin)) / settings.thumbitem;
var $children = $slide.find('.lslide');
var length = $slide.find('.lslide').length;
var i = 0,
pagers = '',
v = 0;
for (i = 0; i < length; i++) {
if (settings.mode === 'slide') {
// calculate scene * slide value
if (!settings.autowidth) {
v = i * ((slidewidth + settings.slidemargin) * settings.slidemove);
} else {
v += ((parseint($children.eq(i).width()) + settings.slidemargin) * settings.slidemove);
}
}
var thumb = $children.eq(i * settings.slidemove).attr('data-thumb');
if (settings.gallery === true) {
pagers += '';
} else {
pagers += '' + (i + 1) + '';
}
if (settings.mode === 'slide') {
if ((v) >= w - elsize - settings.slidemargin) {
i = i + 1;
var minpgr = 2;
if (settings.autowidth) {
pagers += '' + (i + 1) + '';
minpgr = 1;
}
if (i < minpgr) {
pagers = null;
$slide.parent().addclass('nopager');
} else {
$slide.parent().removeclass('nopager');
}
break;
}
}
}
var $csouter = $slide.parent();
$csouter.find('.lspager').html(pagers);
if (settings.gallery === true) {
if (settings.vertical === true) {
// set gallery thumbnail width
$csouter.find('.lspager').css('width', settings.vthumbwidth + 'px');
}
pagerwidth = (i * (settings.thumbmargin + thumbwidth)) + 0.5;
$csouter.find('.lspager').css({
property: pagerwidth + 'px',
'transition-duration': settings.speed + 'ms'
});
if (settings.vertical === true) {
$slide.parent().css('padding-right', (settings.vthumbwidth + settings.gallerymargin) + 'px');
}
$csouter.find('.lspager').css(property, pagerwidth + 'px');
}
var $pager = $csouter.find('.lspager').find('li');
$pager.first().addclass('active');
$pager.on('click', function () {
if (settings.loop === true && settings.mode === 'slide') {
scene = scene + ($pager.index(this) - $csouter.find('.lspager').find('li.active').index());
} else {
scene = $pager.index(this);
}
$el.mode(false);
if (settings.gallery === true) {
$this.slidethumb();
}
return false;
});
};
if (settings.pager) {
var cl = 'lspg';
if (settings.gallery) {
cl = 'lsgallery';
}
$slide.after('');
var gmargin = (settings.vertical) ? 'margin-left' : 'margin-top';
$slide.parent().find('.lspager').css(gmargin, settings.gallerymargin + 'px');
refresh.createpager();
}
settimeout(function () {
refresh.init();
}, 0);
},
setheight: function (ob, fade) {
var obj = null,
$this = this;
if (settings.loop) {
obj = ob.children('.lslide ').first();
} else {
obj = ob.children().first();
}
var setcss = function () {
var th = obj.outerheight(),
tp = 0,
tht = th;
if (fade) {
th = 0;
tp = ((tht) * 100) / elsize;
}
ob.css({
'height': th + 'px',
'padding-bottom': tp + '%'
});
};
setcss();
if (obj.find('img').length) {
if ( obj.find('img')[0].complete) {
setcss();
if (!interval) {
$this.auto();
}
}else{
obj.find('img').load(function () {
settimeout(function () {
setcss();
if (!interval) {
$this.auto();
}
}, 100);
});
}
}else{
if (!interval) {
$this.auto();
}
}
},
active: function (ob, t) {
if (this.docss() && settings.mode === 'fade') {
$slide.addclass('on');
}
var sc = 0;
if (scene * settings.slidemove < length) {
ob.removeclass('active');
if (!this.docss() && settings.mode === 'fade' && t === false) {
ob.fadeout(settings.speed);
}
if (t === true) {
sc = scene;
} else {
sc = scene * settings.slidemove;
}
//t === true ? sc = scene : sc = scene * settings.slidemove;
var l, nl;
if (t === true) {
l = ob.length;
nl = l - 1;
if (sc + 1 >= l) {
sc = nl;
}
}
if (settings.loop === true && settings.mode === 'slide') {
//t === true ? sc = scene - $el.find('.clone.left').length : sc = scene * settings.slidemove;
if (t === true) {
sc = scene - $el.find('.clone.left').length;
} else {
sc = scene * settings.slidemove;
}
if (t === true) {
l = ob.length;
nl = l - 1;
if (sc + 1 === l) {
sc = nl;
} else if (sc + 1 > l) {
sc = 0;
}
}
}
if (!this.docss() && settings.mode === 'fade' && t === false) {
ob.eq(sc).fadein(settings.speed);
}
ob.eq(sc).addclass('active');
} else {
ob.removeclass('active');
ob.eq(ob.length - 1).addclass('active');
if (!this.docss() && settings.mode === 'fade' && t === false) {
ob.fadeout(settings.speed);
ob.eq(sc).fadein(settings.speed);
}
}
},
move: function (ob, v) {
if (settings.rtl === true) {
v = -v;
}
if (this.docss()) {
if (settings.vertical === true) {
ob.css({
'transform': 'translate3d(0px, ' + (-v) + 'px, 0px)',
'-webkit-transform': 'translate3d(0px, ' + (-v) + 'px, 0px)'
});
} else {
ob.css({
'transform': 'translate3d(' + (-v) + 'px, 0px, 0px)',
'-webkit-transform': 'translate3d(' + (-v) + 'px, 0px, 0px)',
});
}
} else {
if (settings.vertical === true) {
ob.css('position', 'relative').animate({
top: -v + 'px'
}, settings.speed, settings.easing);
} else {
ob.css('position', 'relative').animate({
left: -v + 'px'
}, settings.speed, settings.easing);
}
}
var $thumb = $slide.parent().find('.lspager').find('li');
this.active($thumb, true);
},
fade: function () {
this.active($children, false);
var $thumb = $slide.parent().find('.lspager').find('li');
this.active($thumb, true);
},
slide: function () {
var $this = this;
refresh.calslide = function () {
if (w > elsize) {
slidevalue = $this.slidevalue();
$this.active($children, false);
if ((slidevalue) > w - elsize - settings.slidemargin) {
slidevalue = w - elsize - settings.slidemargin;
} else if (slidevalue < 0) {
slidevalue = 0;
}
$this.move($el, slidevalue);
if (settings.loop === true && settings.mode === 'slide') {
if (scene >= (length - ($el.find('.clone.left').length / settings.slidemove))) {
$this.resetslide($el.find('.clone.left').length);
}
if (scene === 0) {
$this.resetslide($slide.find('.lslide').length);
}
}
}
};
refresh.calslide();
},
resetslide: function (s) {
var $this = this;
$slide.find('.lsaction a').addclass('disabled');
settimeout(function () {
scene = s;
$slide.css('transition-duration', '0ms');
slidevalue = $this.slidevalue();
$this.active($children, false);
plugin.move($el, slidevalue);
settimeout(function () {
$slide.css('transition-duration', settings.speed + 'ms');
$slide.find('.lsaction a').removeclass('disabled');
}, 50);
}, settings.speed + 100);
},
slidevalue: function () {
var _sv = 0;
if (settings.autowidth === false) {
_sv = scene * ((slidewidth + settings.slidemargin) * settings.slidemove);
} else {
_sv = 0;
for (var i = 0; i < scene; i++) {
_sv += (parseint($children.eq(i).width()) + settings.slidemargin);
}
}
return _sv;
},
slidethumb: function () {
var position;
switch (settings.currentpagerposition) {
case 'left':
position = 0;
break;
case 'middle':
position = (elsize / 2) - (thumbwidth / 2);
break;
case 'right':
position = elsize - thumbwidth;
}
var sc = scene - $el.find('.clone.left').length;
var $pager = $slide.parent().find('.lspager');
if (settings.mode === 'slide' && settings.loop === true) {
if (sc >= $pager.children().length) {
sc = 0;
} else if (sc < 0) {
sc = $pager.children().length;
}
}
var thumbslide = sc * ((thumbwidth + settings.thumbmargin)) - (position);
if ((thumbslide + elsize) > pagerwidth) {
thumbslide = pagerwidth - elsize - settings.thumbmargin;
}
if (thumbslide < 0) {
thumbslide = 0;
}
this.move($pager, thumbslide);
},
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') {
var distance = endcoords - startcoords;
var swipeval = slidevalue - distance;
if ((swipeval) >= w - elsize - settings.slidemargin) {
if (settings.freemove === false) {
swipeval = w - elsize - settings.slidemargin;
} else {
var swipevalt = w - elsize - settings.slidemargin;
swipeval = swipevalt + ((swipeval - swipevalt) / 5);
}
} else if (swipeval < 0) {
if (settings.freemove === false) {
swipeval = 0;
} else {
swipeval = swipeval / 5;
}
}
this.move($el, swipeval);
}
},
touchend: function (distance) {
$slide.css('transition-duration', settings.speed + 'ms');
if (settings.mode === 'slide') {
var mxval = false;
var _next = true;
slidevalue = slidevalue - distance;
if ((slidevalue) > w - elsize - settings.slidemargin) {
slidevalue = w - elsize - settings.slidemargin;
if (settings.autowidth === false) {
mxval = true;
}
} else if (slidevalue < 0) {
slidevalue = 0;
}
var gc = function (next) {
var ad = 0;
if (!mxval) {
if (next) {
ad = 1;
}
}
if (!settings.autowidth) {
var num = slidevalue / ((slidewidth + settings.slidemargin) * settings.slidemove);
scene = parseint(num) + ad;
if (slidevalue >= (w - elsize - settings.slidemargin)) {
if (num % 1 !== 0) {
scene++;
}
}
} else {
var tw = 0;
for (var i = 0; i < $children.length; i++) {
tw += (parseint($children.eq(i).width()) + settings.slidemargin);
scene = i + ad;
if (tw >= slidevalue) {
break;
}
}
}
};
if (distance >= settings.swipethreshold) {
gc(false);
_next = false;
} else if (distance <= -settings.swipethreshold) {
gc(true);
_next = false;
}
$el.mode(_next);
this.slidethumb();
} else {
if (distance >= settings.swipethreshold) {
$el.gotoprevslide();
} else if (distance <= -settings.swipethreshold) {
$el.gotonextslide();
}
}
},
enabledrag: function () {
var $this = this;
if (!istouch) {
var startcoords = 0,
endcoords = 0,
isdraging = false;
$slide.find('.lightslider').addclass('lsgrab');
$slide.on('mousedown', function (e) {
if (w < elsize) {
if (w !== 0) {
return false;
}
}
if ($(e.target).attr('class') !== ('lsprev') && $(e.target).attr('class') !== ('lsnext')) {
startcoords = (settings.vertical === true) ? e.pagey : e.pagex;
isdraging = true;
if (e.preventdefault) {
e.preventdefault();
} else {
e.returnvalue = false;
}
// ** fix for webkit cursor issue https://code.google.com/p/chromium/issues/detail?id=26723
$slide.scrollleft += 1;
$slide.scrollleft -= 1;
// *
$slide.find('.lightslider').removeclass('lsgrab').addclass('lsgrabbing');
clearinterval(interval);
}
});
$(window).on('mousemove', function (e) {
if (isdraging) {
endcoords = (settings.vertical === true) ? e.pagey : e.pagex;
$this.touchmove(endcoords, startcoords);
}
});
$(window).on('mouseup', function (e) {
if (isdraging) {
$slide.find('.lightslider').removeclass('lsgrabbing').addclass('lsgrab');
isdraging = false;
endcoords = (settings.vertical === true) ? e.pagey : e.pagex;
var distance = endcoords - startcoords;
if (math.abs(distance) >= settings.swipethreshold) {
$(window).on('click.ls', function (e) {
if (e.preventdefault) {
e.preventdefault();
} else {
e.returnvalue = false;
}
e.stopimmediatepropagation();
e.stoppropagation();
$(window).off('click.ls');
});
}
$this.touchend(distance);
}
});
}
},
enabletouch: function () {
var $this = this;
if (istouch) {
var startcoords = {},
endcoords = {};
$slide.on('touchstart', function (e) {
endcoords = e.originalevent.targettouches[0];
startcoords.pagex = e.originalevent.targettouches[0].pagex;
startcoords.pagey = e.originalevent.targettouches[0].pagey;
clearinterval(interval);
});
$slide.on('touchmove', function (e) {
if (w < elsize) {
if (w !== 0) {
return false;
}
}
var orig = e.originalevent;
endcoords = orig.targettouches[0];
var xmovement = math.abs(endcoords.pagex - startcoords.pagex);
var ymovement = math.abs(endcoords.pagey - startcoords.pagey);
if (settings.vertical === true) {
if ((ymovement * 3) > xmovement) {
e.preventdefault();
}
$this.touchmove(endcoords.pagey, startcoords.pagey);
} else {
if ((xmovement * 3) > ymovement) {
e.preventdefault();
}
$this.touchmove(endcoords.pagex, startcoords.pagex);
}
});
$slide.on('touchend', function () {
if (w < elsize) {
if (w !== 0) {
return false;
}
}
var distance;
if (settings.vertical === true) {
distance = endcoords.pagey - startcoords.pagey;
} else {
distance = endcoords.pagex - startcoords.pagex;
}
$this.touchend(distance);
});
}
},
build: function () {
var $this = this;
$this.initialstyle();
if (this.docss()) {
if (settings.enabletouch === true) {
$this.enabletouch();
}
if (settings.enabledrag === true) {
$this.enabledrag();
}
}
$(window).on('focus', function(){
$this.auto();
});
$(window).on('blur', function(){
clearinterval(interval);
});
$this.pager();
$this.pauseonhover();
$this.controls();
$this.keypress();
}
};
plugin.build();
refresh.init = function () {
refresh.chbreakpoint();
if (settings.vertical === true) {
if (settings.item > 1) {
elsize = settings.verticalheight;
} else {
elsize = $children.outerheight();
}
$slide.css('height', elsize + 'px');
} else {
elsize = $slide.outerwidth();
}
if (settings.loop === true && settings.mode === 'slide') {
refresh.clone();
}
refresh.call();
if (settings.mode === 'slide') {
$el.removeclass('lsslide');
}
if (settings.mode === 'slide') {
refresh.calsw();
refresh.ssw();
}
settimeout(function () {
if (settings.mode === 'slide') {
$el.addclass('lsslide');
}
}, 1000);
if (settings.pager) {
refresh.createpager();
}
if (settings.adaptiveheight === true && settings.vertical === false) {
$el.css('height', $children.eq(scene).outerheight(true));
}
if (settings.adaptiveheight === false) {
if (settings.mode === 'slide') {
if (settings.vertical === false) {
plugin.setheight($el, false);
}else{
plugin.auto();
}
} else {
plugin.setheight($el, true);
}
}
if (settings.gallery === true) {
plugin.slidethumb();
}
if (settings.mode === 'slide') {
plugin.slide();
}
if (settings.autowidth === false) {
if ($children.length <= settings.item) {
$slide.find('.lsaction').hide();
} else {
$slide.find('.lsaction').show();
}
} else {
if ((refresh.calwidth(false) < elsize) && (w !== 0)) {
$slide.find('.lsaction').hide();
} else {
$slide.find('.lsaction').show();
}
}
};
$el.gotoprevslide = function () {
if (scene > 0) {
settings.onbeforeprevslide.call(this, $el, scene);
scene--;
$el.mode(false);
if (settings.gallery === true) {
plugin.slidethumb();
}
} else {
if (settings.loop === true) {
settings.onbeforeprevslide.call(this, $el, scene);
if (settings.mode === 'fade') {
var l = (length - 1);
scene = parseint(l / settings.slidemove);
}
$el.mode(false);
if (settings.gallery === true) {
plugin.slidethumb();
}
} else if (settings.slideendanimation === true) {
$el.addclass('leftend');
settimeout(function () {
$el.removeclass('leftend');
}, 400);
}
}
};
$el.gotonextslide = function () {
var nexti = true;
if (settings.mode === 'slide') {
var _slidevalue = plugin.slidevalue();
nexti = _slidevalue < w - elsize - settings.slidemargin;
}
if (((scene * settings.slidemove) < length - settings.slidemove) && nexti) {
settings.onbeforenextslide.call(this, $el, scene);
scene++;
$el.mode(false);
if (settings.gallery === true) {
plugin.slidethumb();
}
} else {
if (settings.loop === true) {
settings.onbeforenextslide.call(this, $el, scene);
scene = 0;
$el.mode(false);
if (settings.gallery === true) {
plugin.slidethumb();
}
} else if (settings.slideendanimation === true) {
$el.addclass('rightend');
settimeout(function () {
$el.removeclass('rightend');
}, 400);
}
}
};
$el.mode = function (_touch) {
if (settings.adaptiveheight === true && settings.vertical === false) {
$el.css('height', $children.eq(scene).outerheight(true));
}
if (on === false) {
if (settings.mode === 'slide') {
if (plugin.docss()) {
$el.addclass('lsslide');
if (settings.speed !== '') {
$slide.css('transition-duration', settings.speed + 'ms');
}
if (settings.csseasing !== '') {
$slide.css('transition-timing-function', settings.csseasing);
}
}
} else {
if (plugin.docss()) {
if (settings.speed !== '') {
$el.css('transition-duration', settings.speed + 'ms');
}
if (settings.csseasing !== '') {
$el.css('transition-timing-function', settings.csseasing);
}
}
}
}
if (!_touch) {
settings.onbeforeslide.call(this, $el, scene);
}
if (settings.mode === 'slide') {
plugin.slide();
} else {
plugin.fade();
}
if (!$slide.hasclass('ls-hover')) {
plugin.auto();
}
settimeout(function () {
if (!_touch) {
settings.onafterslide.call(this, $el, scene);
}
}, settings.speed);
on = true;
};
$el.play = function () {
$el.gotonextslide();
settings.auto = true;
plugin.auto();
};
$el.pause = function () {
settings.auto = false;
clearinterval(interval);
};
$el.refresh = function () {
refresh.init();
};
$el.getcurrentslidecount = function () {
var sc = scene;
if (settings.loop) {
var ln = $slide.find('.lslide').length,
cl = $el.find('.clone.left').length;
if (scene <= cl - 1) {
sc = ln + (scene - cl);
} else if (scene >= (ln + cl)) {
sc = scene - ln - cl;
} else {
sc = scene - cl;
}
}
return sc + 1;
};
$el.gettotalslidecount = function () {
return $slide.find('.lslide').length;
};
$el.gotoslide = function (s) {
if (settings.loop) {
scene = (s + $el.find('.clone.left').length - 1);
} else {
scene = s;
}
$el.mode(false);
if (settings.gallery === true) {
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;
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);
$(window).on('resize orientationchange', function (e) {
settimeout(function () {
if (e.preventdefault) {
e.preventdefault();
} else {
e.returnvalue = false;
}
refresh.init();
}, 200);
});
return this;
};
}(jquery));