PageSourceSearch

https://gdcvault.com/js/thickbox.js

js gdcvault.com collected 2026-10-01 08:44:22 UTC 12,299 bytes, 332 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		  
8var tb_pathToImage = ImageURL + "/loadingAnimation.gif";
9
10// close button layout.
11var closeBtn = '<img src=\'/img/gdc_vault/xClose.png\' />';
12
13
14
15/*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/
16
17//on page load call tb_init
18$(document).ready(function(){   
19	tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
20	imgLoader = new Image();// preload image
21	imgLoader.src = tb_pathToImage;
22});
23
24//add thickbox to href & area elements that have a class of .thickbox
25function tb_init(domChunk){
26	$(domChunk).on("click", function(){
27	var t = this.title || this.name || null;
28	var a = this.href || this.alt;
29	var g = this.rel || false;
30	tb_show(t,a,g);
31	this.blur();
32	return false;
33	});
34}
35
36function tb_show(caption, url, imageGroup) {//function called when the user clicks on a thickbox link
37
38	try {
39		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
40			$("body","html").css({height: "100%", width: "100%"});
41			$("html").css("overflow","hidden");
42			if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
43				$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
44				$("#TB_overlay").on('click', tb_remove);
45			}
46		}else{//all others
47			if(document.getElementById("TB_overlay") === null){
48				$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
49				$("#TB_overlay").on('click', tb_remove);
50			}
51		}
52		
53		if(tb_detectMacXFF()){
54			$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
55		}else{
56			$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
57		}
58		
59		if(caption===null){caption="";}
60		$("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
61		$('#TB_load').show();//show loader
62		
63		var baseURL;
64	   if(url.indexOf("?")!==-1){ //ff there is a query string involved
65			baseURL = url.substr(0, url.indexOf("?"));
66	   }else{ 
67	   		baseURL = url;
68	   }
69	   
70	   var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
71	   var urlType = baseURL.toLowerCase().match(urlString);
72
73		if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){//code to show images
74				
75			TB_PrevCaption = "";
76			TB_PrevURL = "";
77			TB_PrevHTML = "";
78			TB_NextCaption = "";
79			TB_NextURL = "";
80			TB_NextHTML = "";
81			TB_imageCount = "";
82			TB_FoundURL = false;
83			if(imageGroup){
84				TB_TempArray = $("a[@rel="+imageGroup+"]").get();
85				for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML === "")); TB_Counter++) {
86					var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString);
87						if (!(TB_TempArray[TB_Counter].href == url)) {						
88							if (TB_FoundURL) {
89								TB_NextCaption = TB_TempArray[TB_Counter].title;
90								TB_NextURL = TB_TempArray[TB_Counter].href;
91								TB_NextHTML = "<span id='TB_next'>&nbsp;&nbsp;<a href='#'>Next &gt;</a></span>";
92							} else {
93								TB_PrevCaption = TB_TempArray[TB_Counter].title;
94								TB_PrevURL = TB_TempArray[TB_Counter].href;
95								TB_PrevHTML = "<span id='TB_prev'>&nbsp;&nbsp;<a href='#'>&lt; Prev</a></span>";
96							}
97						} else {
98							TB_FoundURL = true;
99							TB_imageCount = "Image " + (TB_Counter + 1) +" of "+ (TB_TempArray.length);											
100						}
101				}
102			}
103
104			imgPreloader = new Image();
105			imgPreloader.onload = function(){		
106			imgPreloader.onload = null;
107				
108			// Resizing large images - orginal by Christian Montoya edited by me.
109			var pagesize = tb_getPageSize();
110			var x = pagesize[0] - 150;
111			var y = pagesize[1] - 150;
112			var imageWidth = imgPreloader.width;
113			var imageHeight = imgPreloader.height;
114			if (imageWidth > x) {
115				imageHeight = imageHeight * (x / imageWidth); 
116				imageWidth = x; 
117				if (imageHeight > y) { 
118					imageWidth = imageWidth * (y / imageHeight); 
119					imageHeight = y; 
120				}
121			} else if (imageHeight > y) { 
122				imageWidth = imageWidth * (y / imageHeight); 
123				imageHeight = y; 
124				if (imageWidth > x) { 
125					imageHeight = imageHeight * (x / imageWidth); 
126					imageWidth = x;
127				}
128			}
129			// End Resizing
130			
131			TB_WIDTH = imageWidth + 30;
132			TB_HEIGHT = imageHeight + 60;
133			$("#TB_window").append("<a href='' id='TB_ImageOff' title='Close'><img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/></a>" + "<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'>" + closeBtn + "</a></div>"); 		
134			
135			$("#TB_closeWindowButton").on('click', tb_remove);
136			
137			if (!(TB_PrevHTML === "")) {
138				function goPrev(){
139					if($(document).unbind("click",goPrev)){$(document).unbind("click",goPrev);}
140					$("#TB_window").remove();
141					$("body").append("<div id='TB_window'></div>");
142					tb_show(TB_PrevCaption, TB_PrevURL, imageGroup);
143					return false;	
144				}
145				$("#TB_prev").click(goPrev);
146			}
147			
148			if (!(TB_NextHTML === "")) {		
149				function goNext(){
150					$("#TB_window").remove();
151					$("body").append("<div id='TB_window'></div>");
152					tb_show(TB_NextCaption, TB_NextURL, imageGroup);				
153					return false;	
154				}
155				$("#TB_next").click(goNext);
156				
157			}
158
159			document.onkeydown = function(e){ 	
160				if (e == null) { // ie
161					keycode = event.keyCode;
162				} else { // mozilla
163					keycode = e.which;
164				}
165				if(keycode == 27){ // close
166					tb_remove();
167				} else if(keycode == 190){ // display previous image
168					if(!(TB_NextHTML == "")){
169						document.onkeydown = "";
170						goNext();
171					}
172				} else if(keycode == 188){ // display next image
173					if(!(TB_PrevHTML == "")){
174						document.onkeydown = "";
175						goPrev();
176					}
177				}	
178			};
179			
180			tb_position();
181			$("#TB_load").remove();
182			$("#TB_ImageOff").click(tb_remove);
183			$("#TB_window").css({display:"block"}); //for safari using css instead of show
184			};
185			
186			imgPreloader.src = url;
187		}else{//code to show html
188			
189			var queryString = url.replace(/^[^\?]+\??/,'');
190			var params = tb_parseQuery( queryString );
191			let browserWidth = $(window).width() - 20; //make sure there is some padding for full width or scrollbars won't show
192			let browserHeight = $(window).height() - 20; //make sure there is some padding for full height or scrollbars won't show
193			let paramsWidth = (params['width']*1) + 30 || 630; //defaults to 630 if no parameters were added to URL
194			let paramsHeight = (params['height']*1) + 40 || 440; //defaults to 440 if no parameters were added to URL
195
196			TB_WIDTH = (paramsWidth > browserWidth) ? browserWidth : paramsWidth; //don't exceed browser width
197			TB_HEIGHT = (paramsHeight > browserHeight) ? browserHeight : paramsHeight; //don't exceed browser height
198			ajaxContentW = TB_WIDTH - 30;
199			ajaxContentH = TB_HEIGHT - 45;
200			
201			if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window		
202					urlNoQuery = url.split('TB_');
203					$("#TB_iframeContent").remove();
204					if(params['modal'] != "true"){//iframe no modal
205						$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'>" + closeBtn + "</a></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 + 29)+"px;height:"+(ajaxContentH + 17)+"px;' > </iframe>");
206					}else{//iframe modal
207					$("#TB_overlay").unbind();
208						$("#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:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;'> </iframe>");
209					}
210			}else{// not an iframe, ajax
211					if($("#TB_window").css("display") != "block"){
212						if(params['modal'] != "true"){//ajax no modal
213						$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'>close</a></div></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>");
214						}else{//ajax modal
215						$("#TB_overlay").unbind();
216						$("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");	
217						}
218					}else{//this means the window is already up, we are just loading new content via ajax
219						$("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
220						$("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
221						$("#TB_ajaxContent")[0].scrollTop = 0;
222						$("#TB_ajaxWindowTitle").html(caption);
223					}
224			}
225					
226			$("#TB_closeWindowButton").on('click', tb_remove);
227
228				if(url.indexOf('TB_inline') != -1){	
229					$("#TB_ajaxContent").append($('#' + params['inlineId']).children());
230					$("#TB_window").unload(function () {
231						$('#' + params['inlineId']).append( $("#TB_ajaxContent").children() ); // move elements back when you're finished
232					});
233					tb_position();
234					$("#TB_load").remove();
235					$("#TB_window").css({display:"block"}); 
236				}else if(url.indexOf('TB_iframe') != -1){
237					tb_position();
238					if($.browser.safari){//safari needs help because it will not fire iframe onload
239						$("#TB_load").remove();
240						$("#TB_window").css({display:"block"});
241					}
242				}else{
243					$("#TB_ajaxContent").load(url += "&random=" + (new Date().getTime()),function(){//to do a post change this load method
244						tb_position();
245						$("#TB_load").remove();
246						tb_init("#TB_ajaxContent a.thickbox");
247						$("#TB_window").css({display:"block"});
248					});
249				}
250			
251		}
252
253		if(!params['modal']){
254			document.onkeyup = function(e){ 	
255				if (e == null) { // ie
256					keycode = event.keyCode;
257				} else { // mozilla
258					keycode = e.which;
259				}
260				if(keycode == 27){ // close
261					tb_remove();
262				}	
263			};
264		}
265		
266	} catch(e) {
267		//nothing here
268	}
269}
270
271//helper functions below
272function tb_showIframe(){
273	$("#TB_load").remove();
274	$("#TB_window").css({display:"block"});
275
276	$iframeBody = $("#TB_window > iframe").contents().find("body");
277	$iframeBody.addClass("iframeBody");
278}
279
280function tb_remove() {
281 	$("#TB_imageOff").off("click");
282	$("#TB_closeWindowButton").off("click");
283	$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").off().remove();});
284	$("#TB_load").remove();
285	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
286		$("body","html").css({height: "auto", width: "auto"});
287		$("html").css("overflow","");
288	}
289	document.onkeydown = "";
290	document.onkeyup = "";
291	return false;
292}
293
294function tb_position() {
295$("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
296	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
297		$("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
298	}
299}
300
301function tb_parseQuery ( query ) {
302   var Params = {};
303   if ( ! query ) {return Params;}// return empty object
304   var Pairs = query.split(/[;&]/);
305   for ( var i = 0; i < Pairs.length; i++ ) {
306      var KeyVal = Pairs[i].split('=');
307      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
308      var key = unescape( KeyVal[0] );
309      var val = unescape( KeyVal[1] );
310      val = val.replace(/\+/g, ' ');
311      Params[key] = val;
312   }
313   return Params;
314}
315
316function tb_getPageSize(){
317	var de = document.documentElement;
318	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
319	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
320	arrayPageSize = [w,h];
321	return arrayPageSize;
322}
323
324function tb_detectMacXFF() {
325  var userAgent = navigator.userAgent.toLowerCase();
326  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
327    return true;
328  }
329}
330
331
332

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.