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