tradeIndex.js
7.6 KB
/*! dili 2016-01-06 */
define("droll",function(require,exports,module){var droll=function(target,options){this.autoTimer=null,this.target=target,this.opt={step:null,moveNum:null,Media:!1,eventType:"click",isHori:!0,index:0,auto:!1,effect:"1",autoDelay:5e3,speed:500,fadeSpeed:400,dirButton:!0,indexButton:!1,showNum:!0,isCycle:!0,relaBtns:null,listCurClass:"pdo-droll_list_current",ibtnCurClass:"pdo-droll_btn_current",lockedClass:"pdo-droll_btn_locked",prevHtml:"<",nextHtml:">",loop:!0,outerSelector:"ul",itemsSelector:"li",btnHoverActive:!1,onFinished:function(target,inview_elems){},onBeforeInView:function(target,inview_elems){},layoutWidth:null,layoutHeight:null},$.extend(this.opt,options),this.LENGTH=0,this.LOCKED=!1,this.I=this.opt.index,this.PREVI=this.opt.index,this.init()};return droll.prototype={init:function(){var _this=this;if(this.LENGTH=$(this.target).find(this.opt.outerSelector).find(this.opt.itemsSelector).length,this.LENGTH<=this.opt.moveNum&&(this.opt.loop=!1),this.printWrapper(),this.setParams(),this.bindEvents(),this.setListState(),this.setDirBtnState(),this.setIndexBtnState(this.opt.index),this.LENGTH<=this.opt.moveNum&&!this.opt.Media)return void this.opt.onBeforeInView.call(this.target,$(this.target).find(this.opt.outerSelector).find(this.opt.itemsSelector));if(0!==this.opt.index?this.move():this.opt.onBeforeInView.call(this.target,this.getInViewList()),2==this.opt.effect&&($(this.target).find(this.opt.itemsSelector).each(function(){$(this).css({left:0,top:0,position:"absolute"}).hide()}),this.move()),this.opt.auto&&(this.auto(),$(this.target).hover(function(){clearTimeout(_this.autoTimer)},function(){_this.auto()})),this.opt.Media){var _itemsSelector=$(_this.target).find(_this.opt.outerSelector).find(_this.opt.itemsSelector),_ml=parseFloat($(_itemsSelector).css("marginLeft")),_mr=parseFloat($(_itemsSelector).css("marginRight"));$(window).resize(function(){_this.opt.step=parseFloat($(_itemsSelector).outerWidth())+_ml+_mr,$(_this.target).find(".pdo-droll_layout , .pdo-droll").css({width:_this.opt.step*_this.opt.moveNum}),_this.setParams(),_this.move(1*_this.opt.moveNum)})}},printWrapper:function(){var numlists="",elem=$(this.target),style=this.opt.isHori?"width: "+(this.opt.layoutWidth||this.opt.step*this.opt.moveNum)+"px; height: "+(this.opt.layoutHeight||$(this.target).outerHeight())+"px;":"height: "+(this.opt.layoutHeight||this.opt.step*this.opt.moveNum)+"px; width: "+(this.opt.layoutWidth||$(this.target).outerWidth())+"px;";2==this.opt.effect&&(style="width:100%;height:100%;");for(var i=0;i<this.LENGTH/this.opt.moveNum;i++){var _i=this.opt.showNum?i+1:" ";numlists+='<a href="javascript:void(0);">'+_i+"</a>"}elem.find(this.opt.outerSelector).wrap('<div style="'+style+'z-index:1;" class="pdo-droll"></div>'),elem.find(".pdo-droll").wrap('<div style="'+style+'" class="pdo-droll_layout"></div>'),this.LENGTH>this.opt.moveNum&&elem.find(".pdo-droll_layout").append(' <div class="pdo-droll_dirbutton" style="display:none;"> <a class="pdo-droll_prev" href="javascript:void(0);"><span><span></a> <a class="pdo-droll_next" href="javascript:void(0);"><span><span></a> </div> <div class="pdo-droll_numbutton" style="display:none;">'+numlists+"</div> ")},setParams:function(){var elem=$(this.target);this.ELEM={outer:elem.find("pdo-droll"),cont:elem.find(this.opt.outerSelector),dirbtn:elem.find("div.pdo-droll_dirbutton"),numbtn:elem.find("div.pdo-droll_numbutton"),prev:elem.find("a.pdo-droll_prev"),next:elem.find("a.pdo-droll_next")},this.opt.dirButton&&!this.opt.btnHoverActive&&this.ELEM.dirbtn.fadeIn(200),this.opt.indexButton&&this.LENGTH>this.opt.moveNum&&this.ELEM.numbtn.fadeIn(200);var size=this.opt.step*this.ELEM.cont.find(this.opt.itemsSelector).length;2==this.opt.effect&&(size="100%"),this.ELEM.cont[this.opt.isHori?"width":"height"](size).css("position","absolute")},bindEvents:function(){var _this=this;this.ELEM.prev.click(function(){_this.move(-1*_this.opt.moveNum)}),this.ELEM.next.click(function(){_this.move(1*_this.opt.moveNum)}),this.opt.btnHoverActive&&(this.target.ha_stimer=null,this.target.ha_htimer=null,$(this.target).hover(function(){clearTimeout(_this.target.ha_stimer),clearTimeout(_this.target.ha_htimer),_this.target.ha_stimer=setTimeout(function(){_this.ELEM.dirbtn.fadeIn(120)},100)},function(){clearTimeout(_this.target.ha_stimer),clearTimeout(_this.target.ha_htimer),_this.target.ha_htimer=setTimeout(function(){_this.ELEM.dirbtn.fadeOut(120)},100)}),this.ELEM.dirbtn.mouseover(function(){clearTimeout(_this.target.ha_stimer),clearTimeout(_this.target.ha_htimer)})),this.ELEM.numbtn.find("a")[this.opt.eventType](function(){_this.move($(this).index()*_this.opt.moveNum-_this.I)}),this.opt.relaBtns&&this.opt.relaBtns[this.opt.eventType](function(){var orgBtns=_this.ELEM.numbtn.find("a").eq($(this).index());orgBtns.triggerHandler(_this.opt.eventType)})},move:function(move_num,cur_ibtn_index){if(!(this.LENGTH<=this.opt.moveNum||1==this.opt.effect&&this.LOCKED)){this.LOCKED=!0;var _this=this,gs=this.getStep(move_num,cur_ibtn_index),step=1==this.opt.effect?gs.step:gs.toindex;if(1==this.opt.effect&&null===gs.step)return void(this.LOCKED=!1);if(this.opt.onBeforeInView.call(this.target,this.getInViewList()),this.setListState(),this.setDirBtnState(),this.setIndexBtnState(Math.abs(gs.toindex)),1==this.opt.effect){var move_config={};move_config[this.opt.isHori?"left":"top"]=step,this.ELEM.cont.animate(move_config,this.opt.speed,function(){_this.LOCKED=!1,_this.opt.onFinished.call(_this.target,_this.getInViewList())})}if(2==this.opt.effect){var items=$(this.target).find(this.opt.itemsSelector);items.eq(gs.toindex).siblings().fadeOut(100),items.eq(gs.toindex).fadeIn(this.opt.fadeSpeed,function(){_this.opt.onFinished.call(_this.target,_this.getInViewList())})}}},getStep:function(move_num){var cycle=this.opt.isCycle;if(void 0==move_num)return this.I=0,{toindex:0,step:null};var range=[0,this.LENGTH-this.opt.moveNum],to_index=move_num+this.I;return to_index>range[1]&&(to_index=this.opt.loop?to_index<this.LENGTH?range[1]:cycle?0:range[1]:range[1]),to_index<range[0]&&(this.opt.loop?to_index+this.LENGTH>range[1]?to_index=0:cycle?to_index+=this.LENGTH:to_index=0:to_index=0),this.I=to_index,{toindex:to_index,step:to_index*this.opt.step*-1}},auto:function(){clearTimeout(this.autoTimer);var _this=this;this.autoTimer=setTimeout(function(){_this.move(1*_this.opt.moveNum),_this.auto()},this.opt.autoDelay)},getInViewList:function(){for(var arr=[],i=this.I;i<this.I+this.opt.moveNum;i++)arr.push(this.ELEM.cont.find(this.opt.itemsSelector).eq(i)[0]);return arr},setListState:function(){},setDirBtnState:function(){this.opt.loop||(this.ELEM.prev.removeClass(this.opt.lockedClass),this.ELEM.next.removeClass(this.opt.lockedClass),this.I<=0&&this.ELEM.prev.addClass(this.opt.lockedClass),this.I>=this.LENGTH-this.opt.moveNum&&this.ELEM.next.addClass(this.opt.lockedClass))},setIndexBtnState:function(index){this.opt.loop;var realIndex=Math.round(index/this.opt.moveNum),orgBtns=this.ELEM.numbtn.find("a");orgBtns.removeClass(this.opt.ibtnCurClass),orgBtns.eq(realIndex).addClass(this.opt.ibtnCurClass),this.opt.relaBtns&&(this.opt.relaBtns.removeClass(this.opt.ibtnCurClass),this.opt.relaBtns.eq(realIndex).addClass(this.opt.ibtnCurClass))}},droll}),define(function(require,exports,module){var _Droll=require("droll");$(function(){$(".promo-inner").length&&$(".promo-inner").each(function(){new _Droll(this,{step:590,moveNum:1,auto:!0,indexButton:!0,btnHoverActive:!0,Media:!0})}),$(".trade-inner").length&&$(".trade-inner").each(function(){new _Droll(this,{step:250,moveNum:1,indexButton:!0,btnHoverActive:!0,Media:!0})})})});