PageSourceSearch

https://mason360.gmu.edu/js/thickbox/thickbox.js

js gmu.edu collected 2026-09-24 07:03:26 UTC 18,117 bytes, 482 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 * Patched Version by Jamie Thompson - Fixes IE7 Positioning Issues
8 * http://jamazon.co.uk/web/2008/03/17/thickbox-31-ie7-positioning-bug/
9*/
10
11var tb_pathToImage = "/images/loader-big.gif";
12
13/* CampusGroups A11Y (2025) - Thickbox iFrame aria-label and title text (set on iframe load) */
14var thickboxA11yTitleContextCallback = null;
15
16// fixes the fact that ie7 now reports itself as MSIE 6.0 compatible
17//$.browser.msie6 =
18//        $.browser.msie
19//        && /MSIE 6\.0/i.test(window.navigator.userAgent)
20//        && !/MSIE 7\.0/i.test(window.navigator.userAgent)
21//		&& !/MSIE 8\.0/i.test(window.navigator.userAgent);
22
23
24//on page load call tb_init
25$(document).ready(function(){
26	tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
27	imgLoader = new Image();// preload image
28	imgLoader.src = tb_pathToImage;
29	document.dispatchEvent(new CustomEvent('thickbox-loaded', { detail: { }}));
30});
31
32//add thickbox to href & area elements that have a class of .thickbox
33
34//var header;
35
36function tb_init(domChunk) {
37    $(domChunk).click(function () {
38        var t = this.title || this.name || null;
39        var a = this.href || this.alt;
40        var g = this.rel || false;
41        tb_show(t, a, g);
42		// !!! MM Addition on 4/2013 - Add this back to new library if update is done. !!!!
43        if ($(this).hasClass('thickboxWhite')) { setWhiteThickbox(); }
44        this.blur();
45        return false;
46    }).removeClass('thickbox');
47}
48
49function tb_show(caption, url, imageGroup) {//function called when the user clicks on a thickbox link
50    try {
51        // IE 6
52		if (typeof document.body.style.maxHeight === "undefined") {
53			$("body","html").css({height: "100%", width: "100%"});
54			$("html").css("overflow","hidden");
55			if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
56			    $("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay' onclick='tb_remove();'></div><div id='TB_window'></div>");
57			}
58		}
59        // Not IE6
60		else {
61		    if (document.getElementById("TB_overlay") === null) {
62		        $("body").append("<div id='TB_overlay' onclick='tb_remove();'></div><div id='TB_window'></div>");
63			}
64		}
65
66		if(tb_detectMacXFF()){
67			$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
68		}else{
69			$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
70		}
71
72		if (caption === null) { caption = ""; }
73		$("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
74		$('#TB_load').show();//show loader
75
76	    var baseURL;
77	    if(url.indexOf("?")!==-1){ //ff there is a query string involved
78		    baseURL = url.substr(0, url.indexOf("?"));
79	    }else{
80	   	    baseURL = url;
81	    }
82
83	    var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
84	    var urlType = baseURL.toLowerCase().match(urlString);
85
86		if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){//code to show images
87			var queryString = url.replace(/^[^\?]+\??/,'');
88			var params = tb_parseQuery( queryString );
89			TB_WIDTH = Math.min(params['width'] || window.innerWidth, window.innerWidth); //Defaults to 100% if no paramaters were added to URL
90			TB_HEIGHT = Math.min(params['height'] || window.innerHeight, window.innerHeight); //Defaults to 100% if no paramaters were added to URL
91			TB_POSITION = params['position'] || ""
92      		TB_onThickboxClose = params['onThickboxClose'] || ""
93            TB_focusOnClose = params['focusOnClose'] || ""
94
95			TB_PrevCaption = "";
96			TB_PrevURL = "";
97			TB_PrevHTML = "";
98			TB_NextCaption = "";
99			TB_NextURL = "";
100			TB_NextHTML = "";
101			TB_imageCount = "";
102			TB_FoundURL = false;
103			if(imageGroup){
104				TB_TempArray = $("a[@rel="+imageGroup+"]").get();
105				for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML === "")); TB_Counter++) {
106					var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString);
107						if (!(TB_TempArray[TB_Counter].href == url)) {
108							if (TB_FoundURL) {
109								TB_NextCaption = TB_TempArray[TB_Counter].title;
110								TB_NextURL = TB_TempArray[TB_Counter].href;
111								TB_NextHTML = "<span id='TB_next'>&nbsp;&nbsp;<a href='#'>Next &gt;</a></span>";
112							} else {
113								TB_PrevCaption = TB_TempArray[TB_Counter].title;
114								TB_PrevURL = TB_TempArray[TB_Counter].href;
115								TB_PrevHTML = "<span id='TB_prev'>&nbsp;&nbsp;<a href='#'>&lt; Prev</a></span>";
116							}
117						} else {
118							TB_FoundURL = true;
119							TB_imageCount = "Image " + (TB_Counter + 1) +" of "+ (TB_TempArray.length);
120						}
121				}
122			}
123
124			imgPreloader = new Image();
125			imgPreloader.onload = function(){
126			imgPreloader.onload = null;
127
128			// Resizing large images - orginal by Christian Montoya edited by me.
129			var pagesize = tb_getPageSize();
130			var x = pagesize[0] - 150;
131			var y = pagesize[1] - 150;
132			var imageWidth = imgPreloader.width;
133			var imageHeight = imgPreloader.height;
134			if (imageWidth > x) {
135				imageHeight = imageHeight * (x / imageWidth);
136				imageWidth = x;
137				if (imageHeight > y) {
138					imageWidth = imageWidth * (y / imageHeight);
139					imageHeight = y;
140				}
141			} else if (imageHeight > y) {
142				imageWidth = imageWidth * (y / imageHeight);
143				imageHeight = y;
144				if (imageWidth > x) {
145					imageHeight = imageHeight * (x / imageWidth);
146					imageWidth = x;
147				}
148			}
149			// End Resizing
150
151			TB_WIDTH = imageWidth + 30;
152			TB_HEIGHT = imageHeight + 60;
153			$("#TB_window").append("<img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/>" + "<div id='TB_caption'>"+caption+"<div id='TB_secondLine'>" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "</div></div><div id='TB_closeWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a> or Esc Key</div>");
154
155			$("#TB_closeWindowButton").click(tb_remove);
156
157			if (!(TB_PrevHTML === "")) {
158				function goPrev(){
159					if($(document).unbind("click",goPrev)){$(document).unbind("click",goPrev);}
160					$("#TB_window").remove();
161					$("body").append("<div id='TB_window'></div>");
162					tb_show(TB_PrevCaption, TB_PrevURL, imageGroup);
163					return false;
164				}
165				$("#TB_prev").click(goPrev);
166			}
167
168			if (!(TB_NextHTML === "")) {
169				function goNext(){
170					$("#TB_window").remove();
171					$("body").append("<div id='TB_window'></div>");
172					tb_show(TB_NextCaption, TB_NextURL, imageGroup);
173					return false;
174				}
175				$("#TB_next").click(goNext);
176
177			}
178
179			document.onkeydown = function(e){
180				if (e == null) { // ie
181					keycode = event.keyCode;
182				} else { // mozilla
183					keycode = e.which;
184				}
185				if(keycode == 27){ // close
186					tb_remove();
187				}
188				else if(keycode == 190){ // display previous image
189					if(!(TB_NextHTML == "")){
190						document.onkeydown = "";
191						goNext();
192					}
193				} else if(keycode == 188){ // display next image
194					if(!(TB_PrevHTML == "")){
195						document.onkeydown = "";
196						goPrev();
197					}
198				}
199			};
200
201			tb_position();
202			$("#TB_load").remove();
203			$("#TB_Image").click(tb_remove);
204			$("#TB_window").css({display:"block"}); //for safari using css instead of show
205			};
206
207			imgPreloader.src = url;
208		}
209        // Show HTML
210		else {
211			var queryString = url.replace(/^[^\?]+\??/,'');
212			var params = tb_parseQuery( queryString );
213			TB_WIDTH = Math.min(params['width'] || window.innerWidth, window.innerWidth); //Defaults to 100% if no paramaters were added to URL
214			TB_HEIGHT = Math.min(params['height'] || window.innerHeight, window.innerHeight); //Defaults to 100% if no paramaters were added to URL
215			TB_POSITION = params['position'] || ""
216      		TB_onThickboxClose = params['onThickboxClose'] || ""
217            TB_focusOnClose = params['focusOnClose'] || ""
218			ajaxContentW = TB_WIDTH;
219			ajaxContentH = TB_HEIGHT;
220
221			if (url.indexOf('TB_iframe') != -1) {// either iframe or ajax window
222					thickboxA11yTitleContextCallback = checkThickboxTitleContext(params['TB_context']);
223					urlNoQuery = url.split('TB_');
224					$("#TB_iframeContent").remove();
225					if(params['modal'] != "true"){ //iframe no modal
226						$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='javascript:void()'  id='TB_closeWindowButton' title='Close'>close</a> or Esc Key</div></div><iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW)+"px;height:"+(ajaxContentH)+"px;' > </iframe>");
227					}
228					// I-Frame & Modal
229					else {
230					    $("#TB_overlay").unbind();
231						$("#TB_window").append("<iframe frameborder='0' hspace='0' src='" + urlNoQuery[0] + "' id='TB_iframeContent' name='TB_iframeContent" + Math.round(Math.random()*1000) + "' onload='tb_showIframe()' style='width:100%;height:100%;'></iframe>");
232					}					
233			}
234			else {// not an iframe, ajax
235					console.log("Not Iframe");
236					if($("#TB_window").css("display") != "block"){
237						if(params['modal'] != "true"){//ajax no modal
238						    $("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>" + caption + "</div><div id='TB_closeAjaxWindow'><a href='javascript:void(0);' id='TB_closeWindowButton'>close</a> or Esc Key</div></div>
238<div id='TB_ajaxContent' style='width:" + ajaxContentW + "px;height:" + ajaxContentH + "px'></div>");
239						}else{//ajax modal
240						$("#TB_overlay").unbind();
241						$("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");
242						}
243					}else{//this means the window is already up, we are just loading new content via ajax
244						$("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
245						$("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
246						$("#TB_ajaxContent")[0].scrollTop = 0;
247						$("#TB_ajaxWindowTitle").html(caption);
248					}
249			}
250
251			if (params['refresh'] == "true") {
252			    $("#TB_closeWindowButton").click(function (tb_remove) {
253			        parent.location.reload(true);
254			    });
255			}
256			else {
257			    $("#TB_closeWindowButton").click(tb_remove);
258			}
259
260			if (url.indexOf('TB_inline') != -1) {
261				$("#TB_ajaxContent").append($('#' + params['inlineId']).children());
262				$("#TB_window").unload(function () {
263					$('#' + params['inlineId']).append( $("#TB_ajaxContent").children() ); // move elements back when you're finished
264				});
265				tb_position();
266				$("#TB_load").remove();
267				$("#TB_window").css({display:"block"});
268			} else if (url.indexOf('TB_iframe') != -1) {
269			    tb_position();
270			    // Safari needs help because it will not fire iframe onload
271				if ($.browser.safari) {
272					$("#TB_load").remove();
273					$("#TB_window").css({display:"block"});
274				}
275
276			} else {
277				$("#TB_ajaxContent").load(url += "&random=" + (new Date().getTime()),function(){//to do a post change this load method
278					tb_position();
279					$("#TB_load").remove();
280					tb_init("#TB_ajaxContent a.thickbox");
281					$("#TB_window").css({ display: "block" });
282				});
283			}
284		}
285
286		
287		document.onkeyup = function(e){
288			if (e == null) { // ie
289				keycode = event.keyCode;
290			} else { // mozilla
291				keycode = e.which;
292			}
293			if(keycode == 27){ // close
294				tb_remove();
295			}
296		};
297
298        lockKeyboardInsideThickbox();
299
300	} catch(e) {
301		//nothing here
302	}
303}
304
305//helper functions below
306function tb_showIframe(){
307    $("#TB_load").remove();
308    $("#TB_window").css({ display: "block" });
309	if (typeof thickboxA11yTitleContextCallback === 'function') {
310		thickboxA11yTitleContextCallback();
311	}
312    tb_in_animation();
313}
314
315function tb_remove() {
316
317    // Javascript function to run on close.
318    if (TB_onThickboxClose !== "") {
319        parent[TB_onThickboxClose]();
320    }
321
322 	$("#TB_imageOff").unbind("click");
323 	$("#TB_closeWindowButton").unbind("click");
324
325 	tb_out_animation();
326
327 	$("#TB_window").fadeOut("fast", function () {
328 	    $('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();
329 	});
330	$("#TB_load").remove();
331	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
332		$("body","html").css({height: "auto", width: "auto"});
333		$("html").css("overflow","");
334	}
335	document.onkeydown = "";
336	document.onkeyup = "";
337    unlockKeyboardOnThickboxClose();
338    if (typeof setFocusToElementFromCssSelector === "function") {
339        setFocusToElementFromCssSelector(TB_focusOnClose);
340    }
341    TB_focusOnClose = "";
342	return true;
343}
344
345 function tb_remove2() {
346  	$("#TB_imageOff").unbind("click");
347	$("#TB_overlay").unbind("click");
348 	$("#TB_closeWindowButton").unbind("click");
349	$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').remove();});
350	$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
351 	$("#TB_load").remove();
352 	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
353 		$("body","html").css({height: "auto", width: "auto"});
354 		$("html").css("overflow","");
355 	}
356 	document.onkeydown = "";
357	document.onkeyup = "";
358 	return false;
359 }
360
361 function tb_position() {
362    $("#TB_window").css({ marginLeft: '-' + parseInt((TB_WIDTH / 2), 10) + 'px', marginTop: '-' + parseInt((TB_HEIGHT / 2), 10) + 'px', width: TB_WIDTH + 'px', height: TB_HEIGHT + 'px' });
363
364     // Custom Position
365    if (TB_POSITION === "right") {
366        $("#TB_window").css({ marginLeft: '0', left: 'initial', right: '0', marginRight: '-' + parseInt(TB_WIDTH, 10) + 'px', transition: 'all .3s ease-out' });
367    }
368    else if (TB_POSITION === "left") {
369        $("#TB_window").css({ marginLeft: '-' + parseInt(TB_WIDTH, 10) + 'px', left: '0', transition: 'all .3s ease-out' });
370    }
371    else if (TB_POSITION === "top") {
372        $("#TB_window").css({ marginTop: '-' + parseInt(TB_HEIGHT, 10) + 'px', top: '0', transition: 'all .3s ease-out' });
373    }
374    else if (TB_POSITION === "bottom") {
375        $("#TB_window").css({ marginTop: '0', top: 'initial', bottom: '0', marginBottom: '-' + parseInt(TB_HEIGHT, 10) + 'px', transition: 'all .3s ease-out' });
376    }
377}
378
379 function tb_in_animation() {
380     // Custom Position In Animation
381    if (TB_POSITION === "right") {
382        window.setTimeout(function () {
383            $("#TB_window").css({ marginRight: '0px' });
384        }, 100);
385    }
386    else if (TB_POSITION === "left") {
387        window.setTimeout(function () {
388            $("#TB_window").css({ marginLeft: '0px' });
389        }, 100);
390    }
391    else if (TB_POSITION === "top") {
392        window.setTimeout(function () {
393            $("#TB_window").css({ marginTop: '0px' });
394        }, 100);
395    }
396    else if (TB_POSITION === "bottom") {
397        window.setTimeout(function () {
398            $("#TB_window").css({ marginBottom: '0px' });
399        }, 100);
400    }
401
402 }
403
404 function tb_out_animation() {
405     // Custom Position In Animation
406     if (TB_POSITION === "right") {
407             $("#TB_window").css({ marginRight: '-' + parseInt(TB_WIDTH, 10) + 'px' });
408     }
409     else if (TB_POSITION === "left") {
410             $("#TB_window").css({ marginLeft: '-' + parseInt(TB_WIDTH, 10) + 'px' });
411     }
412     else if (TB_POSITION === "top") {
413             $("#TB_window").css({ marginTop: '-' + parseInt(TB_HEIGHT, 10) + 'px' });
414     }
415     else if (TB_POSITION === "bottom") {
416             $("#TB_window").css({ marginBottom: '-' + parseInt(TB_HEIGHT, 10) + 'px' });
417     }
418
419 }
420
421function tb_parseQuery ( query ) {
422   var Params = {};
423   if ( ! query ) {return Params;}// return empty object
424   var Pairs = query.split(/[;&]/);
425   for ( var i = 0; i < Pairs.length; i++ ) {
426      var KeyVal = Pairs[i].split('=');
427      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
428      var key = unescape( KeyVal[0] );
429      var val = unescape( KeyVal[1] );
430      val = val.replace(/\+/g, ' ');
431      Params[key] = val;
432   }
433   return Params;
434}
435
436function tb_getPageSize(){
437	var de = document.documentElement;
438	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
439	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
440	arrayPageSize = [w,h];
441	return arrayPageSize;
442}
443
444function tb_detectMacXFF() {
445  var userAgent = navigator.userAgent.toLowerCase();
446  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
447    return true;
448  }
449}
450
451function setFocusThickboxIframe() {
452	var iframe = $("#TB_iframeContent");
453    if (iframe.length > 0) iframe[0].contentWindow.focus();    
454}
455
456//Addition escape key function
457$('#TB_iframeContent').ready(function(){
458
459    setTimeout(function(){
460        $(window).keyup(function(e){
461                  if(e.keyCode == 27){
462                    $('#TB_closeWindowButton').click();
463          }
464            });
465        }, 50);
466
467});
468
469/* CampusGroups A11Y (2025) - Thickbox iFrame aria-label and title text */
470if (typeof window.checkThickboxTitleContext !== 'function') {
471	window.checkThickboxTitleContext = function checkThickboxTitleContext(urlTBContext) {
472		let tbContext = (urlTBContext || '').split('_').join(' ').trim();
473		if (tbContext.length === 0) return null;
474		// Return a function (callback) that can be invoked later to set the iFrame aria-label and iFrame content title
475		return function callback() {
476			let iframe = $('iframe#TB_iframeContent');
477			iframe.attr('aria-label', tbContext);
478			let iframeDoc = iframe.contents();
479			iframeDoc.find('head title').text(tbContext);
480		};
481	};
482}

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.