PageSourceSearch

https://www.newforestobservatory.com/wordpress/wp-content/plugins/…/Lightbox/thickbox/thickbox.js?ver=4.4.1

js newforestobservatory.com collected 2026-09-24 22:46:55 UTC 15,432 bytes, 425 lines download raw bytes

1/*
2 * Thickbox 3.1 - One Box To Rule Them All.
3 * By Cody Lindley (http://www.codylindley.com)
4 * Copyright (c) 2007 cody lindley
5 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
6 *
7 * Modified 2021-07-14 by Benjamin Owens @ Imagely/LionSher to add WebP to the list of image formats.
8*/
9
10if ( typeof tb_pathToImage != 'string' ) {
11	var tb_pathToImage = thickboxL10n.loadingAnimation;
12}
13
14/*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/
15
16//on page load call tb_init
17jQuery(document).ready(function(){
18	tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
19	imgLoader = new Image();// preload image
20	imgLoader.src = tb_pathToImage;
21});
22
23/*
24 * Add thickbox to href & area elements that have a class of .thickbox.
25 * Remove the loading indicator when content in an iframe has loaded.
26 */
27function tb_init(domChunk){
28	jQuery( 'body' )
29		.on( 'click', domChunk, tb_click )
30		.on( 'thickbox:iframe:loaded', function() {
31			jQuery( '#TB_window' ).removeClass( 'thickbox-loading' );
32		});
33}
34
35function tb_click(){
36	var t = this.title || this.name || null;
37	var a = this.href || this.alt;
38	var g = this.rel || false;
39
40	// Sanitize the title to allow only safe HTML tags
41	if (t) {
42		t = sanitizeAllowedHTML(t);
43	}
44
45	// Sanitize the href or alt to allow only safe HTML tags
46	if (a) {
47		a = sanitizeAllowedHTML(a);
48	}
49
50	t = (this.getAttribute('data-view-title')) ? sanitizeAllowedHTML(this.getAttribute('data-view-title')) : t;
51	tb_show(t, a, g);
52	this.blur();
53	return false;
54}
55
56function sanitizeAllowedHTML(value) {
57	// Define allowed HTML tags and attributes similar to wp_kses
58	const allowedTags = {
59		a: ["href", "title", "target", "rel"],
60		b: [],
61		i: [],
62		u: [],
63		em: [],
64		strong: [],
65		p: [],
66		br: [],
67		span: ["class", "id", "style"],
68		img: ["src", "alt", "title"],
69		h1: [],
70		h2: [],
71		h4: [],
72		h4: [],
73		h5: [],
74		h6: [],
75		ul: [],
76		ol: [],
77		li: [],
78		blockquote: [],
79	};
80
81	// Use a temporary DOM element to parse and sanitize the input
82	const tempDiv = document.createElement('div');
83	tempDiv.innerHTML = value;
84
85	// Recursively sanitize child nodes
86	function sanitizeNode(node) {
87		if (node.nodeType === Node.ELEMENT_NODE) {
88			if (!allowedTags[node.tagName.toLowerCase()]) {
89				node.remove();
90				return;
91			}
92
93			// Remove disallowed attributes
94			[...node.attributes].forEach(attr => {
95				if (!allowedTags[node.tagName.toLowerCase()].includes(attr.name)) {
96					node.removeAttribute(attr.name);
97				}
98			});
99		} else if (node.nodeType === Node.TEXT_NODE) {
100			// Allow text nodes
101			return;
102		} else {
103			// Remove other node types
104			node.remove();
105		}
106
107		// Recursively sanitize child nodes
108		[...node.childNodes].forEach(sanitizeNode);
109	}
110
111	[...tempDiv.childNodes].forEach(sanitizeNode);
112
113	return tempDiv.innerHTML;
114}
115
116function sanitizeToPlainText(value) {
117	// Create a temporary element to decode HTML entities and remove HTML tags.
118	const tempDiv = jQuery("<div>").html(value);
119	let plainText = tempDiv.text(); // Get plain text (decodes entities and removes tags).
120	tempDiv.remove(); // Clean up the temporary element.
121
122	// Remove special characters, including quotes and backticks.
123	plainText = plainText.replace(/['"`~!@#$%^&*()_+=\[\]{}|;:,.<>?/\\-]/g, "");
124
125	// Trim any extra spaces.
126	return plainText.trim();
127}
128
129function tb_show(caption, url, imageGroup) {//function called when the user clicks on a thickbox link
130
131	var $closeBtn;
132
133	try {
134		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
135			jQuery("body","html").css({height: "100%", width: "100%"});
136			jQuery("html").css("overflow","hidden");
137			if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
138				jQuery("body").append("<iframe id='TB_HideSelect'>"+thickboxL10n.noiframes+"</iframe><div id='TB_overlay'></div><div id='TB_window' class='thickbox-loading'></div>");
139				jQuery("#TB_overlay").on( 'click', tb_remove );
140			}
141		}else{//all others
142			if(document.getElementById("TB_overlay") === null){
143				jQuery("body").append("<div id='TB_overlay'></div><div id='TB_window' class='thickbox-loading'></div>");
144				jQuery("#TB_overlay").on( 'click', tb_remove );
145				jQuery( 'body' ).addClass( 'modal-open' );
146			}
147		}
148
149		if(tb_detectMacXFF()){
150			jQuery("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
151		}else{
152			jQuery("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
153		}
154
155		if(caption===null){caption="";}
156		jQuery("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' width='208' /></div>");//add loader to the page
157		jQuery('#TB_load').show();//show loader
158
159		var baseURL;
160	   if(url.indexOf("?")!==-1){ //ff there is a query string involved
161			baseURL = url.substr(0, url.indexOf("?"));
162	   }else{
163	   		baseURL = url;
164	   }
165
166	   var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$|\.webp$/;
167	   var urlType = baseURL.toLowerCase().match(urlString);
168
169		if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp' || urlType == '.webp'){//code to show images
170
171			TB_PrevCaption = "";
172			TB_PrevURL = "";
173			TB_PrevHTML = "";
174			TB_NextCaption = "";
175			TB_NextURL = "";
176			TB_NextHTML = "";
177			TB_imageCount = "";
178			TB_FoundURL = false;
179			if(imageGroup){
180				TB_TempArray = jQuery("a[rel="+imageGroup+"]").get();
181				for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML === "")); TB_Counter++) {
182					var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString);
183						if (!(TB_TempArray[TB_Counter].href == url)) {
184							if (TB_FoundURL) {
185								TB_NextCaption = TB_TempArray[TB_Counter].title;
186								TB_NextURL = TB_TempArray[TB_Counter].href;
187								TB_NextHTML = "<span id='TB_next'>&nbsp;&nbsp;<a href='#'>"+thickboxL10n.next+"</a></span>";
188							} else {
189								TB_PrevCaption = TB_TempArray[TB_Counter].title;
190								TB_PrevURL = TB_TempArray[TB_Counter].href;
191								TB_PrevHTML = "<span id='TB_prev'>&nbsp;&nbsp;<a href='#'>"+thickboxL10n.prev+"</a></span>";
192							}
193						} else {
194							TB_FoundURL = true;
195							TB_imageCount = thickboxL10n.image + ' ' + (TB_Counter + 1) + ' ' + thickboxL10n.of + ' ' + (TB_TempArray.length);
196						}
197				}
198			}
199
200			imgPreloader = new Image();
201			imgPreloader.onload = function(){
202			imgPreloader.onload = null;
203
204			// Resizing large images - original by Christian Montoya edited by me.
205			var pagesize = tb_getPageSize();
206			var x = pagesize[0] - 150;
207			var y = pagesize[1] - 150;
208			var imageWidth = imgPreloader.width;
209			var imageHeight = imgPreloader.height;
210			if (imageWidth > x) {
211				imageHeight = imageHeight * (x / imageWidth);
212				imageWidth = x;
213				if (imageHeight > y) {
214					imageWidth = imageWidth * (y / imageHeight);
215					imageHeight = y;
216				}
217			} else if (imageHeight > y) {
218				imageWidth = imageWidth * (y / imageHeight);
219				imageHeight = y;
220				if (imageWidth > x) {
221					imageHeight = imageHeight * (x / imageWidth);
222					imageWidth = x;
223				}
224			}
225			// End Resizing
226
227			TB_WIDTH = imageWidth + 30;
228			TB_HEIGHT = imageHeight + 60;
229			jQuery("#TB_window").append("<a href='' id='TB_ImageOff'><span class='screen-reader-text'>"+thickboxL10n.close+"</span><img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+sanitizeToPlainText(caption)+"'/></a>" + "<div id='TB_caption'>"+caption+"<div id='TB_secondLine'>" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "</div></div><div id='TB_closeWindow'><button type='button' id='TB_closeWindowButton'><span class='screen-reader-text'>"+thickboxL10n.close+"</span><span class='tb-close-icon'></span></button></div>");
230
231			jQuery("#TB_closeWindowButton").on( 'click', tb_remove );
232
233			if (!(TB_PrevHTML === "")) {
234				function goPrev(){
235					if(jQuery(document).off("click",goPrev)){jQuery(document).off("click",goPrev);}
236					jQuery("#TB_window").remove();
237					jQuery("body").append("<div id='TB_window'></div>");
238					tb_show(TB_PrevCaption, TB_PrevURL, imageGroup);
239					return false;
240				}
241				jQuery("#TB_prev").on( 'click', goPrev );
242			}
243
244			if (!(TB_NextHTML === "")) {
245				function goNext(){
246					jQuery("#TB_window").remove();
247					jQuery("body").append("<div id='TB_window'></div>");
248					tb_show(TB_NextCaption, TB_NextURL, imageGroup);
249					return false;
250				}
251				jQuery("#TB_next").on( 'click', goNext );
252
253			}
254
255			jQuery(document).on('keydown.thickbox', function(e){
256				if ( e.which == 27 ){ // close
257					tb_remove();
258
259				} else if ( e.which == 190 ){ // display previous image
260					if(!(TB_NextHTML == "")){
261						jQuery(document).off('thickbox');
262						goNext();
263					}
264				} else if ( e.which == 188 ){ // display next image
265					if(!(TB_PrevHTML == "")){
266						jQuery(document).off('thickbox');
267						goPrev();
268					}
269				}
270				return false;
271			});
272
273			tb_position();
274			jQuery("#TB_load").remove();
275			jQuery("#TB_ImageOff").on( 'click', tb_remove );
276			jQuery("#TB_window").css({'visibility':'visible'}); //for safari using css instead of show
277			};
278
279			imgPreloader.src = url;
280		}else{//code to show html
281
282			var queryString = url.replace(/^[^\?]+\??/,'');
283			var params = tb_parseQuery( queryString );
284
285			TB_WIDTH = (params['width']*1) + 30 || 630; //defaults to 630 if no parameters were added to URL
286			TB_HEIGHT = (params['height']*1) + 40 || 440; //defaults to 440 if no parameters were added to URL
287			ajaxContentW = TB_WIDTH - 30;
288			ajaxContentH = TB_HEIGHT - 45;
289
290			if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window
291					urlNoQuery = url.split('TB_');
292					jQuery("#TB_iframeContent").remove();
293					if(params['modal'] != "true"){//iframe no modal
294						jQuery("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><button type='button' id='TB_closeWindowButton'><span class='screen-reader-text'>"+thickboxL10n.close+"</span><span class='tb-close-icon'></span></button></div></div><iframe frameborder='0' hspace='0' allowtransparency='true' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;' >"+thickboxL10n.noiframes+"</iframe>");
295					}else{//iframe modal
296					jQuery("#TB_overlay").off();
297						jQuery("#TB_window").append("<iframe frameborder='0' hspace='0' allowtransparency='true' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;'>"+thickboxL10n.noiframes+"</iframe>");
298					}
299			}else{// not an iframe, ajax
300					if(jQuery("#TB_window").css("visibility") != "visible"){
301						if(params['modal'] != "true"){//ajax no modal
302						jQuery("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><button type='button' id='TB_closeWindowButton'><span class='screen-reader-text'>"+thickboxL10n.close+"</span><span class='tb-close-icon'></span></button></div></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>");
303						}else{//ajax modal
304						jQuery("#TB_overlay").off();
305						jQuery("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");
306						}
307					}else{//this means the window is already up, we are just loading new content via ajax
308						jQuery("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
309						jQuery("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
310						jQuery("#TB_ajaxContent")[0].scrollTop = 0;
311						jQuery("#TB_ajaxWindowTitle").html(caption);
312					}
313			}
314
315			jQuery("#TB_closeWindowButton").on( 'click', tb_remove );
316
317				if(url.indexOf('TB_inline') != -1){
318					jQuery("#TB_ajaxContent").append(jQuery('#' + params['inlineId']).children());
319					jQuery("#TB_window").on('tb_unload', function () {
320						jQuery('#' + params['inlineId']).append( jQuery("#TB_ajaxContent").children() ); // move elements back when you're finished
321					});
322					tb_position();
323					jQuery("#TB_load").remove();
324					jQuery("#TB_window").css({'visibility':'visible'});
325				}else if(url.indexOf('TB_iframe') != -1){
326					tb_position();
327					jQuery("#TB_load").remove();
328					jQuery("#TB_window").css({'visibility':'visible'});
329				}else{
330					var load_url = url;
331					load_url += -1 === url.indexOf('?') ? '?' : '&';
332					jQuery("#TB_ajaxContent").load(load_url += "random=" + (new Date().getTime()),function(){//to do a post change this load method
333						tb_position();
334						jQuery("#TB_load").remove();
335						tb_init("#TB_ajaxContent a.thickbox");
336						jQuery("#TB_window").css({'visibility':'visible'});
337					});
338				}
339
340		}
341
342		if(!params['modal']){
343			jQuery(document).on('keydown.thickbox', function(e){
344				if ( e.which == 27 ){ // close
345					tb_remove();
346					return false;
347				}
348			});
349		}
350
351		$closeBtn = jQuery( '#TB_closeWindowButton' );
352		/*
353		 * If the native Close button icon is visible, move focus on the button
354		 * (e.g. in the Network Admin Themes screen).
355		 * In other admin screens is hidden and replaced by a different icon.
356		 */
357		if ( $closeBtn.find( '.tb-close-icon' ).is( ':visible' ) ) {
358			$closeBtn.trigger( 'focus' );
359		}
360
361	} catch(e) {
362		//nothing here
363	}
364}
365
366//helper functions below
367function tb_showIframe(){
368	jQuery("#TB_load").remove();
369	jQuery("#TB_window").css({'visibility':'visible'}).trigger( 'thickbox:iframe:loaded' );
370}
371
372function tb_remove() {
373 	jQuery("#TB_imageOff").off("click");
374	jQuery("#TB_closeWindowButton").off("click");
375	jQuery( '#TB_window' ).fadeOut( 'fast', function() {
376		jQuery( '#TB_window, #TB_overlay, #TB_HideSelect' ).trigger( 'tb_unload' ).off().remove();
377		jQuery( 'body' ).trigger( 'thickbox:removed' );
378	});
379	jQuery( 'body' ).removeClass( 'modal-open' );
380	jQuery("#TB_load").remove();
381	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
382		jQuery("body","html").css({height: "auto", width: "auto"});
383		jQuery("html").css("overflow","");
384	}
385	jQuery(document).off('.thickbox');
386	return false;
387}
388
389function tb_position() {
390var isIE6 = typeof document.body.style.maxHeight === "undefined";
391jQuery("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
392	if ( ! isIE6 ) { // take away IE6
393		jQuery("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
394	}
395}
396
397function tb_parseQuery ( query ) {
398   var Params = {};
399   if ( ! query ) {return Params;}// return empty object
400   var Pairs = query.split(/[;&]/);
401   for ( var i = 0; i < Pairs.length; i++ ) {
402      var KeyVal = Pairs[i].split('=');
403      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
404      var key = unescape( KeyVal[0] );
405      var val = unescape( KeyVal[1] );
406      val = val.replace(/\+/g, ' ');
407      Params[key] = val;
408   }
409   return Params;
410}
411
412function tb_getPageSize(){
413	var de = document.documentElement;
414	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
415	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
416	arrayPageSize = [w,h];
417	return arrayPageSize;
418}
419
420function tb_detectMacXFF() {
421  var userAgent = navigator.userAgent.toLowerCase();
422  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
423    return true;
424  }
425}

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.