|
@@ -1,188 +0,0 @@
|
1
|
|
-/*
|
2
|
|
- Slimbox v1.3 - The ultimate lightweight Lightbox clone
|
3
|
|
- by Christophe Beyls (http://www.digitalia.be) - MIT-style license.
|
4
|
|
- Inspired by the original Lightbox v2 by Lokesh Dhakar.
|
5
|
|
-*/
|
6
|
|
-
|
7
|
|
-var Lightbox = {
|
8
|
|
-
|
9
|
|
- init: function(options){
|
10
|
|
- this.options = Object.extend({
|
11
|
|
- resizeDuration: 400,
|
12
|
|
- resizeTransition: Fx.Transitions.sineInOut,
|
13
|
|
- initialWidth: 250,
|
14
|
|
- initialHeight: 250,
|
15
|
|
- animateCaption: true
|
16
|
|
- }, options || {});
|
17
|
|
-
|
18
|
|
- this.anchors = [];
|
19
|
|
- $each(document.links, function(el){
|
20
|
|
- if (el.rel && el.rel.test(/^lightbox/i)){
|
21
|
|
- el.onclick = this.click.pass(el, this);
|
22
|
|
- this.anchors.push(el);
|
23
|
|
- }
|
24
|
|
- }, this);
|
25
|
|
- this.eventKeyDown = this.keyboardListener.bindAsEventListener(this);
|
26
|
|
- this.eventPosition = this.position.bind(this);
|
27
|
|
-
|
28
|
|
- this.overlay = new Element('div').setProperty('id', 'lbOverlay').injectInside(document.body);
|
29
|
|
-
|
30
|
|
- this.center = new Element('div').setProperty('id', 'lbCenter').setStyles({width: this.options.initialWidth+'px', height: this.options.initialHeight+'px', marginLeft: '-'+(this.options.initialWidth/2)+'px', display: 'none'}).injectInside(document.body);
|
31
|
|
- this.image = new Element('div').setProperty('id', 'lbImage').injectInside(this.center);
|
32
|
|
- this.prevLink = new Element('a').setProperties({id: 'lbPrevLink', href: '#'}).setStyle('display', 'none').injectInside(this.image);
|
33
|
|
- this.nextLink = this.prevLink.clone().setProperty('id', 'lbNextLink').injectInside(this.image);
|
34
|
|
- this.prevLink.onclick = this.previous.bind(this);
|
35
|
|
- this.nextLink.onclick = this.next.bind(this);
|
36
|
|
-
|
37
|
|
- this.bottomContainer = new Element('div').setProperty('id', 'lbBottomContainer').setStyle('display', 'none').injectInside(document.body);
|
38
|
|
- this.bottom = new Element('div').setProperty('id', 'lbBottom').injectInside(this.bottomContainer);
|
39
|
|
- new Element('a').setProperties({id: 'lbCloseLink', href: '#'}).injectInside(this.bottom).onclick = this.overlay.onclick = this.close.bind(this);
|
40
|
|
- this.caption = new Element('div').setProperty('id', 'lbCaption').injectInside(this.bottom);
|
41
|
|
- this.number = new Element('div').setProperty('id', 'lbNumber').injectInside(this.bottom);
|
42
|
|
- new Element('div').setStyle('clear', 'both').injectInside(this.bottom);
|
43
|
|
-
|
44
|
|
- var nextEffect = this.nextEffect.bind(this);
|
45
|
|
- this.fx = {
|
46
|
|
- overlay: this.overlay.effect('opacity', {duration: 500}).hide(),
|
47
|
|
- resize: this.center.effects({duration: this.options.resizeDuration, transition: this.options.resizeTransition, onComplete: nextEffect}),
|
48
|
|
- image: this.image.effect('opacity', {duration: 500, onComplete: nextEffect}),
|
49
|
|
- bottom: this.bottom.effect('margin-top', {duration: 400, onComplete: nextEffect})
|
50
|
|
- };
|
51
|
|
-
|
52
|
|
- this.preloadPrev = new Image();
|
53
|
|
- this.preloadNext = new Image();
|
54
|
|
- },
|
55
|
|
-
|
56
|
|
- click: function(link){
|
57
|
|
- if (link.rel.length == 8) return this.show(link.href, link.title);
|
58
|
|
-
|
59
|
|
- var j, imageNum, images = [];
|
60
|
|
- this.anchors.each(function(el){
|
61
|
|
- if (el.rel == link.rel){
|
62
|
|
- for (j = 0; j < images.length; j++) if(images[j][0] == el.href) break;
|
63
|
|
- if (j == images.length){
|
64
|
|
- images.push([el.href, el.title]);
|
65
|
|
- if (el.href == link.href) imageNum = j;
|
66
|
|
- }
|
67
|
|
- }
|
68
|
|
- }, this);
|
69
|
|
- return this.open(images, imageNum);
|
70
|
|
- },
|
71
|
|
-
|
72
|
|
- show: function(url, title){
|
73
|
|
- return this.open([[url, title]], 0);
|
74
|
|
- },
|
75
|
|
-
|
76
|
|
- open: function(images, imageNum){
|
77
|
|
- this.images = images;
|
78
|
|
- this.position();
|
79
|
|
- this.setup(true);
|
80
|
|
- this.top = window.getScrollTop() + (window.getHeight() / 15);
|
81
|
|
- this.center.setStyles({top: this.top+'px', display: ''});
|
82
|
|
- this.fx.overlay.start(0.8);
|
83
|
|
- return this.changeImage(imageNum);
|
84
|
|
- },
|
85
|
|
-
|
86
|
|
- position: function(){
|
87
|
|
- this.overlay.setStyles({top: window.getScrollTop()+'px', height: window.getHeight()+'px'});
|
88
|
|
- },
|
89
|
|
-
|
90
|
|
- setup: function(open){
|
91
|
|
- var elements = $A(document.getElementsByTagName('object'));
|
92
|
|
- if (window.ie) elements.extend(document.getElementsByTagName('select'));
|
93
|
|
- elements.each(function(el){ el.style.visibility = open ? 'hidden' : ''; });
|
94
|
|
- var fn = open ? 'addEvent' : 'removeEvent';
|
95
|
|
- window[fn]('scroll', this.eventPosition)[fn]('resize', this.eventPosition);
|
96
|
|
- document[fn]('keydown', this.eventKeyDown);
|
97
|
|
- this.step = 0;
|
98
|
|
- },
|
99
|
|
-
|
100
|
|
- keyboardListener: function(event){
|
101
|
|
- switch (event.keyCode){
|
102
|
|
- case 27: case 88: case 67: this.close(); break;
|
103
|
|
- case 37: case 80: this.previous(); break;
|
104
|
|
- case 39: case 78: this.next();
|
105
|
|
- }
|
106
|
|
- },
|
107
|
|
-
|
108
|
|
- previous: function(){
|
109
|
|
- return this.changeImage(this.activeImage-1);
|
110
|
|
- },
|
111
|
|
-
|
112
|
|
- next: function(){
|
113
|
|
- return this.changeImage(this.activeImage+1);
|
114
|
|
- },
|
115
|
|
-
|
116
|
|
- changeImage: function(imageNum){
|
117
|
|
- if (this.step || (imageNum < 0) || (imageNum >= this.images.length)) return false;
|
118
|
|
- this.step = 1;
|
119
|
|
- this.activeImage = imageNum;
|
120
|
|
-
|
121
|
|
- this.bottomContainer.style.display = this.prevLink.style.display = this.nextLink.style.display = 'none';
|
122
|
|
- this.fx.image.hide();
|
123
|
|
- this.center.className = 'lbLoading';
|
124
|
|
-
|
125
|
|
- this.preload = new Image();
|
126
|
|
- this.preload.onload = this.nextEffect.bind(this);
|
127
|
|
- this.preload.src = this.images[imageNum][0];
|
128
|
|
- return false;
|
129
|
|
- },
|
130
|
|
-
|
131
|
|
- nextEffect: function(){
|
132
|
|
- switch (this.step++){
|
133
|
|
- case 1:
|
134
|
|
- this.center.className = '';
|
135
|
|
- this.image.style.backgroundImage = 'url('+this.images[this.activeImage][0]+')';
|
136
|
|
- this.image.style.width = this.bottom.style.width = this.preload.width+'px';
|
137
|
|
- this.image.style.height = this.prevLink.style.height = this.nextLink.style.height = this.preload.height+'px';
|
138
|
|
-
|
139
|
|
- this.caption.setHTML(this.images[this.activeImage][1] || '');
|
140
|
|
- this.number.setHTML((this.images.length == 1) ? '' : 'Image '+(this.activeImage+1)+' of '+this.images.length);
|
141
|
|
-
|
142
|
|
- if (this.activeImage) this.preloadPrev.src = this.images[this.activeImage-1][0];
|
143
|
|
- if (this.activeImage != (this.images.length - 1)) this.preloadNext.src = this.images[this.activeImage+1][0];
|
144
|
|
- if (this.center.clientHeight != this.image.offsetHeight){
|
145
|
|
- this.fx.resize.start({height: this.image.offsetHeight});
|
146
|
|
- break;
|
147
|
|
- }
|
148
|
|
- this.step++;
|
149
|
|
- case 2:
|
150
|
|
- if (this.center.clientWidth != this.image.offsetWidth){
|
151
|
|
- this.fx.resize.start({width: this.image.offsetWidth, marginLeft: -this.image.offsetWidth/2});
|
152
|
|
- break;
|
153
|
|
- }
|
154
|
|
- this.step++;
|
155
|
|
- case 3:
|
156
|
|
- this.bottomContainer.setStyles({top: (this.top + this.center.clientHeight)+'px', height: '0px', marginLeft: this.center.style.marginLeft, display: ''});
|
157
|
|
- this.fx.image.start(1);
|
158
|
|
- break;
|
159
|
|
- case 4:
|
160
|
|
- if (this.options.animateCaption){
|
161
|
|
- this.fx.bottom.set(-this.bottom.offsetHeight);
|
162
|
|
- this.bottomContainer.style.height = '';
|
163
|
|
- this.fx.bottom.start(0);
|
164
|
|
- break;
|
165
|
|
- }
|
166
|
|
- this.bottomContainer.style.height = '';
|
167
|
|
- case 5:
|
168
|
|
- if (this.activeImage) this.prevLink.style.display = '';
|
169
|
|
- if (this.activeImage != (this.images.length - 1)) this.nextLink.style.display = '';
|
170
|
|
- this.step = 0;
|
171
|
|
- }
|
172
|
|
- },
|
173
|
|
-
|
174
|
|
- close: function(){
|
175
|
|
- if (this.step < 0) return;
|
176
|
|
- this.step = -1;
|
177
|
|
- if (this.preload){
|
178
|
|
- this.preload.onload = Class.empty;
|
179
|
|
- this.preload = null;
|
180
|
|
- }
|
181
|
|
- for (var f in this.fx) this.fx[f].stop();
|
182
|
|
- this.center.style.display = this.bottomContainer.style.display = 'none';
|
183
|
|
- this.fx.overlay.chain(this.setup.pass(false, this)).start(0);
|
184
|
|
- return false;
|
185
|
|
- }
|
186
|
|
-};
|
187
|
|
-
|
188
|
|
-window.addEvent('domready', Lightbox.init.bind(Lightbox));
|