Edit File by line
/home/barbar84/public_h.../wp-admin/js
File: plugin-install.js
/**
[0] Fix | Delete
* @file Functionality for the plugin install screens.
[1] Fix | Delete
*
[2] Fix | Delete
* @output wp-admin/js/plugin-install.js
[3] Fix | Delete
*/
[4] Fix | Delete
[5] Fix | Delete
/* global tb_click, tb_remove, tb_position */
[6] Fix | Delete
[7] Fix | Delete
jQuery( document ).ready( function( $ ) {
[8] Fix | Delete
[9] Fix | Delete
var tbWindow,
[10] Fix | Delete
$iframeBody,
[11] Fix | Delete
$tabbables,
[12] Fix | Delete
$firstTabbable,
[13] Fix | Delete
$lastTabbable,
[14] Fix | Delete
$focusedBefore = $(),
[15] Fix | Delete
$uploadViewToggle = $( '.upload-view-toggle' ),
[16] Fix | Delete
$wrap = $ ( '.wrap' ),
[17] Fix | Delete
$body = $( document.body );
[18] Fix | Delete
[19] Fix | Delete
window.tb_position = function() {
[20] Fix | Delete
var width = $( window ).width(),
[21] Fix | Delete
H = $( window ).height() - ( ( 792 < width ) ? 60 : 20 ),
[22] Fix | Delete
W = ( 792 < width ) ? 772 : width - 20;
[23] Fix | Delete
[24] Fix | Delete
tbWindow = $( '#TB_window' );
[25] Fix | Delete
[26] Fix | Delete
if ( tbWindow.length ) {
[27] Fix | Delete
tbWindow.width( W ).height( H );
[28] Fix | Delete
$( '#TB_iframeContent' ).width( W ).height( H );
[29] Fix | Delete
tbWindow.css({
[30] Fix | Delete
'margin-left': '-' + parseInt( ( W / 2 ), 10 ) + 'px'
[31] Fix | Delete
});
[32] Fix | Delete
if ( typeof document.body.style.maxWidth !== 'undefined' ) {
[33] Fix | Delete
tbWindow.css({
[34] Fix | Delete
'top': '30px',
[35] Fix | Delete
'margin-top': '0'
[36] Fix | Delete
});
[37] Fix | Delete
}
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
return $( 'a.thickbox' ).each( function() {
[41] Fix | Delete
var href = $( this ).attr( 'href' );
[42] Fix | Delete
if ( ! href ) {
[43] Fix | Delete
return;
[44] Fix | Delete
}
[45] Fix | Delete
href = href.replace( /&width=[0-9]+/g, '' );
[46] Fix | Delete
href = href.replace( /&height=[0-9]+/g, '' );
[47] Fix | Delete
$(this).attr( 'href', href + '&width=' + W + '&height=' + ( H ) );
[48] Fix | Delete
});
[49] Fix | Delete
};
[50] Fix | Delete
[51] Fix | Delete
$( window ).on( 'resize', function() {
[52] Fix | Delete
tb_position();
[53] Fix | Delete
});
[54] Fix | Delete
[55] Fix | Delete
/*
[56] Fix | Delete
* Custom events: when a Thickbox iframe has loaded and when the Thickbox
[57] Fix | Delete
* modal gets removed from the DOM.
[58] Fix | Delete
*/
[59] Fix | Delete
$body
[60] Fix | Delete
.on( 'thickbox:iframe:loaded', tbWindow, function() {
[61] Fix | Delete
/*
[62] Fix | Delete
* Return if it's not the modal with the plugin details iframe. Other
[63] Fix | Delete
* thickbox instances might want to load an iframe with content from
[64] Fix | Delete
* an external domain. Avoid to access the iframe contents when we're
[65] Fix | Delete
* not sure the iframe loads from the same domain.
[66] Fix | Delete
*/
[67] Fix | Delete
if ( ! tbWindow.hasClass( 'plugin-details-modal' ) ) {
[68] Fix | Delete
return;
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
iframeLoaded();
[72] Fix | Delete
})
[73] Fix | Delete
.on( 'thickbox:removed', function() {
[74] Fix | Delete
// Set focus back to the element that opened the modal dialog.
[75] Fix | Delete
// Note: IE 8 would need this wrapped in a fake setTimeout `0`.
[76] Fix | Delete
$focusedBefore.trigger( 'focus' );
[77] Fix | Delete
});
[78] Fix | Delete
[79] Fix | Delete
function iframeLoaded() {
[80] Fix | Delete
var $iframe = tbWindow.find( '#TB_iframeContent' );
[81] Fix | Delete
[82] Fix | Delete
// Get the iframe body.
[83] Fix | Delete
$iframeBody = $iframe.contents().find( 'body' );
[84] Fix | Delete
[85] Fix | Delete
// Get the tabbable elements and handle the keydown event on first load.
[86] Fix | Delete
handleTabbables();
[87] Fix | Delete
[88] Fix | Delete
// Set initial focus on the "Close" button.
[89] Fix | Delete
$firstTabbable.trigger( 'focus' );
[90] Fix | Delete
[91] Fix | Delete
/*
[92] Fix | Delete
* When the "Install" button is disabled (e.g. the Plugin is already installed)
[93] Fix | Delete
* then we can't predict where the last focusable element is. We need to get
[94] Fix | Delete
* the tabbable elements and handle the keydown event again and again,
[95] Fix | Delete
* each time the active tab panel changes.
[96] Fix | Delete
*/
[97] Fix | Delete
$( '#plugin-information-tabs a', $iframeBody ).on( 'click', function() {
[98] Fix | Delete
handleTabbables();
[99] Fix | Delete
});
[100] Fix | Delete
[101] Fix | Delete
// Close the modal when pressing Escape.
[102] Fix | Delete
$iframeBody.on( 'keydown', function( event ) {
[103] Fix | Delete
if ( 27 !== event.which ) {
[104] Fix | Delete
return;
[105] Fix | Delete
}
[106] Fix | Delete
tb_remove();
[107] Fix | Delete
});
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
/*
[111] Fix | Delete
* Get the tabbable elements and detach/attach the keydown event.
[112] Fix | Delete
* Called after the iframe has fully loaded so we have all the elements we need.
[113] Fix | Delete
* Called again each time a Tab gets clicked.
[114] Fix | Delete
* @todo Consider to implement a WordPress general utility for this and don't use jQuery UI.
[115] Fix | Delete
*/
[116] Fix | Delete
function handleTabbables() {
[117] Fix | Delete
var $firstAndLast;
[118] Fix | Delete
// Get all the tabbable elements.
[119] Fix | Delete
$tabbables = $( ':tabbable', $iframeBody );
[120] Fix | Delete
// Our first tabbable element is always the "Close" button.
[121] Fix | Delete
$firstTabbable = tbWindow.find( '#TB_closeWindowButton' );
[122] Fix | Delete
// Get the last tabbable element.
[123] Fix | Delete
$lastTabbable = $tabbables.last();
[124] Fix | Delete
// Make a jQuery collection.
[125] Fix | Delete
$firstAndLast = $firstTabbable.add( $lastTabbable );
[126] Fix | Delete
// Detach any previously attached keydown event.
[127] Fix | Delete
$firstAndLast.off( 'keydown.wp-plugin-details' );
[128] Fix | Delete
// Attach again the keydown event on the first and last focusable elements.
[129] Fix | Delete
$firstAndLast.on( 'keydown.wp-plugin-details', function( event ) {
[130] Fix | Delete
constrainTabbing( event );
[131] Fix | Delete
});
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
// Constrain tabbing within the plugin modal dialog.
[135] Fix | Delete
function constrainTabbing( event ) {
[136] Fix | Delete
if ( 9 !== event.which ) {
[137] Fix | Delete
return;
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
if ( $lastTabbable[0] === event.target && ! event.shiftKey ) {
[141] Fix | Delete
event.preventDefault();
[142] Fix | Delete
$firstTabbable.trigger( 'focus' );
[143] Fix | Delete
} else if ( $firstTabbable[0] === event.target && event.shiftKey ) {
[144] Fix | Delete
event.preventDefault();
[145] Fix | Delete
$lastTabbable.trigger( 'focus' );
[146] Fix | Delete
}
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
/*
[150] Fix | Delete
* Open the Plugin details modal. The event is delegated to get also the links
[151] Fix | Delete
* in the plugins search tab, after the Ajax search rebuilds the HTML. It's
[152] Fix | Delete
* delegated on the closest ancestor and not on the body to avoid conflicts
[153] Fix | Delete
* with other handlers, see Trac ticket #43082.
[154] Fix | Delete
*/
[155] Fix | Delete
$( '.wrap' ).on( 'click', '.thickbox.open-plugin-details-modal', function( e ) {
[156] Fix | Delete
// The `data-title` attribute is used only in the Plugin screens.
[157] Fix | Delete
var title = $( this ).data( 'title' ) ?
[158] Fix | Delete
wp.i18n.sprintf(
[159] Fix | Delete
// translators: %s: Plugin name.
[160] Fix | Delete
wp.i18n.__( 'Plugin: %s' ),
[161] Fix | Delete
$( this ).data( 'title' )
[162] Fix | Delete
) :
[163] Fix | Delete
wp.i18n.__( 'Plugin details' );
[164] Fix | Delete
[165] Fix | Delete
e.preventDefault();
[166] Fix | Delete
e.stopPropagation();
[167] Fix | Delete
[168] Fix | Delete
// Store the element that has focus before opening the modal dialog, i.e. the control which opens it.
[169] Fix | Delete
$focusedBefore = $( this );
[170] Fix | Delete
[171] Fix | Delete
tb_click.call(this);
[172] Fix | Delete
[173] Fix | Delete
// Set ARIA role, ARIA label, and add a CSS class.
[174] Fix | Delete
tbWindow
[175] Fix | Delete
.attr({
[176] Fix | Delete
'role': 'dialog',
[177] Fix | Delete
'aria-label': wp.i18n.__( 'Plugin details' )
[178] Fix | Delete
})
[179] Fix | Delete
.addClass( 'plugin-details-modal' );
[180] Fix | Delete
[181] Fix | Delete
// Set title attribute on the iframe.
[182] Fix | Delete
tbWindow.find( '#TB_iframeContent' ).attr( 'title', title );
[183] Fix | Delete
});
[184] Fix | Delete
[185] Fix | Delete
/* Plugin install related JS */
[186] Fix | Delete
$( '#plugin-information-tabs a' ).on( 'click', function( event ) {
[187] Fix | Delete
var tab = $( this ).attr( 'name' );
[188] Fix | Delete
event.preventDefault();
[189] Fix | Delete
[190] Fix | Delete
// Flip the tab.
[191] Fix | Delete
$( '#plugin-information-tabs a.current' ).removeClass( 'current' );
[192] Fix | Delete
$( this ).addClass( 'current' );
[193] Fix | Delete
[194] Fix | Delete
// Only show the fyi box in the description section, on smaller screen,
[195] Fix | Delete
// where it's otherwise always displayed at the top.
[196] Fix | Delete
if ( 'description' !== tab && $( window ).width() < 772 ) {
[197] Fix | Delete
$( '#plugin-information-content' ).find( '.fyi' ).hide();
[198] Fix | Delete
} else {
[199] Fix | Delete
$( '#plugin-information-content' ).find( '.fyi' ).show();
[200] Fix | Delete
}
[201] Fix | Delete
[202] Fix | Delete
// Flip the content.
[203] Fix | Delete
$( '#section-holder div.section' ).hide(); // Hide 'em all.
[204] Fix | Delete
$( '#section-' + tab ).show();
[205] Fix | Delete
});
[206] Fix | Delete
[207] Fix | Delete
/*
[208] Fix | Delete
* When a user presses the "Upload Plugin" button, show the upload form in place
[209] Fix | Delete
* rather than sending them to the devoted upload plugin page.
[210] Fix | Delete
* The `?tab=upload` page still exists for no-js support and for plugins that
[211] Fix | Delete
* might access it directly. When we're in this page, let the link behave
[212] Fix | Delete
* like a link. Otherwise we're in the normal plugin installer pages and the
[213] Fix | Delete
* link should behave like a toggle button.
[214] Fix | Delete
*/
[215] Fix | Delete
if ( ! $wrap.hasClass( 'plugin-install-tab-upload' ) ) {
[216] Fix | Delete
$uploadViewToggle
[217] Fix | Delete
.attr({
[218] Fix | Delete
role: 'button',
[219] Fix | Delete
'aria-expanded': 'false'
[220] Fix | Delete
})
[221] Fix | Delete
.on( 'click', function( event ) {
[222] Fix | Delete
event.preventDefault();
[223] Fix | Delete
$body.toggleClass( 'show-upload-view' );
[224] Fix | Delete
$uploadViewToggle.attr( 'aria-expanded', $body.hasClass( 'show-upload-view' ) );
[225] Fix | Delete
});
[226] Fix | Delete
}
[227] Fix | Delete
});
[228] Fix | Delete
[229] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function