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