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 ///////////////////////
20 //on page load call tb_init
21 jQuery(document
).ready(function(){
22 tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
23 imgLoader
= new Image();// preload image
24 imgLoader
.src
= tb_pathToImage
;
27 //add thickbox to href & area elements that have a class of .thickbox
28 function tb_init(domChunk
){
29 jQuery(domChunk
).click(function(){
30 var t
= this.title
|| this.name
|| null;
31 var a
= this.href
|| this.alt
;
32 var g
= this.rel
|| false;
39 function tb_show(caption
, url
, imageGroup
) {//function called when the user clicks on a thickbox link
42 if (typeof document
.body
.style
.maxHeight
=== "undefined") {//if IE 6
43 jQuery("body","html").css({height
: "100%", width
: "100%"});
44 jQuery("html").css("overflow","hidden");
45 if (document
.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
46 jQuery("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
47 jQuery("#TB_overlay").click(tb_remove
);
50 if(document
.getElementById("TB_overlay") === null){
51 jQuery("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
52 jQuery("#TB_overlay").click(tb_remove
);
56 if(tb_detectMacXFF()){
57 jQuery("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
59 jQuery("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
62 if(caption
===null){caption
="";}
63 jQuery("body").append("<div id='TB_load'><img src='"+imgLoader
.src
+"' /></div>");//add loader to the page
64 jQuery('#TB_load').show();//show loader
67 if(url
.indexOf("?")!==-1){ //ff there is a query string involved
68 baseURL
= url
.substr(0, url
.indexOf("?"));
73 var urlString
= /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
74 var urlType
= baseURL
.toLowerCase().match(urlString
);
76 if(urlType
== '.jpg' || urlType
== '.jpeg' || urlType
== '.png' || urlType
== '.gif' || urlType
== '.bmp'){//code to show images
87 TB_TempArray
= jQuery("a[@rel="+imageGroup
+"]").get();
88 for (TB_Counter
= 0; ((TB_Counter
< TB_TempArray
.length
) && (TB_NextHTML
=== "")); TB_Counter
++) {
89 var urlTypeTemp
= TB_TempArray
[TB_Counter
].href
.toLowerCase().match(urlString
);
90 if (!(TB_TempArray
[TB_Counter
].href
== url
)) {
92 TB_NextCaption
= TB_TempArray
[TB_Counter
].title
;
93 TB_NextURL
= TB_TempArray
[TB_Counter
].href
;
94 TB_NextHTML
= "<span id='TB_next'> <a href='#'>Next ></a></span>";
96 TB_PrevCaption
= TB_TempArray
[TB_Counter
].title
;
97 TB_PrevURL
= TB_TempArray
[TB_Counter
].href
;
98 TB_PrevHTML
= "<span id='TB_prev'> <a href='#'>< Prev</a></span>";
102 TB_imageCount
= "Image " + (TB_Counter
+ 1) +" of "+ (TB_TempArray
.length
);
107 imgPreloader
= new Image();
108 imgPreloader
.onload = function(){
109 imgPreloader
.onload
= null;
111 // Resizing large images - orginal by Christian Montoya edited by me.
112 var pagesize
= tb_getPageSize();
113 var x
= pagesize
[0] - 150;
114 var y
= pagesize
[1] - 150;
115 var imageWidth
= imgPreloader
.width
;
116 var imageHeight
= imgPreloader
.height
;
117 if (imageWidth
> x
) {
118 imageHeight
= imageHeight
* (x
/ imageWidth
);
120 if (imageHeight
> y
) {
121 imageWidth
= imageWidth
* (y
/ imageHeight
);
124 } else if (imageHeight
> y
) {
125 imageWidth
= imageWidth
* (y
/ imageHeight
);
127 if (imageWidth
> x
) {
128 imageHeight
= imageHeight
* (x
/ imageWidth
);
134 TB_WIDTH
= imageWidth
+ 30;
135 TB_HEIGHT
= imageHeight
+ 60;
136 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>");
138 jQuery("#TB_closeWindowButton").click(tb_remove
);
140 if (!(TB_PrevHTML
=== "")) {
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
);
148 jQuery("#TB_prev").click(goPrev
);
151 if (!(TB_NextHTML
=== "")) {
153 jQuery("#TB_window").remove();
154 jQuery("body").append("<div id='TB_window'></div>");
155 tb_show(TB_NextCaption
, TB_NextURL
, imageGroup
);
158 jQuery("#TB_next").click(goNext
);
162 document
.onkeydown = function(e
){
163 if (e
== null) { // ie
164 keycode
= event
.keyCode
;
168 if(keycode
== 27){ // close
170 } else if(keycode
== 190){ // display previous image
171 if(!(TB_NextHTML
== "")){
172 document
.onkeydown
= "";
175 } else if(keycode
== 188){ // display next image
176 if(!(TB_PrevHTML
== "")){
177 document
.onkeydown
= "";
184 jQuery("#TB_load").remove();
185 jQuery("#TB_ImageOff").click(tb_remove
);
186 jQuery("#TB_window").css({display
:"block"}); //for safari using css instead of show
189 imgPreloader
.src
= url
;
190 }else{//code to show html
192 var queryString
= url
.replace(/^[^\?]+\??/,'');
193 var params
= tb_parseQuery( queryString
);
195 TB_WIDTH
= (params
['width']*1) + 30 || 630; //defaults to 630 if no paramaters were added to URL
196 TB_HEIGHT
= (params
['height']*1) + 40 || 440; //defaults to 440 if no paramaters were added to URL
197 ajaxContentW
= TB_WIDTH
- 30;
198 ajaxContentH
= TB_HEIGHT
- 45;
200 if(url
.indexOf('TB_iframe') != -1){// either iframe or ajax window
201 urlNoQuery
= url
.split('TB_');
202 jQuery("#TB_iframeContent").remove();
203 if(params
['modal'] != "true"){//iframe no modal
204 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>");
206 jQuery("#TB_overlay").unbind();
207 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>");
209 }else{// not an iframe, ajax
210 if(jQuery("#TB_window").css("display") != "block"){
211 if(params
['modal'] != "true"){//ajax no modal
212 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>");
214 jQuery("#TB_overlay").unbind();
215 jQuery("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW
+"px;height:"+ajaxContentH
+"px;'></div>");
217 }else{//this means the window is already up, we are just loading new content via ajax
218 jQuery("#TB_ajaxContent")[0].style
.width
= ajaxContentW
+"px";
219 jQuery("#TB_ajaxContent")[0].style
.height
= ajaxContentH
+"px";
220 jQuery("#TB_ajaxContent")[0].scrollTop
= 0;
221 jQuery("#TB_ajaxWindowTitle").html(caption
);
225 jQuery("#TB_closeWindowButton").click(tb_remove
);
227 if(url
.indexOf('TB_inline') != -1){
228 jQuery("#TB_ajaxContent").append(jQuery('#' + params
['inlineId']).children());
229 jQuery("#TB_window").unload(function () {
230 jQuery('#' + params
['inlineId']).append( jQuery("#TB_ajaxContent").children() ); // move elements back when you're finished
233 jQuery("#TB_load").remove();
234 jQuery("#TB_window").css({display
:"block"});
235 }else if(url
.indexOf('TB_iframe') != -1){
237 if(jQuery
.browser
.safari
){//safari needs help because it will not fire iframe onload
238 jQuery("#TB_load").remove();
239 jQuery("#TB_window").css({display
:"block"});
242 jQuery("#TB_ajaxContent").load(url
+= "&random=" + (new Date().getTime()),function(){//to do a post change this load method
244 jQuery("#TB_load").remove();
245 tb_init("#TB_ajaxContent a.thickbox");
246 jQuery("#TB_window").css({display
:"block"});
252 if(!params
['modal']){
253 document
.onkeyup = function(e
){
254 if (e
== null) { // ie
255 keycode
= event
.keyCode
;
259 if(keycode
== 27){ // close
270 //helper functions below
271 function tb_showIframe(){
272 jQuery("#TB_load").remove();
273 jQuery("#TB_window").css({display
:"block"});
276 function tb_remove() {
277 jQuery("#TB_imageOff").unbind("click");
278 jQuery("#TB_closeWindowButton").unbind("click");
279 jQuery("#TB_window").fadeOut("fast",function(){jQuery('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
280 jQuery("#TB_load").remove();
281 if (typeof document
.body
.style
.maxHeight
== "undefined") {//if IE 6
282 jQuery("body","html").css({height
: "auto", width
: "auto"});
283 jQuery("html").css("overflow","");
285 document
.onkeydown
= "";
286 document
.onkeyup
= "";
290 function tb_position() {
291 jQuery("#TB_window").css({marginLeft
: '-' + parseInt((TB_WIDTH
/ 2),10) + 'px', width
: TB_WIDTH
+ 'px'});
292 if ( !(jQuery
.browser
.msie
&& jQuery
.browser
.version
< 7)) { // take away IE6
293 jQuery("#TB_window").css({marginTop
: '-' + parseInt((TB_HEIGHT
/ 2),10) + 'px'});
297 function tb_parseQuery ( query
) {
299 if ( ! query
) {return Params
;}// return empty object
300 var Pairs
= query
.split(/[;&]/);
301 for ( var i
= 0; i
< Pairs
.length
; i
++ ) {
302 var KeyVal
= Pairs
[i
].split('=');
303 if ( ! KeyVal
|| KeyVal
.length
!= 2 ) {continue;}
304 var key
= unescape( KeyVal
[0] );
305 var val
= unescape( KeyVal
[1] );
306 val
= val
.replace(/\+/g, ' ');
312 function tb_getPageSize(){
313 var de
= document
.documentElement
;
314 var w
= window
.innerWidth
|| self
.innerWidth
|| (de
&&de
.clientWidth
) || document
.body
.clientWidth
;
315 var h
= window
.innerHeight
|| self
.innerHeight
|| (de
&&de
.clientHeight
) || document
.body
.clientHeight
;
316 arrayPageSize
= [w
,h
];
317 return arrayPageSize
;
320 function tb_detectMacXFF() {
321 var userAgent
= navigator
.userAgent
.toLowerCase();
322 if (userAgent
.indexOf('mac') != -1 && userAgent
.indexOf('firefox')!=-1) {