Created
May 3, 2011 08:35
-
-
Save thinkphp/953011 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var FancySlide=new Class({initialize:function(params){this.items=params.items;this.startItem=params.startItem||0;this.mode=params.mode||"horizontal";this.modes={horizontal:["left","width"],vertical:["top","height"]};this.size=params.size||300;this.box=params.box.setStyle(this.modes[this.mode][1],(this.size*this.items.length)+"px");this.button_event=params.button_event||"click";this.handle_event=params.handle_event||"click";this.onWalk=params.onWalk||null;this.currentIndex=null;this.nextIndex=null;this.previousIndex=null;this.interval=params.interval||4000;this.autoPlay=params.autoPlay||false;this._play=null;this.handles=params.handles||null;if(this.handles){this.addActionHandles(this.handles)}this.buttons={next:[],previous:[],play:[],stop:[],playback:[]};if(params.addButtons){for(action in params.addButtons){this.addActionButtons(action,$type(params.addButtons[action])=="array"?params.addButtons[action]:[params.addButtons[action]])}}var prop=this.modes[this.mode][0];this.fx=new Fx.Tween(this.box,Object.merge(params.fxOptions||{duration:500,wait:false},{property:prop}));this.walk(this.startItem||0,true,true)},addActionButtons:function(action,buttons){for(var i=0,j=buttons.length;i<j;i++){switch(action){case"next":buttons[i].addEvent(this.button_event,function(event){if(event){event.stop()}return this.next(true)}.bind(this));break;case"previous":buttons[i].addEvent(this.button_event,function(event){if(event){event.stop()}return this.previous(true)}.bind(this));break;case"stop":buttons[i].addEvent(this.button_event,function(event){if(event){event.stop()}return this.stop()}.bind(this));break;case"play":buttons[i].addEvent(this.button_event,this.play.bind(this,[this.interval,"next",false]));break}this.buttons[action].push(buttons[i])}},addActionHandles:function(handles){for(var i=0,j=handles.length;i<j;i++){handles[i].addEvent(this.handle_event,this.walk.pass([i,true],this))}},next:function(manual){if(this.autoPlay){this.autoPlay=false}this.walk((this.currentIndex<this.items.length-1?this.currentIndex+1:0),manual)},previous:function(manual){if(this.autoPlay){this.autoPlay=false}this.walk((this.currentIndex>0?this.currentIndex-1:this.items.length-1),manual)},stop:function(){$clear(this._play)},walk:function(item,manual,noFx){if(item!=this.currentIndex){this.currentIndex=item;this.nextIndex=this.currentIndex+(this.currentIndex<this.items.length-1?1:1-this.items.length);this.previousIndex=this.curentIndex+(this.currentIndex>0?-1:this.items.length-1);if(manual){this.stop()}if(noFx){this.fx.cancel().set(-this.size*this.currentIndex+"px")}else{this.fx.cancel();this.fx.start(this.size*-this.currentIndex)}if(manual&&this.autoPlay){this.play(this.interval,"next",true)}if(this.onWalk){this.onWalk((this.items[this.curentIndex]||null),(this.handles&&this.handles[this.currentIndex])?this.handles[this.currentIndex]:null)}}},play:function(interval,direction,wait){this.stop();if(!wait){this[direction](false)}this._play=this[direction].periodical(interval,this,[false])}}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment