/*! * cxslide 2.0 * http://code.ciaoca.com/ * https://github.com/ciaoca/cxslide * e-mail: ciaoca@gmail.com * released under the mit license * date: 2015-08-24 */ !function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a(jquery)}(function(a){a.cxslide=function(){var b,c,d,h,i,e={dom:{},api:{}},f=function(a){return a&&("function"==typeof htmlelement||"object"==typeof htmlelement)&&a instanceof htmlelement?!0:a&&a.nodetype&&1===a.nodetype?!0:!1},g=function(a){return a&&a.length&&("function"==typeof jquery||"object"==typeof jquery)&&a instanceof jquery?!0:!1};for(h=0,i=arguments.length;i>h;h++)g(arguments[h])?b=arguments[h]:f(arguments[h])?b=a(arguments[h]):"function"==typeof arguments[h]?d=arguments[h]:"object"==typeof arguments[h]&&(c=arguments[h]);b.length&&(e.init=function(){var e=this;e.dom.el=b,e.settings=a.extend({},a.cxslide.defaults,c),e.build(),e.api={play:function(){e.settings.auto=!0,e.play()},stop:function(){e.settings.auto=!1,e.stop()},"goto":function(){e.goto.apply(e,arguments)},prev:function(){e.goto(e.now-1)},next:function(){e.goto()}},"function"==typeof d&&d(e.api)},e.build=function(){var c,d,b=this;if(b.dom.box=b.dom.el.find(".box"),b.dom.list=b.dom.box.find(".list"),b.dom.items=b.dom.list.find("li"),b.itemsum=b.dom.items.length,!(b.itemsum<=1)){if(b.dom.numlist=b.dom.el.find(".btn"),b.dom.numbtns=b.dom.numlist.find("li"),b.dom.plusbtn=b.dom.el.find(".plus"),b.dom.minusbtn=b.dom.el.find(".minus"),b.boxwidth=b.dom.box.width(),b.boxheight=b.dom.box.height(),b.now=0,b.settings.btn&&!b.dom.numlist.length){for(c="",d=1;d<=b.itemsum;d++)c+='
  • '+d+"
  • ";b.dom.numlist=a("",{"class":"btn",html:c}).appendto(b.dom.el),b.dom.numbtns=b.dom.numlist.find("li")}b.settings.plus&&!b.dom.plusbtn.length&&(b.dom.plusbtn=a("
    ",{"class":"plus"}).appendto(b.dom.el)),b.settings.minus&&!b.dom.minusbtn.length&&(b.dom.minusbtn=a("
    ",{"class":"minus"}).appendto(b.dom.el)),b.dom.box.on("mouseenter",function(){b.stop()}),b.dom.box.on("mouseleave",function(){b.play()}),b.settings.btn&&b.dom.numlist.on(b.settings.events,"li",function(){b.goto(a(this).index())}),b.settings.minus&&b.dom.minusbtn.on(b.settings.events,function(){b.goto(b.now-1)}),b.settings.plus&&b.dom.plusbtn.on(b.settings.events,function(){b.goto()}),b.goto(b.settings.start)}},e.play=function(){var a=this;a.settings.auto&&(a.stop(),a.run=settimeout(function(){a.goto()},a.settings.time))},e.stop=function(){"undefined"!=typeof this.run&&cleartimeout(this.run)},e.goto=function(a){var f,b=this,c="undefined"==typeof a?b.now+1:parseint(a,10),d=b.now,e=b.itemsum-1;if(c>e?c=0:0>c&&(c=e),b.dom.numlist.length&&b.dom.numbtns.removeclass("in out selected"),b.stop(),d===c)return b.dom.numbtns.eq(c).addclass("in selected"),b.dom.items.eq(c).addclass("in"),b.play(),void 0;switch(b.dom.numbtns.eq(d).addclass("out").end().eq(c).addclass("in selected"),b.dom.items.removeclass("in out").eq(d).addclass("out").end().eq(c).addclass("in"),b.settings.type){case"fade":b.dom.items.css({display:"none",position:"absolute",top:0,left:0,zindex:""}),b.dom.items.eq(d).css({display:"",zindex:1}),b.dom.items.eq(c).css({zindex:2}).fadein(b.settings.speed);break;case"toggle":b.dom.items.hide().eq(c).show();break;case"x":f=b.boxwidth*c,0===c&&d===e?(b.dom.items.eq(0).css({left:b.boxwidth*b.itemsum}),f=b.boxwidth*b.itemsum):0===d&&(b.dom.items.eq(0).css({left:""}),b.dom.box.scrollleft(0)),b.dom.box.stop(!0,!1).animate({scrollleft:f},b.settings.speed);break;case"y":f=b.boxheight*c,0===c&&d===e?(b.dom.items.eq(0).css({top:b.boxheight*b.itemsum}),f=b.boxheight*b.itemsum):0===d&&(b.dom.items.eq(0).css({top:""}),b.dom.box.scrolltop(0)),b.dom.box.stop(!0,!1).animate({scrolltop:f},b.settings.speed)}b.now=c,b.dom.box.queue(function(){b.play(),b.dom.box.dequeue()})},e.init())},a.cxslide.defaults={events:"click",type:"x",start:0,speed:800,time:5e3,auto:!0,btn:!0,plus:!1,minus:!1},a.fn.cxslide=function(b,c){return this.each(function(){a.cxslide(this,b,c)}),this}});