-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlightbox.js
More file actions
423 lines (364 loc) · 9.25 KB
/
lightbox.js
File metadata and controls
423 lines (364 loc) · 9.25 KB
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
//
// Firebox
//
// Copyright 2011 alimsky@oggettoweb.com
//
// https://github.com/alimsky/FireBox/
//
// What is LOVE? Baby don't hurt me.
// Don't hurt me... No more.
// ______ _ ____ _ __ __
//| ____(_) | _ \ | /_ /_ |
//| |__ _ _ __ ___| |_) | _____ _| || || |
//| __| | | '__/ _ \ _ < / _ \ \/ / || || |
//| | | | | | __/ |_) | (_) > <|_|| || |
//|_| |_|_| \___|____/ \___/_/\_(_)|_||_|
//
//
var merge = function (a, b, m) {
"use strict";
var aa; //iterator
for (aa in b) {
if (m) {
if (b.hasOwnProperty(aa) && !a.hasOwnProperty(aa)) {
a[aa] = b[aa];
}
} else {
if (b.hasOwnProperty(aa) && a.hasOwnProperty(aa)) {
a[aa] = b[aa];
}
}
}
return a;
};
var lightboxMaster = function(op) {
var h = { },
dO = { // isn't it clear? d is default, and O is Options
fadeClassName:'oggetto-lightbox-fade',
fadeLoaderClassName:'oggetto-lightbox-loader',
dontCloseOnEsc: false, // observe ESC button to autoclose LB (L is Light and B is Box)
noFade:false,
appearOptions:{ duration:0.4, to:0.5 },
hideOptions:{ duration:0.4 }
};
h.ol=0;
//init options
h.op = op || { };
h.op = merge(h.op, dO, true);
h.go = function () { // Get option
return h.op;
};
h.so = function(on, ov) { //Set option
if (h.op.hasOwnProperty(on)) {
h.op[on] = ov;
}
};
if (!h.op.noFade && !$('x78432berg3fader')) {
ddiv = document.createElement('div');
ddiv.style.display='none';
ddiv.id="x78432berg3fader";
ddiv.className = 'oggetto-lightbox-fade ' + h.op.fadeClassName;
h.fa = $(document.body.appendChild(ddiv));
ddiv = document.createElement('div');
ddiv.style.display='none';
ddiv.id="x78432berg3loader";
ddiv.className = 'oggetto-lightbox-loader ' + h.op.fadeLoaderClassName;
h.fl = $(document.body.appendChild(ddiv));
}
h.boxes = [];
Event.observe(document, 'globallightbox:opened', function(e){
h.ol++;
h.boxes[h.ol] = (e.memo.box); //it's not funny, it's ¬ast xiupened ¬ightbox...
h.hl();
h.fd();
}.bind(h));
Event.observe(document, 'globallightbox:closed', function(e){
h.ol--;
h.uf();
}.bind(h));
Event.observe(document, 'globallightbox:soft.closed', function(e){
h.sl();
h.ol--;
}.bind(h));
h.rf = function (){ // Refresh the fader position
h.fa.setStyle({ // our fader need position too...
left: 0,
top: 0,
position: 'fixed',
width: document.viewport.getWidth() + 'px',
height: document.viewport.getHeight() + 'px',
zIndex: 9980
});
h.fl.setStyle({ // our fader need position too...
zIndex: 10000
});
};
Event.observe(window, 'resize', h.rf);
//hello
h.fd = function (){ //Fade
if (h.ff) {
return;
}
h.ff=true; //Faded==true
h.rf();
h.fa.setOpacity(0);
Effect.Appear(h.fa, h.op.appearOptions);
};
h.uf = function (){ //Unfade
if (h.ol > 0) {
return;
}
h.ff=false; //Faded
Effect.Fade (h.fa, h.op.hideOptions);
if (h.ls) { //Hide loader if it didn't hidden yet
h.ls=false;
Effect.Fade (h.fl, h.op.hideOptions);
}
};
h.sl = function () { //Show loader
if (h.ls) {
return;
}
h.ls = true;
h.fd();
h.fl.setOpacity(0);
Effect.Appear(h.fl, h.op.appearOptions);
}
h.hl = function () { //Hide loader
h.ls=false;
setTimeout(h.uf, 100);
Effect.Fade (h.fl, h.op.hideOptions);
}
// Close on ESC
//
if (!h.op.dontCloseOnEsc) {
Event.observe(document, 'keyup', function (e) {
if (h.boxes[h.ol] && e.keyCode === 27 && h.boxes[h.ol].isOpened()) {
h.boxes[h.ol].close();
}
});
}
return h;
};
//GLOBAL SCOPE ATTACK ATTENTIOOON!!!111
Event.observe(window, 'load', function(){
window.lightboxMasterGlobal = new lightboxMaster();
});
/*
* Huy vam a ne kommentarii
*
*/
var lightbox = function (xdata, op) {
//"use strict";
var h = { }, // OLOLO, dont touch it please
dO = { // isn't it clear? d is default, and O is Options
uid: '',
positionMode: 'absolute-center', // ...
noEffects: false, // true if wouldn't or cant use Effect class
dontShowRightNow: false, // all lightbox shown right after creation (by default)
hDesign: false, // use hardcoded design styles, hope nobody will use it
keyWord: 'lightbox', // keyword used in control classnames(inside lb) to operate with it
appearEffect:'Appear', // I am tired, will finish with comments later...
hideEffect:'Fade',
reposition:true,
wrapperClassName:'oggetto-lightbox',
appearOptions:{
duration:0.3
},
hideOptions:{
duration:0.3
}
},
S$ = $ || function (id) { // It was a little dream about make it without Prototype
document.getElementById(id);
},
fuu, // two little iterators
piu, // ...
xiu,
ddiv; // little DOM shit
//init options
h.op = op || { };
h.op = merge(h.op, dO, true);
if (h.op.uid.length>0) { // Check if ID is ok
h.op.uid = h.op.keyWord + '_' + h.op.uid.toString();
}
//init
if ( S$(h.op.uid) && S$(h.op.uid).innerHTML ) { // if the element with this id exist
h.fb = $(h.op.uid); // parazite on it
h.fb.update(xdata); // and update it's content with XDATA
} else { // if not exist
if (typeof (xdata) === 'string') { // let's know is it some kind of html...
if ( S$(xdata) !== null ) { // and there is some element with XDATA id
h.fb = S$(xdata); // just use it!...
} else {
ddiv = $(document.createElement('div'));
ddiv.className = 'oggetto-lightbox ' + h.op.wrapperClassName;
ddiv.style.display = 'none';
ddiv.update (xdata);
h.fb = document.body.appendChild(ddiv);
}
} else {
if (S$(xdata).tagName) {
h.fb = xdata;
} else {
console.log('Lightbox: Can\'t understand you boy');
return false;
}
}
}
if (h.op.uid.length>0) { // Check if ID is ok
h.fb.id = h.op.uid;
}
h.up = function (html) { // Update Inner html
h.fb.update(html);
h.bc();
}
h.go = function () { // Get option
return h.op;
};
h.so = function(on, ov) { //Set option
if (h.op.hasOwnProperty(on)) {
h.op[on] = ov;
}
};
if (!Effect) {
h.setOption('noEffects', true);
}
h.toggle = function () { //Toggle show
if (h.isOpened()) {
return h.close();
} else {
return h.open();
}
};
h.observe = function(event, handler) {
h.fb.observe(event, handler);
}
h.open = function (reposition) { //Open Lightbox
h.sp();
if (h.isOpened()) {
return false;
}
Event.fire(document, 'globallightbox:opened', {box:h});
h.fb.fire('lightbox:opened');
if (h.op.noEffects || Prototype.Browser.IE) {
return h.fb.show();
} else {
Effect[h.op.appearEffect](h.fb, h.op.appearOptions);
}
};
h.close = function (soft) { //Close lightbox
if (!h.isOpened) {
return false;
}
if(soft === true) {
Event.fire(document, 'globallightbox:soft.closed');
} else {
Event.fire(document, 'globallightbox:closed');
}
h.fb.fire('lightbox:closed');
if (h.op.noEffects || Prototype.Browser.IE) {
return h.fb.hide();
} else {
Effect[h.op.hideEffect](h.fb, h.op.hideOptions);
}
};
h.closeSoft = function(){ //Close but lock fader, thank you Lewis
h.close(true);
}
h.isOpened = function () { // is this lightbox opened
if (h.fb.style.display !== 'none') {
return true;
}
return false;
}
h.hD = function(){ // Use hardcoded design, lol
h.fb.setStyle({
background:"#fff",
boxShadow:"0 0 10px #555",
padding:'10px',
borderRadius:'5px'
});
}
h.sp = function (mode) { // very easy
var m = mode || h.op.positionMode;
var f = h.fb; //shortcut
var t = []; //temp shit
var elay;
if (h.op.hDesign) {
h.hD();
}
t.dh = document.viewport.getHeight();
t.sy = document.viewport.getScrollOffsets()[1];
f.setStyle({
top: '-100550px',
position: 'absolute'
});
t.olddisplay = f.style.display;
f.style.display = 'block'; //Sorry for reflow, bitch
t.w = f.getWidth();
t.h = f.getHeight();
f.style.display = t.olddisplay;
f.style.zIndex = 10001;
switch (m) {
case 'absolute-page-center':
f.setStyle({
position: 'absolute',
top: '50%',
left: '50%',
marginLeft: -Math.floor(t.w/2) + 'px',
marginTop: -Math.floor(t.h/2) + 'px'
});
break;
case 'absolute-center':
t.ct = (t.dh - t.h)/2 + t.sy;
if (t.ct < 150) {
t.ct = 150;
}
f.setStyle({
position: 'absolute',
top: Math.floor(t.ct) + 'px',
left: '50%',
marginLeft: -Math.floor(t.w/2) + 'px'
});
break;
default:
return;
}
h.positioned=true;
};
h.bc = function () {
// Bind direct CONTROLS
//
if (h.op.controls) {
for (fuu in h.op.controls) {
if (h.hasOwnProperty(fuu) && (typeof (h[fuu]) === 'function') && h.op.controls.hasOwnProperty(fuu)) {
h.op.controls[fuu].each(function (piu) {
Event.observe(piu, 'click', h[fuu]);
});
}
}
}
// Bind CONTROLS through keyword + controlname in classname
//
ddiv = h.fb.select('*');
ddiv.each(function(fuu){
var cList = fuu.className.split(' ');
for (piu=0; piu<cList.length; piu++) {
if (cList[piu].substring(0, h.op.keyWord.length) === h.op.keyWord) {
xiu = cList[piu].substring(h.op.keyWord.length+1);
if (h.hasOwnProperty(xiu) && (typeof (h[xiu]) === 'function')) {
Event.observe(fuu, 'click', h[xiu]);
}
}
}
});
}
h.bc(); //BIND CONTROLS, WHAR ARE YOU WAITING FOR!!11??
// Show right after class definition
//
if (!h.op.dontShowRightNow) {
setTimeout(h.open, 110);
}
return h;
};