[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
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 if ( 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 15 jQuery(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 */ 25 function 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 33 function 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 42 function 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$|\.avif$/; 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 urlType == '.avif' 89 ){//code to show images 90 91 TB_PrevCaption = ""; 92 TB_PrevURL = ""; 93 TB_PrevHTML = ""; 94 TB_NextCaption = ""; 95 TB_NextURL = ""; 96 TB_NextHTML = ""; 97 TB_imageCount = ""; 98 TB_FoundURL = false; 99 if(imageGroup){ 100 TB_TempArray = jQuery("a[rel="+imageGroup+"]").get(); 101 for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML === "")); TB_Counter++) { 102 var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString); 103 if (!(TB_TempArray[TB_Counter].href == url)) { 104 if (TB_FoundURL) { 105 TB_NextCaption = TB_TempArray[TB_Counter].title; 106 TB_NextURL = TB_TempArray[TB_Counter].href; 107 TB_NextHTML = "<span id='TB_next'> <a href='#'>"+thickboxL10n.next+"</a></span>"; 108 } else { 109 TB_PrevCaption = TB_TempArray[TB_Counter].title; 110 TB_PrevURL = TB_TempArray[TB_Counter].href; 111 TB_PrevHTML = "<span id='TB_prev'> <a href='#'>"+thickboxL10n.prev+"</a></span>"; 112 } 113 } else { 114 TB_FoundURL = true; 115 TB_imageCount = thickboxL10n.image + ' ' + (TB_Counter + 1) + ' ' + thickboxL10n.of + ' ' + (TB_TempArray.length); 116 } 117 } 118 } 119 120 imgPreloader = new Image(); 121 imgPreloader.onload = function(){ 122 imgPreloader.onload = null; 123 124 // Resizing large images - original by Christian Montoya edited by me. 125 var pagesize = tb_getPageSize(); 126 var x = pagesize[0] - 150; 127 var y = pagesize[1] - 150; 128 var imageWidth = imgPreloader.width; 129 var imageHeight = imgPreloader.height; 130 if (imageWidth > x) { 131 imageHeight = imageHeight * (x / imageWidth); 132 imageWidth = x; 133 if (imageHeight > y) { 134 imageWidth = imageWidth * (y / imageHeight); 135 imageHeight = y; 136 } 137 } else if (imageHeight > y) { 138 imageWidth = imageWidth * (y / imageHeight); 139 imageHeight = y; 140 if (imageWidth > x) { 141 imageHeight = imageHeight * (x / imageWidth); 142 imageWidth = x; 143 } 144 } 145 // End Resizing 146 147 TB_WIDTH = imageWidth + 30; 148 TB_HEIGHT = imageHeight + 60; 149 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>"); 150 151 jQuery("#TB_closeWindowButton").on( 'click', tb_remove ); 152 153 if (!(TB_PrevHTML === "")) { 154 function goPrev(){ 155 if(jQuery(document).off("click",goPrev)){jQuery(document).off("click",goPrev);} 156 jQuery("#TB_window").remove(); 157 jQuery("body").append("<div id='TB_window'></div>"); 158 tb_show(TB_PrevCaption, TB_PrevURL, imageGroup); 159 return false; 160 } 161 jQuery("#TB_prev").on( 'click', goPrev ); 162 } 163 164 if (!(TB_NextHTML === "")) { 165 function goNext(){ 166 jQuery("#TB_window").remove(); 167 jQuery("body").append("<div id='TB_window'></div>"); 168 tb_show(TB_NextCaption, TB_NextURL, imageGroup); 169 return false; 170 } 171 jQuery("#TB_next").on( 'click', goNext ); 172 173 } 174 175 jQuery(document).on('keydown.thickbox', function(e){ 176 if ( e.which == 27 ){ // close 177 tb_remove(); 178 179 } else if ( e.which == 190 ){ // display previous image 180 if(!(TB_NextHTML == "")){ 181 jQuery(document).off('thickbox'); 182 goNext(); 183 } 184 } else if ( e.which == 188 ){ // display next image 185 if(!(TB_PrevHTML == "")){ 186 jQuery(document).off('thickbox'); 187 goPrev(); 188 } 189 } 190 return false; 191 }); 192 193 tb_position(); 194 jQuery("#TB_load").remove(); 195 jQuery("#TB_ImageOff").on( 'click', tb_remove ); 196 jQuery("#TB_window").css({'visibility':'visible'}); //for safari using css instead of show 197 }; 198 199 imgPreloader.src = url; 200 }else{//code to show html 201 202 var queryString = url.replace(/^[^\?]+\??/,''); 203 var params = tb_parseQuery( queryString ); 204 205 TB_WIDTH = (params['width']*1) + 30 || 630; //defaults to 630 if no parameters were added to URL 206 TB_HEIGHT = (params['height']*1) + 40 || 440; //defaults to 440 if no parameters were added to URL 207 ajaxContentW = TB_WIDTH - 30; 208 ajaxContentH = TB_HEIGHT - 45; 209 210 if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window 211 urlNoQuery = url.split('TB_'); 212 jQuery("#TB_iframeContent").remove(); 213 if(params['modal'] != "true"){//iframe no modal 214 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>"); 215 }else{//iframe modal 216 jQuery("#TB_overlay").off(); 217 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>"); 218 } 219 }else{// not an iframe, ajax 220 if(jQuery("#TB_window").css("visibility") != "visible"){ 221 if(params['modal'] != "true"){//ajax no modal 222 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>"); 223 }else{//ajax modal 224 jQuery("#TB_overlay").off(); 225 jQuery("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>"); 226 } 227 }else{//this means the window is already up, we are just loading new content via ajax 228 jQuery("#TB_ajaxContent")[0].style.width = ajaxContentW +"px"; 229 jQuery("#TB_ajaxContent")[0].style.height = ajaxContentH +"px"; 230 jQuery("#TB_ajaxContent")[0].scrollTop = 0; 231 jQuery("#TB_ajaxWindowTitle").html(caption); 232 } 233 } 234 235 jQuery("#TB_closeWindowButton").on( 'click', tb_remove ); 236 237 if(url.indexOf('TB_inline') != -1){ 238 jQuery("#TB_ajaxContent").append(jQuery('#' + params['inlineId']).children()); 239 jQuery("#TB_window").on('tb_unload', function () { 240 jQuery('#' + params['inlineId']).append( jQuery("#TB_ajaxContent").children() ); // move elements back when you're finished 241 }); 242 tb_position(); 243 jQuery("#TB_load").remove(); 244 jQuery("#TB_window").css({'visibility':'visible'}); 245 }else if(url.indexOf('TB_iframe') != -1){ 246 tb_position(); 247 jQuery("#TB_load").remove(); 248 jQuery("#TB_window").css({'visibility':'visible'}); 249 }else{ 250 var load_url = url; 251 load_url += -1 === url.indexOf('?') ? '?' : '&'; 252 jQuery("#TB_ajaxContent").load(load_url += "random=" + (new Date().getTime()),function(){//to do a post change this load method 253 tb_position(); 254 jQuery("#TB_load").remove(); 255 tb_init("#TB_ajaxContent a.thickbox"); 256 jQuery("#TB_window").css({'visibility':'visible'}); 257 }); 258 } 259 260 } 261 262 if(!params['modal']){ 263 jQuery(document).on('keydown.thickbox', function(e){ 264 if ( e.which == 27 ){ // close 265 tb_remove(); 266 return false; 267 } 268 }); 269 } 270 271 $closeBtn = jQuery( '#TB_closeWindowButton' ); 272 /* 273 * If the native Close button icon is visible, move focus on the button 274 * (e.g. in the Network Admin Themes screen). 275 * In other admin screens is hidden and replaced by a different icon. 276 */ 277 if ( $closeBtn.find( '.tb-close-icon' ).is( ':visible' ) ) { 278 $closeBtn.trigger( 'focus' ); 279 } 280 281 } catch(e) { 282 //nothing here 283 } 284 } 285 286 //helper functions below 287 function tb_showIframe(){ 288 jQuery("#TB_load").remove(); 289 jQuery("#TB_window").css({'visibility':'visible'}).trigger( 'thickbox:iframe:loaded' ); 290 } 291 292 function tb_remove() { 293 jQuery("#TB_imageOff").off("click"); 294 jQuery("#TB_closeWindowButton").off("click"); 295 jQuery( '#TB_window' ).fadeOut( 'fast', function() { 296 jQuery( '#TB_window, #TB_overlay, #TB_HideSelect' ).trigger( 'tb_unload' ).off().remove(); 297 jQuery( 'body' ).trigger( 'thickbox:removed' ); 298 }); 299 jQuery( 'body' ).removeClass( 'modal-open' ); 300 jQuery("#TB_load").remove(); 301 if (typeof document.body.style.maxHeight == "undefined") {//if IE 6 302 jQuery("body","html").css({height: "auto", width: "auto"}); 303 jQuery("html").css("overflow",""); 304 } 305 jQuery(document).off('.thickbox'); 306 return false; 307 } 308 309 function tb_position() { 310 var isIE6 = typeof document.body.style.maxHeight === "undefined"; 311 jQuery("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'}); 312 if ( ! isIE6 ) { // take away IE6 313 jQuery("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'}); 314 } 315 } 316 317 function tb_parseQuery ( query ) { 318 var Params = {}; 319 if ( ! query ) {return Params;}// return empty object 320 var Pairs = query.split(/[;&]/); 321 for ( var i = 0; i < Pairs.length; i++ ) { 322 var KeyVal = Pairs[i].split('='); 323 if ( ! KeyVal || KeyVal.length != 2 ) {continue;} 324 var key = unescape( KeyVal[0] ); 325 var val = unescape( KeyVal[1] ); 326 val = val.replace(/\+/g, ' '); 327 Params[key] = val; 328 } 329 return Params; 330 } 331 332 function tb_getPageSize(){ 333 var de = document.documentElement; 334 var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth; 335 var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight; 336 arrayPageSize = [w,h]; 337 return arrayPageSize; 338 } 339 340 function tb_detectMacXFF() { 341 var userAgent = navigator.userAgent.toLowerCase(); 342 if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) { 343 return true; 344 } 345 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Thu Nov 21 08:20:01 2024 | Cross-referenced by PHPXref |