Enable users to initiate a shiny update from plugin detail modal

The plugin detail modal can contain a link to update a plugin.  When it does, we should initiate a shiny update.

This relies upon postMessage which isn't available in all browsers, specifically it isn't in IE versions below 8 so this is going to be a progressive enhancement that some small percentage of users will miss out on.  These are the same users that can't use the customizer. 

Fixes #31739



Built from https://develop.svn.wordpress.org/trunk@32062


git-svn-id: http://core.svn.wordpress.org/trunk@32041 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Aaron Jorbin 2015-04-07 03:09:26 +00:00
parent 1985d00886
commit 99d6c67148
4 changed files with 44 additions and 5 deletions

View File

@ -561,7 +561,7 @@ function install_plugin_information() {
break; break;
case 'update_available': case 'update_available':
if ( $status['url'] ) { if ( $status['url'] ) {
echo '<a class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) .'</a>'; echo '<a data-slug="' . esc_attr( $api->slug ) . '" id="plugin_update_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) .'</a>';
} }
break; break;
case 'newer_installed': case 'newer_installed':

View File

@ -1,3 +1,4 @@
/* global tb_remove */
window.wp = window.wp || {}; window.wp = window.wp || {};
(function( $, wp, pagenow ) { (function( $, wp, pagenow ) {
@ -473,6 +474,26 @@ window.wp = window.wp || {};
wp.updates.updatePlugin( $button.data( 'plugin' ), $button.data( 'slug' ) ); wp.updates.updatePlugin( $button.data( 'plugin' ), $button.data( 'slug' ) );
} ); } );
//
$( '#plugin_update_from_iframe' ).on( 'click' , function( e ) {
var target, data;
target = window.parent == window ? null : window.parent,
$.support.postMessage = !! window.postMessage;
if ( $.support.postMessage === false || target === null )
return;
e.preventDefault();
data = {
'action' : 'updatePlugin',
'slug' : $(this).data('slug')
};
target.postMessage( JSON.stringify( data ), window.location.origin );
});
} ); } );
$( window ).on( 'message', function( e ) { $( window ).on( 'message', function( e ) {
@ -487,11 +508,29 @@ window.wp = window.wp || {};
message = $.parseJSON( event.data ); message = $.parseJSON( event.data );
if ( typeof message.action === 'undefined' || message.action !== 'decrementUpdateCount' ) { if ( typeof message.action === 'undefined' ) {
return; return;
} }
wp.updates.decrementCount( message.upgradeType ); switch (message.action){
case 'decrementUpdateCount' :
wp.updates.decrementCount( message.upgradeType );
break;
case 'updatePlugin' :
tb_remove();
if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
// Return the user to the input box of the plugin's table row after closing the modal.
$( '#' + message.slug ).find( '.check-column input' ).focus();
// trigger the update
$( '.plugin-update-tr[data-slug="' + message.slug + '"]' ).find( '.update-link' ).trigger( 'click' );
} else if ( 'plugin-install' === pagenow ) {
$( '.plugin-card-' + message.slug ).find( 'h4 a' ).focus();
$( '.plugin-card-' + message.slug ).find( '[data-slug="' + message.slug + '"]' ).trigger( 'click' );
}
break;
}
} ); } );

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.2-beta4-32061'; $wp_version = '4.2-beta4-32062';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.