PageSourceSearch

https://www.travelphotoreport.com/wp-content/themes/Mundo/lightbox/lightbox.js

js travelphotoreport.com collected 2026-10-02 13:57:37 UTC 11,631 bytes, 385 lines download raw bytes

1/*
2	Lightbox JS: Fullsize Image Overlays by Lokesh Dhakar - http://www.huddletogether.com
3	For more information on this script, visit:	http://huddletogether.com/projects/lightbox/
4
5	Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
6	(basically, do anything you want, just leave my name and link)
7	
8	Table of Contents
9	-----------------
10	Configuration
11	
12	Functions
13	- getPageScroll()
14	- getPageSize()
15	- pause()
16	- getKey()
17	- listenKey()
18	- showLightbox()
19	- hideLightbox()
20	- initLightbox()
21	- addLoadEvent()
22	
23	Function Calls
24	- addLoadEvent(initLightbox)
25
26	WP Lightbox JS WordPress Plugin: 
27	--------------------------------
28	Changelog
29	- 4/6/06 3:18 GMT+8: Fixes a Zlib output compression problem that conflicts with PHP setting (Rudd-0).
30	- 3/9/06 2:49 GMT+8: Enabled and use WordPress gzip compression (Safirul Alredha).
31	- 3/6/06 2:06 GMT+8: Fix plugin path issue (Dennis Crall).
32	- 3/3/06 19:00 GMT-5: Fixed blog caching override introduced by wp-blog-header.php (Rudd-O).
33	- 1/19/06 10:40PM EST: Added keypress (x) activated closing (Lokesh Dhakar).
34
35	Last updated: April 6, 2006 by Safirul Alredha 
36	http://zeo.unic.net.my
37*/
38//
39// getPageScroll()
40// Returns array with x,y page scroll values.
41// Core code from - quirksmode.org
42//
43function getPageScroll(){
44
45	var yScroll;
46
47	if (self.pageYOffset) {
48		yScroll = self.pageYOffset;
49	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
50		yScroll = document.documentElement.scrollTop;
51	} else if (document.body) {// all other Explorers
52		yScroll = document.body.scrollTop;
53	}
54
55	arrayPageScroll = new Array('',yScroll) 
56	return arrayPageScroll;
57}
58
59//
60// getPageSize()
61// Returns array with page width, height and window width, height
62// Core code from - quirksmode.org
63// Edit for Firefox by pHaez
64//
65function getPageSize(){
66	
67	var xScroll, yScroll;
68	
69	if (window.innerHeight && window.scrollMaxY) {	
70		xScroll = document.body.scrollWidth;
71		yScroll = window.innerHeight + window.scrollMaxY;
72	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
73		xScroll = document.body.scrollWidth;
74		yScroll = document.body.scrollHeight;
75	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
76		xScroll = document.body.offsetWidth;
77		yScroll = document.body.offsetHeight;
78	}
79	
80	var windowWidth, windowHeight;
81	if (self.innerHeight) {	// all except Explorer
82		windowWidth = self.innerWidth;
83		windowHeight = self.innerHeight;
84	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
85		windowWidth = document.documentElement.clientWidth;
86		windowHeight = document.documentElement.clientHeight;
87	} else if (document.body) { // other Explorers
88		windowWidth = document.body.clientWidth;
89		windowHeight = document.body.clientHeight;
90	}	
91	
92	// for small pages with total height less then height of the viewport
93	if(yScroll < windowHeight){
94		pageHeight = windowHeight;
95	} else { 
96		pageHeight = yScroll;
97	}
98
99	// for small pages with total width less then width of the viewport
100	if(xScroll < windowWidth){	
101		pageWidth = windowWidth;
102	} else {
103		pageWidth = xScroll;
104	}
105
106	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
107	return arrayPageSize;
108}
109
110//
111// pause(numberMillis)
112// Pauses code execution for specified time. Uses busy code, not good.
113// Code from http://www.faqts.com/knowledge_base/view.phtml/aid/1602
114//
115function pause(numberMillis) {
116	var now = new Date();
117	var exitTime = now.getTime() + numberMillis;
118	while (true) {
119		now = new Date();
120		if (now.getTime() > exitTime)
121			return;
122	}
123}
124
125//
126// getKey(key)
127// Gets keycode. If 'x' is pressed then it hides the lightbox.
128//
129function getKey(e){
130	if (e == null) { // ie
131		keycode = event.keyCode;
132	} else { // mozilla
133		keycode = e.which;
134	}
135	key = String.fromCharCode(keycode).toLowerCase();
136	
137	if(key == 'x'){ hideLightbox(); }
138}
139
140//
141// listenKey()
142//
143function listenKey () {	document.onkeypress = getKey; }
144	
145//
146// showLightbox()
147// Preloads images. Pleaces new image in lightbox then centers and displays.
148//
149function showLightbox(objLink)
150{
151	// prep objects
152	var objOverlay = document.getElementById('overlay');
153	var objLightbox = document.getElementById('lightbox');
154	var objCaption = document.getElementById('lightboxCaption');
155	var objImage = document.getElementById('lightboxImage');
156	var objLoadingImage = document.getElementById('loadingImage');
157
158	var arrayPageSize = getPageSize();
159	var arrayPageScroll = getPageScroll();
160
161	// center loadingImage if it exists
162	if (objLoadingImage) {
163		objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objLoadingImage.height) / 2) + 'px');
164		objLoadingImage.style.left = (((arrayPageSize[0] - 20 - objLoadingImage.width) / 2) + 'px');
165		objLoadingImage.style.display = 'block';
166	}
167
168	// set height of Overlay to take up whole page and show
169	objOverlay.style.height = (arrayPageSize[1] + 'px');
170	objOverlay.style.display = 'block';
171
172	// preload image
173	imgPreload = new Image();
174
175	imgPreload.onload=function(){
176		objImage.src = objLink.href;
177
178		// center lightbox and make sure that the top and left values are not negative
179		// and the image placed outside the viewport
180		var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - imgPreload.height) / 2);
181		var lightboxLeft = ((arrayPageSize[0] - 20 - imgPreload.width) / 2);
182		
183		objLightbox.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
184		objLightbox.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
185
186		//objLightboxDetails.style.width = imgPreload.width + 'px';
187		
188		if(objLink.getAttribute('title')){
189			objCaption.style.display = 'block';
190			objCaption.style.width = imgPreload.width + 'px';
191			objCaption.innerHTML = objLink.getAttribute('title');
192		} else {
193			objCaption.style.display = 'none';
194		}
195		
196		// A small pause between the image loading and displaying is required with IE,
197		// this prevents the previous image displaying for a short burst causing flicker.
198		if (navigator.appVersion.indexOf("MSIE")!=-1){
199			pause(250);
200		} 
201
202		if (objLoadingImage) {	objLoadingImage.style.display = 'none'; }
203		objLightbox.style.display = 'block';
204
205		// After image is loaded, update the overlay height as the new image might have
206		// increased the overall page height.
207		arrayPageSize = getPageSize();
208		objOverlay.style.height = (arrayPageSize[1] + 'px');
209		
210		// Check for 'x' keypress
211                listenKey();
212
213		return false;
214	}
215
216	imgPreload.src = objLink.href;
217	
218}
219
220//
221// hideLightbox()
222//
223function hideLightbox()
224{
225	// get objects
226	objOverlay = document.getElementById('overlay');
227	objLightbox = document.getElementById('lightbox');
228
229	// hide lightbox and overlay
230	objOverlay.style.display = 'none';
231	objLightbox.style.display = 'none';
232	
233	// disable keypress listener
234	document.onkeypress = '';
235
236}
237
238//
239// initLightbox()
240// Function runs on window load, going through link tags looking for rel="lightbox".
241// These links receive onclick events that enable the lightbox display for their targets.
242// The function also inserts html markup at the top of the page which will be used as a
243// container for the overlay pattern and the inline image.
244//
245function initLightbox()
246{
247	
248	if (!document.getElementsByTagName){ return; }
249	var anchors = document.getElementsByTagName("a");
250
251	// loop through all anchor tags
252	for (var i=0; i<anchors.length; i++){
253		var anchor = anchors[i];
254
255		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "lightbox")){
256			anchor.onclick = function () {showLightbox(this); return false;}
257		}
258	}
259
260	// the rest of this code inserts html at the top of the page that looks like this:
261	//
262	// <div id="overlay">
263	//		<a href="#" onclick="hideLightbox(); return false;"><img id="loadingImage" /></a>
264	//	</div>
265	// <div id="lightbox">
266	//		<a href="#" onclick="hideLightbox(); return false;" title="Click anywhere to close image">
267	//			<img id="closeButton" />		
268	//			<img id="lightboxImage" />
269	//		</a>
270	//		<div id="lightboxDetails">
271	//			<div id="lightboxCaption"></div>
272	//			<div id="keyboardMsg"></div>
273	//		</div>
274	// </div>
275	
276	var objBody = document.getElementsByTagName("body").item(0);
277	
278	// create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
279	var objOverlay = document.createElement("div");
280	objOverlay.setAttribute('id','overlay');
281	//objOverlay.onclick = function () {hideLightbox(); return false;}
282	objOverlay.style.display = 'none';
283	objOverlay.style.position = 'absolute';
284	objOverlay.style.top = '0';
285	objOverlay.style.left = '0';
286	objOverlay.style.zIndex = '90';
287 	objOverlay.style.width = '100%';
288	objBody.insertBefore(objOverlay, objBody.firstChild);
289	
290	var arrayPageSize = getPageSize();
291	var arrayPageScroll = getPageScroll();
292
293	// preload and create loader image
294	var imgPreloader = new Image();
295	
296	// if loader image found, create link to hide lightbox and create loadingimage
297	imgPreloader.onload=function(){
298
299		var objLoadingImageLink = document.createElement("a");
300		objLoadingImageLink.setAttribute('href','#');
301		objLoadingImageLink.onclick = function () {hideLightbox(); return false;}
302		objOverlay.appendChild(objLoadingImageLink);
303		
304		var objLoadingImage = document.createElement("img");
305		objLoadingImage.src = loadingImage;
306		objLoadingImage.setAttribute('id','loadingImage');
307		objLoadingImage.style.position = 'absolute';
308		objLoadingImage.style.zIndex = '150';
309		objLoadingImageLink.appendChild(objLoadingImage);
310
311		imgPreloader.onload=function(){};	//	clear onLoad, as IE will flip out w/animated gifs
312
313		return false;
314	}
315
316	imgPreloader.src = loadingImage;
317
318	// create lightbox div, same note about styles as above
319	var objLightbox = document.createElement("div");
320	objLightbox.setAttribute('id','lightbox');
321	objLightbox.style.display = 'none';
322	objLightbox.style.position = 'absolute';
323	objLightbox.style.zIndex = '100';	
324	objBody.insertBefore(objLightbox, objOverlay.nextSibling);
325	
326	// create link
327	var objLink = document.createElement("a");
328	objLink.setAttribute('href','#');
329	objLink.setAttribute('title','Click to close');
330	objLink.onclick = function () {hideLightbox(); return false;}
331	objLightbox.appendChild(objLink);
332
333	// preload and create close button image
334	var imgPreloadCloseButton = new Image();
335
336	// if close button image found, 
337	imgPreloadCloseButton.onload=function(){
338
339		var objCloseButton = document.createElement("img");
340		objCloseButton.src = closeButton;
341		objCloseButton.setAttribute('id','closeButton');
342		objCloseButton.style.position = 'absolute';
343		objCloseButton.style.zIndex = '200';
344                objCloseButton.style.top = '5px';
345                objCloseButton.style.right = '5px';
346		objLink.appendChild(objCloseButton);
347
348		return false;
349	}
350
351	imgPreloadCloseButton.src = closeButton;
352
353	// create image
354	var objImage = document.createElement("img");
355	objImage.setAttribute('id','lightboxImage');
356	objLink.appendChild(objImage);
357	
358	// create caption
359	var objCaption = document.createElement("div");
360	objCaption.setAttribute('id','lightboxCaption');
361	objCaption.style.display = 'none';
362	objLightbox.appendChild(objCaption);
363
364}
365
366//
367// addLoadEvent()
368// Adds event to window.onload without overwriting currently assigned onload functions.
369// Function found at Simon Willison's weblog - http://simon.incutio.com/
370//
371function addLoadEvent(func)
372{	
373	var oldonload = window.onload;
374	if (typeof window.onload != 'function'){
375    	window.onload = func;
376	} else {
377		window.onload = function(){
378		oldonload();
379		func();
380		}
381	}
382
383}
384
385addLoadEvent(initLightbox);	// run initLightbox onLoad

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.