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