;(function($){
$.extend({
isarray: function(v) {
return object.prototype.tostring.call(v) === '[object array]';
},
isobject: function(v) {
return object.prototype.tostring.call(v) === '[object object]';
}
});
var sliderevent = function(val) {
this.$ele = $(val);
this.param = this.$ele.data('lzslider-param');
this.status = this.$ele.data('lzslider-status');
this.imgbox = this.$ele.data('lzslider-imgbox');
this.img = this.$ele.data('lzslider-img');
}
sliderevent.prototype.setevent = function() {
var event = this,
param = this.param;
if ($.isarray(param.event)) {
$.each(param.event,function(index, val) {
event[val] && event[val]();
});
} else {
event[param.event] && event[param.event]();
}
}
sliderevent.prototype.wheel = function(){
var me = this.$ele,
status = this.status,
param = this.param;
me.off('mousewheel.lzslider dommousescroll.lzslider').on('mousewheel.lzslider dommousescroll.lzslider',function(e){
if(status.flag && status.mouseh){
e.preventdefault();
var delta = (e.originalevent.wheeldelta && (e.originalevent.wheeldelta > 0 ? 1 : -1)) || // chrome & ie
(e.originalevent.detail && (e.originalevent.detail > 0 ? -1 : 1)); // firefox
if(delta>0) status.cpoint-=param.num;
if(delta<0) status.cpoint+=param.num;
me.sliderexcute();
}
})
}
sliderevent.prototype.keyboard = function(){
var me = this.$ele,
status = this.status,
param = this.param;
$(window).on('keydown',function(e){
if(status.flag && status.mouseh){
e.preventdefault();
if(e.keycode == 37 || e.keycode ==38) status.cpoint-=param.num;
if(e.keycode ==39 || e.keycode==40) status.cpoint+=param.num;
me.sliderexcute();
}
})
}
sliderevent.prototype.btn = function() {
var me = this.$ele,
param = this.param,
status = this.status,
imgbox = this.imgbox,
img = this.img,
imglen = status.imglen,
btnw = 0,
boxlen = (param.dir=='left' || param.dir=='right')?status.imgw:status.imgh;
var pointbox = $("
");
me.append(pointbox.get(0));
pointinbox = $("");
pointbox.append(pointinbox.get(0));
point = "";
for (i = 0; i");
me.append(arrowbox.get(0));
if (param.arrowstyle) {
arrowp = "<>";
} else {
arrowp = "";
}
arrowbox.append(arrowp);
arrowbox.find('li').eq(0).off('.lzslider').on('click.lzslider',function(e) {
if (status.flag) {
status.cpoint-=param.num;
me.sliderexcute();
}
});
arrowbox.find('li').eq(1).off('.lzslider').on('click.lzslider',function(e) {
if (status.flag) {
status.cpoint+=param.num;
me.sliderexcute();
}
});
}
sliderevent.prototype.touch = function(){
var startpoint={},endpoint={},
me = this.$ele,
param = this.param,
status = this.status,
imglen = status.imglen;
me.on('touchstart', function(e) {
e.preventdefault();
e.stoppropagation();
var touchstart = e.originalevent.touches[0];
startpoint.x = math.floor(touchstart.clientx);
startpoint.y = math.floor(touchstart.clienty);
timer = settimeout(function(){
startpoint = {};
endpoint = {};
},1000)
});
me.on('touchmove', function(e) {
e.preventdefault();
e.stoppropagation();
var touchend = e.originalevent.touches[0];
endpoint.x = math.floor(touchend.clientx);
endpoint.y = math.floor(touchend.clienty);
});
me.on('touchend', function(e) {
e.preventdefault();
e.stoppropagation();
var dir = param.dir;
if((dir ==='left' || dir==='right') && status.flag && startpoint.x){
(startpoint.x-endpoint.x<-30) && (status.cpoint -=param.num);
(startpoint.x-endpoint.x>30) && (status.cpoint +=param.num);
me.sliderexcute();
}else if((dir==='up' || dir ==='down') && status.flag && startpoint.y){
startpoint.y-endpoint.y<-30 && (status.cpoint -=param.num);
startpoint.y-endpoint.y>30 && (status.cpoint +=param.num);
me.sliderexcute();
}
startpoint = {};
endpoint = {};
});
}
var slidermethods = function(val){
this.$ele = $(val);
this.status = this.$ele.data('lzslider-status');
this.param = this.$ele.data('lzslider-param');
this.imgbox = this.$ele.data('lzslider-imgbox');
this.img = this.$ele.data('lzslider-img');
}
slidermethods.prototype.calboxlen = function(){
var me = this.$ele,
param = this.param,
status = this.status,
img = this.img,
temp = 0,
k = 0;
status.arrlen = [0];
if(param.dir =='left' || param.dir =='right')
$.each(img,function(index,val){
temp+=$(val).outerwidth(true);
status.arrlen.push(temp);
});
else
$.each(img,function(index,val){
temp+=$(val).outerheight(true);
status.arrlen.push(temp);
});
status.boxlen = (param.dir=='left' || param.dir=='right') ? parsefloat(me.css('width')) : parsefloat(me.css('height'));
while(status.arrlen[k++]<=temp-status.boxlen) status.lastlen = k;
return temp;
}
slidermethods.prototype.autoplay = function(){
var me = this.$ele,
status = this.status,
param = this.param;
if(status.flag){
(param.dir =='left' || param.dir=='up')? (status.cpoint+=param.num) : (status.cpoint-=param.num);
me.sliderexcute();
}
}
slidermethods.prototype.indexchange = function(){
var status = this.status,
param = this.param,
imglen = status.lastlen;
(!param.cycle && status.cpoint>imglen - 1) && (status.cpoint = imglen - 1);
(!param.cycle && status.cpoint<0) && (status.cpoint=0);
(param.cycle && status.sponit!=imglen - 1 && status.cpoint>imglen - 1) && (status.cpoint = imglen - 1);
(param.cycle && status.sponit==imglen - 1 && status.cpoint>imglen - 1) && (status.cpoint = 0);
(param.cycle && status.sponit!=0 && status.cpoint<0) && (status.cpoint=0);
(param.cycle && status.sponit==0 && status.cpoint<0) && (status.cpoint=imglen - 1);
}
slidermethods.prototype.calmovelen = function(){
var status = this.status;
return status.arrlen[status.cpoint];
}
slidermethods.prototype.excute = function(){
var status = this.status,
param = this.param,
imgbox = this.imgbox,
len = this.calmovelen(),
pointbox = this.$ele.find('.'+param.btncls[0]).find('div');
if(pointbox) pointbox.removeclass(param.btncls[3]).eq(status.cpoint).addclass(param.btncls[3]);
(param.dir == 'left' || param.dir == 'right') && imgbox.stop().animate({'marginleft':-len},param.speed);
(param.dir == 'up' || param.dir == 'down') && imgbox.stop().animate({'margintop':-len},param.speed);
status.sponit = status.cpoint;
}
slidermethods.prototype.onprogress = function(){
var progress = this,
status = this.status,
param = this.param;
progress.indexchange();
progress.excute();
if(status.cpoint == status.lastlen - 1 && param._onlast) param._onlast.call(this,param,status);
param._onswitch && param._onswitch.call(this,param,status);
status.flag = false;
settimeout(function(){
status.flag = true;
},param.speed);
}
var sliderinit = function(val,a,b,c,d){
this.$ele = $(val);
this.$ele.data('lzslider-param',this.initparam(a,b,c,d));
this.$ele.data('lzslider-imgbox',this.$ele.children().first());
this.$ele.data('lzslider-img',this.$ele.data('lzslider-imgbox').children());
this.$ele.data('lzslider-status',{
flag:true,
mouseh:false,
sponit:0,
cpoint:0,
arrlen:[],
boxlen:0,
imglen:this.$ele.data('lzslider-img').length,
lastlen:0,
timer:null
})
}
sliderinit.prototype.layout = function(){
var me = this.$ele,
status = me.data('lzslider-status'),
param = me.data('lzslider-param'),
imgbox = me.data('lzslider-imgbox');
len = me.get(0).sliderexcute.calboxlen();
me.css('position')=='static' && me.css('position','relative');
(param.dir=='left' || param.dir =='right')? imgbox.css('width',len):imgbox.css('height',len);
}
sliderinit.prototype.initevent = function(){
var me = this.$ele,
self = me.get(0),
status = me.data('lzslider-status'),
param = me.data('lzslider-param'),
imgbox = me.data('lzslider-imgbox'),
event = new sliderevent(me);
me.off('.lzslider');
me.on('mouseover.lzslider', function() {
clearinterval(status.timer);
status.timer = null;
status.mouseh = true;
}).on('mouseout.lzslider', function() {
param.auto && (status.timer = setinterval(self.sliderexcute.autoplay.bind(self.sliderexcute),param.interval));
status.mouseh = false;
});
event.setevent();
param.auto && (status.timer = setinterval(self.sliderexcute.autoplay.bind(self.sliderexcute),param.interval));
}
sliderinit.prototype.initparam = function(a,b,c,d){
var param = {
dir:'left',
speed:600,
interval:3000,
event:['arrow'],
auto:true,
cycle:true,
num:1,
btncls: ['lz-sliderpoint-box','lz-sliderpoint','lz-sliderpoint-point','lz-sliderpoint-hover'],
arrowcls:['lz-sliderbtn','lz-sliderbtn-left','lz-sliderbtn-right'],
arrowstyle:true,
_onswitch:null,
_onlast:null
}
if($.isobject(a)){
param = $.extend({},param,a);
}else{
param.dir = a;
param.interval = b;
param.speed = c;
param.auto = d;
!isnan(a) && (param.interval = a, param.speed = b);
typeof a === 'function' && (param._onswitch = a);
typeof a ==='boolean' && (param.auto = a);
}
if(this.$ele.data('slider-param')){
$.extend({},param,this.$ele.data('slider-param'));
}
param.dir = (param.dir == 'left' || param.dir == 'right' || param.dir == 'up' || param.dir == 'down') ? param.dir: 'left';
param.speed = (param.speed == null) ? 600 : param.speed;
param.interval = (param.interval == null) ? 3000 : param.interval;
param.interval == 'fast' && (param.interval = 1500, param.speed = 300);
param.interval == 'medium' && (param.interval = 3000, param.speed = 600);
param.interval == 'slow' && (param.interval = 6000, param.speed = 1200);
(isnan(param.interval) || isnan(param.speed)) && (param.interval = 3000, param.speed = 600);
(param.interval < param.speed) && jquery.error('参数设置错误 动画间隔小于动画速度');
param.auto = (param.auto === false) ? false: true;
param.cycle = (param.cycle === false) ? false: true;
param.arrowstyle = (param.arrowstyle === false) ? false: true;
typeof param._onswitch !=='function' && (param._onswitch = null);
typeof param._onlast !=='function' && (param._onlast=null);
return param;
}
var tool = function(val){
this.$ele = $(val);
}
tool.prototype.destory = function(){
var me = this.$ele;
$.each(me,function(index,val){
var self = $(val),
status = self.data('lzslider-status'),
param = self.data('lzslider-param');
if(status.timer) clearinterval(status.timer);
self.off('lzslider')
if(btn=self.find(param.btncls[0])) btn.remove();
if(arrow=self.find(param.arrowcls[0])) arrow.remove();
self.removedata('lzslider-status').removedata('lzslider-param');
});
return false;
}
tool.prototype.refresh = function(){
var me = this.$ele,
self = me.get(0),
status = me.data('lzslider-status'),
param = me.data('lzslider-param'),
imgbox = me.data('lzslider-imgbox');
var len = self.sliderexcute.calboxlen(),
marginlen = self.sliderexcute.calmovelen();
(param.dir=='left' || param.dir =='right')? imgbox.css('width',len):imgbox.css('height',len);
(param.dir=='left' || param.dir =='right')? imgbox.css('marginleft',-marginlen):imgbox.css('margintop',-marginlen);
}
tool.prototype.init = function(a,b,c,d){
var me = this.$ele;
this.destory();
me.lzbanner(a,b,c,d);
}
tool.prototype.index = function(num){
var me = this.$ele,
self = this;
if(num===undefined){
return me.eq(0).data('lzslider-status').sponit+1;
}else{
$.each(me,function(index,val){
self.stop();
var status = $(val).data('lzslider-status'),
param = $(val).data('lzslider-param');
if(status.flag){
status.cpoint = num-1;
$(val).sliderexcute();
}
param.auto && self.start();
})
return this;
}
}
tool.prototype.next = function(){
var self = this,
me = this.$ele;
$.each(me,function(index,val){
self.stop();
var status = $(val).data('lzslider-status'),
param = $(val).data('lzslider-param');
if(status.flag){
status.cpoint+=param.num;
$(val).sliderexcute();
}
param.auto && self.start();
})
return this;
}
tool.prototype.prev = function(){
var self = this,
me = this.$ele;
$.each(me,function(index,val){
self.stop();
var status = $(val).data('lzslider-status'),
param = $(val).data('lzslider-param');
if(status.flag){
status.cpoint-=param.num;
$(val).sliderexcute();
}
param.auto && self.start();
})
return this;
}
tool.prototype.setinterval = function(num){
var me = this.$ele,
self = this;
$.each(me,function(index,val){
self.stop();
var param = $(val).data('lzslider-param');
num>param.speed && (param.interval = ~~num);
param.auto && self.start();
})
return this;
}
tool.prototype.setspeed = function(num){
var me = this.$ele;
$.each(me,function(index,val){
var param = $(val).data('lzslider-param');
num