From 2aebf33f9d0aa2b78084f9eb280643dbb375ea64 Mon Sep 17 00:00:00 2001 From: Andrea Fercia Date: Fri, 10 Jun 2016 22:38:57 +0000 Subject: [PATCH] Plugin Install: fix edge-case where the tab=upload page can be accessed directly. The `?tab=upload` page still exists for no-js support and for users who may access it directly (e.g. from bookmarks or history) or plugins doing the same. In this page, the "Browse plugins" link should always behave like a link. Fixes #35429. git-svn-id: https://develop.svn.wordpress.org/trunk@37681 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/plugin-install.js | 36 +++++++++++++++++-------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/wp-admin/js/plugin-install.js b/src/wp-admin/js/plugin-install.js index 4cd1bb8eb4..8954766838 100644 --- a/src/wp-admin/js/plugin-install.js +++ b/src/wp-admin/js/plugin-install.js @@ -11,7 +11,9 @@ jQuery( document ).ready( function( $ ) { $iframeBody, $tabbables, $firstTabbable, - $lastTabbable; + $lastTabbable, + uploadViewToggle = $( '.upload-view-toggle' ), + $body = $( document.body ); tb_position = function() { var width = $( window ).width(), @@ -53,7 +55,7 @@ jQuery( document ).ready( function( $ ) { * Custom events: when a Thickbox iframe has loaded and when the Thickbox * modal gets removed from the DOM. */ - $( 'body' ) + $body .on( 'thickbox:iframe:loaded', tbWindow, function() { iframeLoaded(); }) @@ -180,19 +182,21 @@ jQuery( document ).ready( function( $ ) { /* * When a user presses the "Upload Plugin" button, show the upload form in place * rather than sending them to the devoted upload plugin page. - * @todo consider to abstract this in a generic, reusable, utility, see theme.js + * The `?tab=upload` page still exists for no-js support and for plugins that + * might access it directly (?). When we're in this page, let the link behave + * like a link. Otherwise we're in the normal plugin installer pages and the + * link should behave like a toggle button. */ - var uploadViewToggle = $( '.upload-view-toggle' ), - $body = $( document.body ); - - uploadViewToggle - .attr({ - role: 'button', - 'aria-expanded': 'false' - }) - .on( 'click', function( event ) { - event.preventDefault(); - $body.toggleClass( 'show-upload-view' ); - uploadViewToggle.attr( 'aria-expanded', $body.hasClass( 'show-upload-view' ) ); - }); + if ( ! uploadViewToggle.hasClass( 'upload-tab' ) ) { + uploadViewToggle + .attr({ + role: 'button', + 'aria-expanded': 'false' + }) + .on( 'click', function( event ) { + event.preventDefault(); + $body.toggleClass( 'show-upload-view' ); + uploadViewToggle.attr( 'aria-expanded', $body.hasClass( 'show-upload-view' ) ); + }); + } });