-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneomoogal.js
356 lines (342 loc) · 9.9 KB
/
neomoogal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
/*
Script: neomoogal.js
MooTools simple gallery
License:
LGPL.
Version:
0.1
Copyright:
Copyright (c) 2009 [Carlos Bolaños](http://wocp.net).
Dependencies:
- MooTools Core 1.2.3 (http://mootools.net)
Todo:
- Add events (onFinish,onSlide,etc...)
Inspiration:
- Multiple flash gals
- Default icons Tango iconset (http://tango.freedesktop.org/)
Options:
- resx: (integer) Width of the view area
- resy: (integer) Height of the view area
- gal: ($() object) div to inject gallery
- source: ($() object) Source of a elements with info
- seconds: (integer) Seconds between slides
- cicle: (boolean) slideshow repeat?
- dataPath: (string) path to icons
- fade: (boolean) enable fading between images
- buttons: (boolean) enable bottom toolbar
Events:
- TODO
Notes:
- Tested on ie6, ie7, ie8, ff3.5.1, safari4.0.2, o9.64
*/
var NeoMooGal = new Class({
options: {
resx: 384,
resy: 384,
gal: null,
source: null,
imgs: [],
process: [],
current: 0,
dataPath: '',
seconds: 10,
cycle: false,
fade: true,
buttons: true,
legend: true,
theme: {
legend:'white',
legendBackground:'#7a8a85',
imgBackground:'#222',
buttons:'white',
buttonsBackground:'black'
}
},
loading: null,
loadingIndex:-1,
playing:false,
initialize: function(options) {
this.options = $merge(this.options,options)
},
goTo: function() {
gal.scan()
gal.createDefault()
gal.goToPage(0)
gal.hideSource()
},
__f1:function() {
if(this.playing) {
this.timerImg = this.div.clone()
this.timerImg.empty()
this.div.adopt(this.timerImg)
this.timerImg.setStyle('background','url('+this.options.dataPath+'timer1.gif) right bottom no-repeat')
this.timerImg.setStyle('position','absolute')
}
},
__f2: function() {
if(this.playing)
this.timerImg.setStyle('backgroundImage','url('+this.options.dataPath+'timer2.gif)')
},
__f3: function() {
if(this.playing)
this.timerImg.setStyle('backgroundImage','url('+this.options.dataPath+'timer3.gif)')
},
__f4: function() {
if(this.playing) {
this.timerImg.dispose()
this.onNext({stop:function(){}})
this.goPlay()
}
},
__f5: function() {
if(this.playing) {
this.timerImg.dispose()
this.goToPage(0)
this.goPlay()
}
},
goPlay:function(force) {
if(this.loading)
this.goPlay.bind(this).delay(500)
else
if(this.options.current<this.options.process.length-1) {
if(this.playPauseButton)
this.playPauseButton.setStyle('backgroundImage','url('+this.options.dataPath+'playback-pause.png)')
this.playing = true;
var quatter = this.options.seconds*1000/4
this.__f1.bind(this).delay(quatter)
this.__f2.bind(this).delay(quatter*2)
this.__f3.bind(this).delay(quatter*3)
this.__f4.bind(this).delay(quatter*4)
} else if(this.options.cycle||force) {
if(this.playPauseButton)
this.playPauseButton.setStyle('backgroundImage','url('+this.options.dataPath+'playback-pause.png)')
this.playing = true;
var quatter = this.options.seconds*1000/4
this.__f1.bind(this).delay(quatter)
this.__f2.bind(this).delay(quatter*2)
this.__f3.bind(this).delay(quatter*3)
this.__f5.bind(this).delay(quatter*4)
} else {
this.playing = false
if(this.playPauseButton)
this.playPauseButton.setStyle('backgroundImage','url('+this.options.dataPath+'playback-start.png)')
}
},
scan:function() {
this.options.process =
this.options.source.getElements('a').map(function(i) {
return [i.get('href'),i.get('text')]
})
},
goToPage:function(index) {
this.div.empty()
if(this.loading) {
this.loading.dispose()
} else {
this.loadingImg = this.div.clone()
this.loadingImg.setStyle('backgroundColor','transparent')
this.div.adopt(this.loadingImg)
this.loadingImg.setStyle('backgroundImage','url('+this.options.dataPath+'loading.gif)')
}
this.loadingIndex = index
this.loading = new Element('img', {
events: {
load:this.onLoadImage.bind(this)
}
})
this.loading.set('src',this.options.process[index][0])
},
hideSource: function() {
this.options.source.setStyle('display','none')
},
createDefault: function() {
var opts = this.options
var div = opts.gal
div.empty()
div.setStyles({
width:opts.resx
})
if(opts.legend)
div.adopt(
this.legend = new Element('p', {
text: 'loading',
styles: {
fontSize:'1.1em',
margin:0,
padding:'0.3em 0.3em 0.1em 0.3em',
overflow:'hidden',
height:'1.2em',
backgroundColor:opts.theme.legendBackground,
color:opts.theme.legend
}
})
)
div.adopt(
this.div = new Element('div', {
styles: {
width:opts.resx,
height:opts.resy,
background:opts.theme.imgBackground+' url('+opts.dataPath+'loading.gif) center no-repeat'
}
})
)
var _this = this
this.aes = opts.process.map(function(el,i) {
var str = (i+1)+''
if(str.length<2)
str = '0'+str
return [new Element('a',{
href:'#',
text:str,
styles:{
color:opts.theme.buttons
},
events: {
click:_this.onPage.bind(_this)
}
}),new Element('text',{text:' '})]
})
if(opts.buttons) {
var tds = [
new Element('td').adopt( new Element('a', {
href:'#',
styles: {
display:'block', width:16, height:16,
background:'url('+this.options.dataPath+'skip-backward.png) center'
},
events: {
click:this.onIni.bind(this)
}
})),
new Element('td').adopt( new Element('a', {
href:'#',
styles: {
display:'block', width:16, height:16,
background:'url('+this.options.dataPath+'seek-backward.png) center'
},
events: {
click:this.onPrevious.bind(this)
}
})),
this.pages = new Element('td', {
href:'#',
styles: {
width:'100%',
textAlign:'center',
fontSize:'0.8em'
}
}).adopt(this.aes.flatten()),
new Element('td').adopt( new Element('a', {
href:'#',
styles: {
display:'block', width:16, height:16,
background:'url('+this.options.dataPath+'seek-forward.png) center'
},
events: {
click:this.onNext.bind(this)
}
})),
new Element('td').adopt( new Element('a', {
href:'#',
styles: {
display:'block', width:16, height:16,
background:'url('+this.options.dataPath+'skip-forward.png) center'
},
events: {
click:this.onEnd.bind(this)
}
})),
new Element('td').adopt( this.playPauseButton = new Element('a', {
href:'#',
styles: {
display:'block', width:16, height:16,
background:'url('+this.options.dataPath+'playback-start.png) center'
},
events: {
click:this.onPlayPause.bind(this)
}
}))
]
var todo =
new Element('tr', {
// fuck IE ;)
// styles: { verticalAlign: 'center' }
}).adopt(tds)
div.adopt(
new Element('table', {
styles: {
backgroundColor:opts.theme.buttonsBackground,
color:opts.theme.buttons,
width:'100%'
}
}).adopt(
new Element('tbody').adopt(todo)
)
)
}
},
onPage: function(event) {
event.stop()
var as = this.pages.getElements('a')
this.goToPage(as.indexOf(event.target))
},
onIni:function(event) {
event.stop()
this.goToPage(0)
},
onPrevious:function(event) {
event.stop()
if(this.options.current>0)
this.goToPage(this.options.current-1)
},
onNext:function(event) {
event.stop()
if(this.options.current<this.options.process.length-1)
this.goToPage(this.options.current+1)
},
onEnd:function(event) {
event.stop()
this.goToPage(this.options.process.length-1)
},
onPlayPause:function(event) {
event.stop()
if(this.playing) {
this.playing = false
this.playPauseButton.setStyle('backgroundImage','url('+this.options.dataPath+'playback-start.png)')
} else {
this.goPlay(true)
}
},
onLoadImage:function(event) {
var opts = this.options
var index = this.loadingIndex
var kk = this.options.process[index][0]
if(opts.fade) {
this.loadingImg.setStyle('backgroundColor',this.div.getStyle('backgroundColor'))
this.loadingImg.setStyle('backgroundImage',this.div.getStyle('backgroundImage'))
}
this.div.setStyle('backgroundImage','url('+kk+')')
if(this.legend)
this.legend.set('text',opts.process[index][1])
if(opts.buttons) {
var as = this.pages.getElements('a')
as.each(function(el,i) {
if(i==index)
el.setStyle('textDecoration','none')
else
el.setStyle('textDecoration','underline')
})
}
opts.current = index
if(opts.fade) {
this.loadingImg.fade(0).get('tween').chain(this.onEndFade.bind(this))
} else {
this.onEndFade()
}
},
onEndFade:function() {
this.loadingImg.dispose()
this.loading = null
}
})