wp/wp-includes/js/thickbox/thickbox.js
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 18 be944660c56a
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
    16 	tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
    16 	tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
    17 	imgLoader = new Image();// preload image
    17 	imgLoader = new Image();// preload image
    18 	imgLoader.src = tb_pathToImage;
    18 	imgLoader.src = tb_pathToImage;
    19 });
    19 });
    20 
    20 
    21 //add thickbox to href & area elements that have a class of .thickbox
    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  */
    22 function tb_init(domChunk){
    25 function tb_init(domChunk){
    23 	jQuery('body').on('click', domChunk, tb_click);
    26 	jQuery( 'body' )
       
    27 		.on( 'click', domChunk, tb_click )
       
    28 		.on( 'thickbox:iframe:loaded', function() {
       
    29 			jQuery( '#TB_window' ).removeClass( 'thickbox-loading' );
       
    30 		});
    24 }
    31 }
    25 
    32 
    26 function tb_click(){
    33 function tb_click(){
    27 	var t = this.title || this.name || null;
    34 	var t = this.title || this.name || null;
    28 	var a = this.href || this.alt;
    35 	var a = this.href || this.alt;
    32 	return false;
    39 	return false;
    33 }
    40 }
    34 
    41 
    35 function tb_show(caption, url, imageGroup) {//function called when the user clicks on a thickbox link
    42 function tb_show(caption, url, imageGroup) {//function called when the user clicks on a thickbox link
    36 
    43 
       
    44 	var $closeBtn;
       
    45 
    37 	try {
    46 	try {
    38 		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
    47 		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
    39 			jQuery("body","html").css({height: "100%", width: "100%"});
    48 			jQuery("body","html").css({height: "100%", width: "100%"});
    40 			jQuery("html").css("overflow","hidden");
    49 			jQuery("html").css("overflow","hidden");
    41 			if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
    50 			if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
    42 				jQuery("body").append("<iframe id='TB_HideSelect'>"+thickboxL10n.noiframes+"</iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
    51 				jQuery("body").append("<iframe id='TB_HideSelect'>"+thickboxL10n.noiframes+"</iframe><div id='TB_overlay'></div><div id='TB_window' class='thickbox-loading'></div>");
    43 				jQuery("#TB_overlay").click(tb_remove);
    52 				jQuery("#TB_overlay").click(tb_remove);
    44 			}
    53 			}
    45 		}else{//all others
    54 		}else{//all others
    46 			if(document.getElementById("TB_overlay") === null){
    55 			if(document.getElementById("TB_overlay") === null){
    47 				jQuery("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
    56 				jQuery("body").append("<div id='TB_overlay'></div><div id='TB_window' class='thickbox-loading'></div>");
    48 				jQuery("#TB_overlay").click(tb_remove);
    57 				jQuery("#TB_overlay").click(tb_remove);
    49 				jQuery( 'body' ).addClass( 'modal-open' );
    58 				jQuery( 'body' ).addClass( 'modal-open' );
    50 			}
    59 			}
    51 		}
    60 		}
    52 
    61 
   128 			}
   137 			}
   129 			// End Resizing
   138 			// End Resizing
   130 
   139 
   131 			TB_WIDTH = imageWidth + 30;
   140 			TB_WIDTH = imageWidth + 30;
   132 			TB_HEIGHT = imageHeight + 60;
   141 			TB_HEIGHT = imageHeight + 60;
   133 			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'><a href='#' id='TB_closeWindowButton'><span class='screen-reader-text'>"+thickboxL10n.close+"</span><div class='tb-close-icon'></div></a></div>");
   142 			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>");
   134 
   143 
   135 			jQuery("#TB_closeWindowButton").click(tb_remove);
   144 			jQuery("#TB_closeWindowButton").click(tb_remove);
   136 
   145 
   137 			if (!(TB_PrevHTML === "")) {
   146 			if (!(TB_PrevHTML === "")) {
   138 				function goPrev(){
   147 				function goPrev(){
   193 
   202 
   194 			if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window
   203 			if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window
   195 					urlNoQuery = url.split('TB_');
   204 					urlNoQuery = url.split('TB_');
   196 					jQuery("#TB_iframeContent").remove();
   205 					jQuery("#TB_iframeContent").remove();
   197 					if(params['modal'] != "true"){//iframe no modal
   206 					if(params['modal'] != "true"){//iframe no modal
   198 						jQuery("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'><span class='screen-reader-text'>"+thickboxL10n.close+"</span><div class='tb-close-icon'></div></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;' >"+thickboxL10n.noiframes+"</iframe>");
   207 						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>");
   199 					}else{//iframe modal
   208 					}else{//iframe modal
   200 					jQuery("#TB_overlay").unbind();
   209 					jQuery("#TB_overlay").unbind();
   201 						jQuery("#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;'>"+thickboxL10n.noiframes+"</iframe>");
   210 						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>");
   202 					}
   211 					}
   203 			}else{// not an iframe, ajax
   212 			}else{// not an iframe, ajax
   204 					if(jQuery("#TB_window").css("visibility") != "visible"){
   213 					if(jQuery("#TB_window").css("visibility") != "visible"){
   205 						if(params['modal'] != "true"){//ajax no modal
   214 						if(params['modal'] != "true"){//ajax no modal
   206 						jQuery("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'><div class='tb-close-icon'></div></a></div></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>");
   215 						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>");
   207 						}else{//ajax modal
   216 						}else{//ajax modal
   208 						jQuery("#TB_overlay").unbind();
   217 						jQuery("#TB_overlay").unbind();
   209 						jQuery("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");
   218 						jQuery("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");
   210 						}
   219 						}
   211 					}else{//this means the window is already up, we are just loading new content via ajax
   220 					}else{//this means the window is already up, we are just loading new content via ajax
   229 				}else if(url.indexOf('TB_iframe') != -1){
   238 				}else if(url.indexOf('TB_iframe') != -1){
   230 					tb_position();
   239 					tb_position();
   231 					jQuery("#TB_load").remove();
   240 					jQuery("#TB_load").remove();
   232 					jQuery("#TB_window").css({'visibility':'visible'});
   241 					jQuery("#TB_window").css({'visibility':'visible'});
   233 				}else{
   242 				}else{
   234 					jQuery("#TB_ajaxContent").load(url += "&random=" + (new Date().getTime()),function(){//to do a post change this load method
   243 					var load_url = url;
       
   244 					load_url += -1 === url.indexOf('?') ? '?' : '&';
       
   245 					jQuery("#TB_ajaxContent").load(load_url += "random=" + (new Date().getTime()),function(){//to do a post change this load method
   235 						tb_position();
   246 						tb_position();
   236 						jQuery("#TB_load").remove();
   247 						jQuery("#TB_load").remove();
   237 						tb_init("#TB_ajaxContent a.thickbox");
   248 						tb_init("#TB_ajaxContent a.thickbox");
   238 						jQuery("#TB_window").css({'visibility':'visible'});
   249 						jQuery("#TB_window").css({'visibility':'visible'});
   239 					});
   250 					});
   248 					return false;
   259 					return false;
   249 				}
   260 				}
   250 			});
   261 			});
   251 		}
   262 		}
   252 
   263 
       
   264 		$closeBtn = jQuery( '#TB_closeWindowButton' );
       
   265 		/*
       
   266 		 * If the native Close button icon is visible, move focus on the button
       
   267 		 * (e.g. in the Network Admin Themes screen).
       
   268 		 * In other admin screens is hidden and replaced by a different icon.
       
   269 		 */
       
   270 		if ( $closeBtn.find( '.tb-close-icon' ).is( ':visible' ) ) {
       
   271 			$closeBtn.focus();
       
   272 		}
       
   273 
   253 	} catch(e) {
   274 	} catch(e) {
   254 		//nothing here
   275 		//nothing here
   255 	}
   276 	}
   256 }
   277 }
   257 
   278 
   258 //helper functions below
   279 //helper functions below
   259 function tb_showIframe(){
   280 function tb_showIframe(){
   260 	jQuery("#TB_load").remove();
   281 	jQuery("#TB_load").remove();
   261 	jQuery("#TB_window").css({'visibility':'visible'});
   282 	jQuery("#TB_window").css({'visibility':'visible'}).trigger( 'thickbox:iframe:loaded' );
   262 }
   283 }
   263 
   284 
   264 function tb_remove() {
   285 function tb_remove() {
   265  	jQuery("#TB_imageOff").unbind("click");
   286  	jQuery("#TB_imageOff").unbind("click");
   266 	jQuery("#TB_closeWindowButton").unbind("click");
   287 	jQuery("#TB_closeWindowButton").unbind("click");
   267 	jQuery("#TB_window").fadeOut("fast",function(){jQuery('#TB_window,#TB_overlay,#TB_HideSelect').trigger("tb_unload").unbind().remove();});
   288 	jQuery( '#TB_window' ).fadeOut( 'fast', function() {
       
   289 		jQuery( '#TB_window, #TB_overlay, #TB_HideSelect' ).trigger( 'tb_unload' ).unbind().remove();
       
   290 		jQuery( 'body' ).trigger( 'thickbox:removed' );
       
   291 	});
   268 	jQuery( 'body' ).removeClass( 'modal-open' );
   292 	jQuery( 'body' ).removeClass( 'modal-open' );
   269 	jQuery("#TB_load").remove();
   293 	jQuery("#TB_load").remove();
   270 	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
   294 	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
   271 		jQuery("body","html").css({height: "auto", width: "auto"});
   295 		jQuery("body","html").css({height: "auto", width: "auto"});
   272 		jQuery("html").css("overflow","");
   296 		jQuery("html").css("overflow","");