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