1/* 2 * Thickbox 3.1 - One Box To Rule Them All. 3 4* By Cody Lindley (http://www.codylindley.com) 5 6* Copyright (c) 2007 cody lindley 7 8* Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php 9*/ 10 11 12 13//var tb_pathToImage = 'images/loading.gif'; 14 15 16 17/*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/ 18 19 20//on page load call tb_init 21$(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; 25}); 26 27//add thickbox to href & area elements that have a class of .thickbox 28function tb_init(domChunk){ 29 $(domChunk).click(function(){ 30 var t = this.title || this.name || null; 31 var a = this.href || this.alt; 32 var g = this.rel || false; 33 tb_show(t,a,g); 34 this.blur(); 35 return false; 36 }); 37} 38 39function tb_show(caption, url, imageGroup) {//function called when the user clicks on a thickbox link 40 41 try { 42 if (typeof document.body.style.maxHeight === "undefined") {//if IE 6 43 $("body","html").css({height: "100%", width: "100%"}); 44 $("html").css("overflow","hidden"); 45 if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6 46 $("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>"); 47 $("#TB_overlay").click(tb_remove); 48 } 49 }else{//all others 50 if(document.getElementById("TB_overlay") === null){ 51 $("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>"); 52 $("#TB_overlay").click(tb_remove); 53 } 54 } 55 56 if(tb_detectMacXFF()){ 57 $("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash 58 }else{ 59 $("#TB_overlay").addClass("TB_overlayBG");//use background and opacity 60 } 61 62 if(caption===null){caption="";} 63 $("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page 64 $('#TB_load').show();//show loader 65 66 var baseURL; 67 if(url.indexOf("?")!==-1){ //ff there is a query string involved 68 baseURL = url.substr(0, url.indexOf("?")); 69 }else{ 70 baseURL = url; 71 } 72 73 var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/; 74 var urlType = baseURL.toLowerCase().match(urlString); 75 76 if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){//code to show images 77 78 TB_PrevCaption = ""; 79 TB_PrevURL = ""; 80 TB_PrevHTML = ""; 81 TB_NextCaption = ""; 82 TB_NextURL = ""; 83 TB_NextHTML = ""; 84 TB_imageCount = ""; 85 TB_FoundURL = false; 86 if(imageGroup){ 87 TB_TempArray = $("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)) { 91 if (TB_FoundURL) { 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>"; 95 } else { 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>"; 99 } 100 } else { 101 TB_FoundURL = true; 102 TB_imageCount = "Image " + (TB_Counter + 1) +" of "+ (TB_TempArray.length); 103 } 104 } 105 } 106 107 imgPreloader = new Image(); 108 imgPreloader.onload = function(){ 109 imgPreloader.onload = null; 110 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); 119 imageWidth = x; 120 if (imageHeight > y) { 121 imageWidth = imageWidth * (y / imageHeight); 122 imageHeight = y; 123 } 124 } else if (imageHeight > y) { 125 imageWidth = imageWidth * (y / imageHeight); 126 imageHeight = y; 127 if (imageWidth > x) { 128 imageHeight = imageHeight * (x / imageWidth); 129 imageWidth = x; 130 } 131 } 132 // End Resizing 133 134 TB_WIDTH = imageWidth + 30; 135 TB_HEIGHT = imageHeight + 60; 136 $("#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>"); 137 138 $("#TB_closeWindowButton").click(tb_remove); 139 140 if (!(TB_PrevHTML === "")) { 141 function goPrev(){ 142 if($(document).unbind("click",goPrev)){$(document).unbind("click",goPrev);} 143 $("#TB_window").remove(); 144 $("body").append("<div id='TB_window'></div>"); 145 tb_show(TB_PrevCaption, TB_PrevURL, imageGroup); 146 return false; 147 } 148 $("#TB_prev").click(goPrev); 149 } 150 151 if (!(TB_NextHTML === "")) { 152 function goNext(){ 153 $("#TB_window").remove(); 154 $("body").append("<div id='TB_window'></div>"); 155 tb_show(TB_NextCaption, TB_NextURL, imageGroup); 156 return false; 157 } 158 $("#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 } else if(keycode == 190){ // display previous image 171 if(!(TB_NextHTML == "")){ 172 document.onkeydown = ""; 173 goNext(); 174 } 175 } else if(keycode == 188){ // display next image 176 if(!(TB_PrevHTML == "")){ 177 document.onkeydown = ""; 178 goPrev(); 179 } 180 } 181 }; 182 183 tb_position(); 184 $("#TB_load").remove(); 185 $("#TB_ImageOff").click(tb_remove); 186 $("#TB_window").css({display:"block"}); //for safari using css instead of show 187 }; 188 189 imgPreloader.src = url; 190 }else{//code to show html 191 192 var queryString = url.replace(/^[^\?]+\??/,''); 193 var params = tb_parseQuery( queryString ); 194 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; 199 200 if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window 201 urlNoQuery = url.split('TB_'); 202 $("#TB_iframeContent").remove(); 203 if(params['modal'] != "true"){//iframe no modal 204 $("#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>"); 205 }else{//iframe modal 206 $("#TB_overlay").unbind(); 207 $("#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>"); 208 } 209 }else{// not an iframe, ajax 210 if($("#TB_window").css("display") != "block"){ 211 if(params['modal'] != "true"){//ajax no modal 212 $("#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>"); 213 }else{//ajax modal 214 $("#TB_overlay").unbind(); 215 $("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>"); 216 } 217 }else{//this means the window is already up, we are just loading new content via ajax 218 $("#TB_ajaxContent")[0].style.width = ajaxContentW +"px"; 219 $("#TB_ajaxContent")[0].style.height = ajaxContentH +"px"; 220 $("#TB_ajaxContent")[0].scrollTop = 0; 221 $("#TB_ajaxWindowTitle").html(caption); 222 } 223 } 224 225 $("#TB_closeWindowButton").click(tb_remove); 226 227 if(url.indexOf('TB_inline') != -1){ 228 $("#TB_ajaxContent").append($('#' + params['inlineId']).children()); 229 $("#TB_window").unload(function () { 230 $('#' + params['inlineId']).append( $("#TB_ajaxContent").children() ); // move elements back when you're finished 231 }); 232 tb_position(); 233 $("#TB_load").remove(); 234 $("#TB_window").css({display:"block"}); 235 }else if(url.indexOf('TB_iframe') != -1){ 236 tb_position(); 237 if($.browser.safari){//safari needs help because it will not fire iframe onload 238 $("#TB_load").remove(); 239 $("#TB_window").css({display:"block"}); 240 } 241 }else{ 242 $("#TB_ajaxContent").load(url += "&random=" + (new Date().getTime()),function(){//to do a post change this load method 243 tb_position(); 244 $("#TB_load").remove(); 245 tb_init("#TB_ajaxContent a.thickbox"); 246 $("#TB_window").css({display:"block"}); 247 }); 248 } 249 250 } 251 252 if(!params['modal']){ 253 document.onkeyup = function(e){ 254 if (e == null) { // ie 255 keycode = event.keyCode; 256 } else { // mozilla 257 keycode = e.which; 258 } 259 if(keycode == 27){ // close 260 tb_remove(); 261 } 262 }; 263 } 264 265 } catch(e) { 266 //nothing here 267 } 268} 269 270//helper functions below 271function tb_showIframe(){ 272 $("#TB_load").remove(); 273 $("#TB_window").css({display:"block"}); 274} 275 276function tb_remove() { 277 $("#TB_imageOff").unbind("click"); 278 $("#TB_closeWindowButton").unbind("click"); 279 $("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();}); 280 $("#TB_load").remove(); 281 if (typeof document.body.style.maxHeight == "undefined") {//if IE 6 282 $("body","html").css({height: "auto", width: "auto"}); 283 $("html").css("overflow",""); 284 } 285 document.onkeydown = ""; 286 document.onkeyup = ""; 287 return false; 288} 289 290function tb_position() { 291$("#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 $("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'}); 294 } 295} 296 297function tb_parseQuery ( query ) { 298 var Params = {}; 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, ' '); 307 Params[key] = val; 308 } 309 return Params; 310} 311 312function 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; 318} 319 320function tb_detectMacXFF() { 321 var userAgent = navigator.userAgent.toLowerCase(); 322 if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) { 323 return true; 324 } 325} 326 327
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.