wp/wp-admin/js/plugin-install.js
changeset 18 be944660c56a
parent 16 a86126ab1dd4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
     4  * @output wp-admin/js/plugin-install.js
     4  * @output wp-admin/js/plugin-install.js
     5  */
     5  */
     6 
     6 
     7 /* global tb_click, tb_remove, tb_position */
     7 /* global tb_click, tb_remove, tb_position */
     8 
     8 
     9 jQuery( document ).ready( function( $ ) {
     9 jQuery( function( $ ) {
    10 
    10 
    11 	var tbWindow,
    11 	var tbWindow,
    12 		$iframeBody,
    12 		$iframeBody,
    13 		$tabbables,
    13 		$tabbables,
    14 		$firstTabbable,
    14 		$firstTabbable,
    48 			href = href.replace( /&height=[0-9]+/g, '' );
    48 			href = href.replace( /&height=[0-9]+/g, '' );
    49 			$(this).attr( 'href', href + '&width=' + W + '&height=' + ( H ) );
    49 			$(this).attr( 'href', href + '&width=' + W + '&height=' + ( H ) );
    50 		});
    50 		});
    51 	};
    51 	};
    52 
    52 
    53 	$( window ).resize( function() {
    53 	$( window ).on( 'resize', function() {
    54 		tb_position();
    54 		tb_position();
    55 	});
    55 	});
    56 
    56 
    57 	/*
    57 	/*
    58 	 * Custom events: when a Thickbox iframe has loaded and when the Thickbox
    58 	 * Custom events: when a Thickbox iframe has loaded and when the Thickbox
    73 			iframeLoaded();
    73 			iframeLoaded();
    74 		})
    74 		})
    75 		.on( 'thickbox:removed', function() {
    75 		.on( 'thickbox:removed', function() {
    76 			// Set focus back to the element that opened the modal dialog.
    76 			// Set focus back to the element that opened the modal dialog.
    77 			// Note: IE 8 would need this wrapped in a fake setTimeout `0`.
    77 			// Note: IE 8 would need this wrapped in a fake setTimeout `0`.
    78 			$focusedBefore.focus();
    78 			$focusedBefore.trigger( 'focus' );
    79 		});
    79 		});
    80 
    80 
    81 	function iframeLoaded() {
    81 	function iframeLoaded() {
    82 		var $iframe = tbWindow.find( '#TB_iframeContent' );
    82 		var $iframe = tbWindow.find( '#TB_iframeContent' );
    83 
    83 
    86 
    86 
    87 		// Get the tabbable elements and handle the keydown event on first load.
    87 		// Get the tabbable elements and handle the keydown event on first load.
    88 		handleTabbables();
    88 		handleTabbables();
    89 
    89 
    90 		// Set initial focus on the "Close" button.
    90 		// Set initial focus on the "Close" button.
    91 		$firstTabbable.focus();
    91 		$firstTabbable.trigger( 'focus' );
    92 
    92 
    93 		/*
    93 		/*
    94 		 * When the "Install" button is disabled (e.g. the Plugin is already installed)
    94 		 * When the "Install" button is disabled (e.g. the Plugin is already installed)
    95 		 * then we can't predict where the last focusable element is. We need to get
    95 		 * then we can't predict where the last focusable element is. We need to get
    96 		 * the tabbable elements and handle the keydown event again and again,
    96 		 * the tabbable elements and handle the keydown event again and again,
   139 			return;
   139 			return;
   140 		}
   140 		}
   141 
   141 
   142 		if ( $lastTabbable[0] === event.target && ! event.shiftKey ) {
   142 		if ( $lastTabbable[0] === event.target && ! event.shiftKey ) {
   143 			event.preventDefault();
   143 			event.preventDefault();
   144 			$firstTabbable.focus();
   144 			$firstTabbable.trigger( 'focus' );
   145 		} else if ( $firstTabbable[0] === event.target && event.shiftKey ) {
   145 		} else if ( $firstTabbable[0] === event.target && event.shiftKey ) {
   146 			event.preventDefault();
   146 			event.preventDefault();
   147 			$lastTabbable.focus();
   147 			$lastTabbable.trigger( 'focus' );
   148 		}
   148 		}
   149 	}
   149 	}
   150 
   150 
   151 	/*
   151 	/*
   152 	 * Open the Plugin details modal. The event is delegated to get also the links
   152 	 * Open the Plugin details modal. The event is delegated to get also the links
   183 		// Set title attribute on the iframe.
   183 		// Set title attribute on the iframe.
   184 		tbWindow.find( '#TB_iframeContent' ).attr( 'title', title );
   184 		tbWindow.find( '#TB_iframeContent' ).attr( 'title', title );
   185 	});
   185 	});
   186 
   186 
   187 	/* Plugin install related JS */
   187 	/* Plugin install related JS */
   188 	$( '#plugin-information-tabs a' ).click( function( event ) {
   188 	$( '#plugin-information-tabs a' ).on( 'click', function( event ) {
   189 		var tab = $( this ).attr( 'name' );
   189 		var tab = $( this ).attr( 'name' );
   190 		event.preventDefault();
   190 		event.preventDefault();
   191 
   191 
   192 		// Flip the tab.
   192 		// Flip the tab.
   193 		$( '#plugin-information-tabs a.current' ).removeClass( 'current' );
   193 		$( '#plugin-information-tabs a.current' ).removeClass( 'current' );