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
8 var tb_pathToImage = '/documents/img/sgn_logo_animated.gif'; //"images/loadingAnimation.gif";
10 /*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/
11 /////////////////////////
12 /*Comment by Naama Menda (Feb. 2009):
13 * calling jQeury.noConflict() in jQuery.init() function
14 * so this object will not override the '$' namespace used in Prototype.js
15 * sub classes using jQuery (see thickbox.js) must use the jQuery namespace instead of '$'
17 ///////////////////////
18 // meaningless comment delete me. just testing version control.
21 //on page load call tb_init
22 jQuery(document).ready(function(){
23 tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
24 imgLoader = new Image();// preload image
25 imgLoader.src = tb_pathToImage;
28 //add thickbox to href & area elements that have a class of .thickbox
29 function tb_init(domChunk){
30 jQuery(domChunk).click(function(){
31 var t = this.title || this.name || null;
32 var a = this.href || this.alt;
33 var g = this.rel || false;
40 function tb_show(caption, url, imageGroup) {//function called when the user clicks on a thickbox link
43 if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
44 jQuery("body","html").css({height: "100%", width: "100%"});
45 jQuery("html").css("overflow","hidden");
46 if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
47 jQuery("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
48 jQuery("#TB_overlay").click(tb_remove);
51 if(document.getElementById("TB_overlay") === null){
52 jQuery("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
53 jQuery("#TB_overlay").click(tb_remove);
57 if(tb_detectMacXFF()){
58 jQuery("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
60 jQuery("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
63 if(caption===null){caption="";}
64 jQuery("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
65 jQuery('#TB_load').show();//show loader
68 if(url.indexOf("?")!==-1){ //ff there is a query string involved
69 baseURL = url.substr(0, url.indexOf("?"));
74 var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
75 var urlType = baseURL.toLowerCase().match(urlString);
77 if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){//code to show images
88 TB_TempArray = jQuery("a[@rel="+imageGroup+"]").get();
89 for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML === "")); TB_Counter++) {
90 var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString);
91 if (!(TB_TempArray[TB_Counter].href == url)) {
93 TB_NextCaption = TB_TempArray[TB_Counter].title;
94 TB_NextURL = TB_TempArray[TB_Counter].href;
95 TB_NextHTML = "<span id='TB_next'> <a href='#'>Next ></a></span>";
97 TB_PrevCaption = TB_TempArray[TB_Counter].title;
98 TB_PrevURL = TB_TempArray[TB_Counter].href;
99 TB_PrevHTML = "<span id='TB_prev'> <a href='#'>< Prev</a></span>";
103 TB_imageCount = "Image " + (TB_Counter + 1) +" of "+ (TB_TempArray.length);
108 imgPreloader = new Image();
109 imgPreloader.onload = function(){
110 imgPreloader.onload = null;
112 // Resizing large images - orginal by Christian Montoya edited by me.
113 var pagesize = tb_getPageSize();
114 var x = pagesize[0] - 150;
115 var y = pagesize[1] - 150;
116 var imageWidth = imgPreloader.width;
117 var imageHeight = imgPreloader.height;
118 if (imageWidth > x) {
119 imageHeight = imageHeight * (x / imageWidth);
121 if (imageHeight > y) {
122 imageWidth = imageWidth * (y / imageHeight);
125 } else if (imageHeight > y) {
126 imageWidth = imageWidth * (y / imageHeight);
128 if (imageWidth > x) {
129 imageHeight = imageHeight * (x / imageWidth);
135 TB_WIDTH = imageWidth + 30;
136 TB_HEIGHT = imageHeight + 60;
137 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> or Esc Key</div>");
139 jQuery("#TB_closeWindowButton").click(tb_remove);
141 if (!(TB_PrevHTML === "")) {
143 if(jQuery(document).unbind("click",goPrev)){jQuery(document).unbind("click",goPrev);}
144 jQuery("#TB_window").remove();
145 jQuery("body").append("<div id='TB_window'></div>");
146 tb_show(TB_PrevCaption, TB_PrevURL, imageGroup);
149 jQuery("#TB_prev").click(goPrev);
152 if (!(TB_NextHTML === "")) {
154 jQuery("#TB_window").remove();
155 jQuery("body").append("<div id='TB_window'></div>");
156 tb_show(TB_NextCaption, TB_NextURL, imageGroup);
159 jQuery("#TB_next").click(goNext);
163 document.onkeydown = function(e){
164 if (e == null) { // ie
165 keycode = event.keyCode;
169 if(keycode == 27){ // close
171 } else if(keycode == 190){ // display previous image
172 if(!(TB_NextHTML == "")){
173 document.onkeydown = "";
176 } else if(keycode == 188){ // display next image
177 if(!(TB_PrevHTML == "")){
178 document.onkeydown = "";
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
190 imgPreloader.src = url;
191 }else{//code to show html
193 var queryString = url.replace(/^[^\?]+\??/,'');
194 var params = tb_parseQuery( queryString );
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;
201 if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window
202 urlNoQuery = url.split('TB_');
203 jQuery("#TB_iframeContent").remove();
204 if(params['modal'] != "true"){//iframe no modal
205 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> 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 + 29)+"px;height:"+(ajaxContentH + 17)+"px;' > </iframe>");
207 jQuery("#TB_overlay").unbind();
208 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 }else{// not an iframe, ajax
211 if(jQuery("#TB_window").css("display") != "block"){
212 if(params['modal'] != "true"){//ajax no modal
213 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> or Esc Key</div></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>");
215 jQuery("#TB_overlay").unbind();
216 jQuery("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");
218 }else{//this means the window is already up, we are just loading new content via ajax
219 jQuery("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
220 jQuery("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
221 jQuery("#TB_ajaxContent")[0].scrollTop = 0;
222 jQuery("#TB_ajaxWindowTitle").html(caption);
226 jQuery("#TB_closeWindowButton").click(tb_remove);
228 if(url.indexOf('TB_inline') != -1){
229 jQuery("#TB_ajaxContent").append(jQuery('#' + params['inlineId']).children());
230 jQuery("#TB_window").unload(function () {
231 jQuery('#' + params['inlineId']).append( jQuery("#TB_ajaxContent").children() ); // move elements back when you're finished
234 jQuery("#TB_load").remove();
235 jQuery("#TB_window").css({display:"block"});
236 }else if(url.indexOf('TB_iframe') != -1){
238 if(jQuery.browser.safari){//safari needs help because it will not fire iframe onload
239 jQuery("#TB_load").remove();
240 jQuery("#TB_window").css({display:"block"});
243 jQuery("#TB_ajaxContent").load(url += "&random=" + (new Date().getTime()),function(){//to do a post change this load method
245 jQuery("#TB_load").remove();
246 tb_init("#TB_ajaxContent a.thickbox");
247 jQuery("#TB_window").css({display:"block"});
253 if(!params['modal']){
254 document.onkeyup = function(e){
255 if (e == null) { // ie
256 keycode = event.keyCode;
260 if(keycode == 27){ // close
271 //helper functions below
272 function tb_showIframe(){
273 jQuery("#TB_load").remove();
274 jQuery("#TB_window").css({display:"block"});
277 function tb_remove() {
278 jQuery("#TB_imageOff").unbind("click");
279 jQuery("#TB_closeWindowButton").unbind("click");
280 jQuery("#TB_window").fadeOut("fast",function(){jQuery('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
281 jQuery("#TB_load").remove();
282 if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
283 jQuery("body","html").css({height: "auto", width: "auto"});
284 jQuery("html").css("overflow","");
286 document.onkeydown = "";
287 document.onkeyup = "";
291 function tb_position() {
292 jQuery("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
293 if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
294 jQuery("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
298 function tb_parseQuery ( query ) {
300 if ( ! query ) {return Params;}// return empty object
301 var Pairs = query.split(/[;&]/);
302 for ( var i = 0; i < Pairs.length; i++ ) {
303 var KeyVal = Pairs[i].split('=');
304 if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
305 var key = unescape( KeyVal[0] );
306 var val = unescape( KeyVal[1] );
307 val = val.replace(/\+/g, ' ');
313 function tb_getPageSize(){
314 var de = document.documentElement;
315 var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
316 var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
317 arrayPageSize = [w,h];
318 return arrayPageSize;
321 function tb_detectMacXFF() {
322 var userAgent = navigator.userAgent.toLowerCase();
323 if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {