_class.noobSlide.js
Go to the documentation of this file.
1 /*
2 Author:
3  luistar15, <leo020588 [at] gmail.com>
4  with modifications by Stephen Lau <stevel [at] songbirdnest.com>
5 License:
6  MIT License
7 
8 Class
9  noobSlide (rev.19-06-08)
10 
11 Arguments:
12  Parameters - see Parameters below
13 
14 Parameters:
15  box: dom element | required
16  items: dom collection | required
17  size: int | item size (px) | default: 240
18  mode: string | 'horizontal', 'vertical' | default: 'horizontal'
19  addButtons:{
20  previous: single dom element OR dom collection| default: null
21  next: single dom element OR dom collection | default: null
22  play: single dom element OR dom collection | default: null
23  playback: single dom element OR dom collection | default: null
24  stop: single dom element OR dom collection | default: null
25  }
26  button_event: string | event type | default: 'click'
27  handles: dom collection | default: null
28  handle_event: string | event type| default: 'click'
29  fxOptions: object | Fx.Tween options | default: {duration:500,wait:false}
30  interval: int | for periodical | default: 5000
31  autoPlay: boolean | default: false
32  onWalk: event | pass arguments: currentItem, currentHandle | default: null
33  startItem: int | default: 0
34 
35 Properties:
36  box: dom element
37  items: dom collection
38  size: int
39  mode: string
40  buttons: object
41  button_event: string
42  handles: dom collection
43  handle_event: string
44  previousIndex: int
45  nextIndex: int
46  fx: Fx.Tween instance
47  interval: int
48  autoPlay: boolean
49  onWalk: function
50 
51 Methods:
52  previous(manual): walk to previous item
53  manual: bolean | default:false
54  next(manual): walk to next item
55  manual: bolean | default:false
56  play (interval,direction,wait): auto walk items
57  interval: int | required
58  direction: string | "previous" or "next" | required
59  wait: boolean | required
60  stop(): stop auto walk
61  walk(item,manual,noFx): walk to item
62  item: int | required
63  manual: bolean | default:false
64  noFx: boolean | default:false
65  addHandleButtons(handles):
66  handles: dom collection | required
67  addActionButtons(action,buttons):
68  action: string | "previous", "next", "play", "playback", "stop" | required
69  buttons: dom collection | required
70 
71 Requires:
72  mootools 1.2 core
73 */
74 var noobSlide = new Class({
75 
76  initialize: function(params){
77  this.items = params.items;
78  this.mode = params.mode || 'horizontal';
79  this.modes = {horizontal:['left','width'], vertical:['top','height']};
80  this.size = params.size || 240;
81  this.box = params.box.setStyle(this.modes[this.mode][1],(this.size*this.items.length)+'px');
82  this.button_event = params.button_event || 'click';
83  this.handle_event = params.handle_event || 'click';
84  this.onButtons = params.onButtons || null;
85  this.onWalk = params.onWalk || null;
86  this.currentIndex = null;
87  this.previousIndex = null;
88  this.nextIndex = null;
89  this.interval = params.interval || 5000;
90  this.autoPlay = params.autoPlay || false;
91  this._play = null;
92  this.handles = params.handles || null;
93  if(this.handles){
94  this.addHandleButtons(this.handles);
95  }
96  this.buttons = {
97  previous: [],
98  next: [],
99  play: [],
100  playback: [],
101  stop: [],
102  playpause: []
103  };
104  if(params.addButtons){
105  for(var action in params.addButtons){
106  this.addActionButtons(action, $type(params.addButtons[action])=='array' ? params.addButtons[action] : [params.addButtons[action]]);
107  }
108  }
109  this.fx = new Fx.Tween(this.box,$extend((params.fxOptions||{duration:500,wait:false}),{property:this.modes[this.mode][0]}));
110  this.walk((params.startItem||0),true,true);
111  },
112 
113  addHandleButtons: function(handles){
114  for(var i=0;i<handles.length;i++){
115  handles[i].addEvent(this.handle_event,this.walk.bind(this,[i,true]));
116  }
117  },
118 
119  addActionButtons: function(action,buttons){
120  for(var i=0; i<buttons.length; i++){
121  switch(action){
122  case 'previous': buttons[i].addEvent(this.button_event,this.previous.bind(this,[true])); break;
123  case 'next': buttons[i].addEvent(this.button_event,this.next.bind(this,[true])); break;
124  case 'play': buttons[i].addEvent(this.button_event,this.play.bind(this,[this.interval,'next',false])); break;
125  case 'playback': buttons[i].addEvent(this.button_event,this.play.bind(this,[this.interval,'previous',false])); break;
126  case 'stop': buttons[i].addEvent(this.button_event,this.stop.bind(this)); break;
127  case 'playpause': buttons[i].addEvent(this.button_event,this.playpause.bind(this,[this.interval,'next'])); break;
128  }
129  this.buttons[action].push(buttons[i]);
130  }
131  },
132 
133  cleanup: function() {
134  for (var commands in this.buttons) {
135  for (var button in commands) {
136  button.removeEvents();
137  }
138  }
139  },
140 
141  previous: function(manual){
142  this.walk((this.currentIndex>0 ? this.currentIndex-1 : this.items.length-1),false);
143  },
144 
145  next: function(manual){
146  this.walk((this.currentIndex<this.items.length-1 ? this.currentIndex+1 : 0),false);
147  },
148 
149  play: function(interval,direction,wait){
150  this.isPlaying = true;
151  this.stop();
152  if(!wait){
153  this[direction](false);
154  }
155  this._play = this[direction].periodical(interval,this,[false]);
156  },
157 
158  playpause: function(interval,direction) {
159  if (this.isPlaying) {
160  $clear(this._play);
161  this.isPlaying = false;
162  } else {
163  this._play = this[direction].periodical(interval,this,[false]);
164  this.isPlaying = true;
165  }
166 
167  if (this.onButtons) {
168  this.onButtons("playpause", this.isPlaying);
169  }
170  },
171 
172  stop: function(){
173  $clear(this._play);
174  },
175 
176  gotoSlide: function(index) {
177  //dump("proceeding to slide: " + index);
178  this.walk(index, true, true);
179  },
180 
181  walk: function(item,manual,noFx){
182  if(item!=this.currentIndex){
183  this.currentIndex=item;
184  if (this.currentIndex < 0)
185  this.currentIndex = 0;
186  //dump("> advancing track:" + this.items[this.currentIndex].title + "\n");
187  this.previousIndex = this.currentIndex + (this.currentIndex>0 ? -1 : this.items.length-1);
188  this.nextIndex = this.currentIndex + (this.currentIndex<this.items.length-1 ? 1 : 1-this.items.length);
189  if(manual){
190  this.stop();
191  }
192  if(noFx){
193  this.fx.cancel().set((this.size*-this.currentIndex)+'px');
194  }else{
195  this.fx.start(0-this.items[this.currentIndex].el.offsetLeft);
196  }
197  if(manual && this.autoPlay){
198  this.play(this.interval,'next',true);
199  }
200  if(this.onWalk){
201  this.onWalk((this.items[this.currentIndex] || null), (this.handles && this.handles[this.currentIndex] ? this.handles[this.currentIndex] : null));
202  }
203  }
204  }
205 
206 });
function Fx prototype initialize
function stop(ch, cx, status, data)
_hideDatepicker duration
function $type(A)
return null
Definition: FeedWriter.js:1143
var Fx
var Class
function cleanup()
function $clear(A)
var noobSlide
function $extend(C, A)
_getSelectedPageStyle s i
function next()