PageSourceSearch

https://www.psykinematix.com/rw_common/themes/alpha/css/slimbox/js/slimbox.js

js psykinematix.com collected 2026-10-06 09:07:25 UTC 7,073 bytes, 192 lines download raw bytes

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

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.