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