PageSourceSearch

http://www.activa.com.au/js/thickbox.js

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

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.