2014-02-26 07:55:14 +01:00
|
|
|
window.wp = window.wp || {};
|
|
|
|
|
2015-02-11 06:06:28 +01:00
|
|
|
(function( $, wp, pagenow ) {
|
2014-02-26 07:55:14 +01:00
|
|
|
wp.updates = {};
|
|
|
|
|
|
|
|
/**
|
2015-02-05 05:19:23 +01:00
|
|
|
* User nonce for ajax calls.
|
|
|
|
*
|
|
|
|
* @since 4.2.0
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
wp.updates.ajaxNonce = window._wpUpdatesSettings.ajax_nonce;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Localized strings.
|
|
|
|
*
|
|
|
|
* @since 4.2.0
|
|
|
|
*
|
|
|
|
* @var object
|
|
|
|
*/
|
|
|
|
wp.updates.l10n = window._wpUpdatesSettings.l10n;
|
|
|
|
|
2015-03-18 04:18:27 +01:00
|
|
|
/**
|
|
|
|
* Whether filesystem credentials need to be requested from the user.
|
|
|
|
*
|
|
|
|
* @since 4.2.0
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
wp.updates.shouldRequestFilesystemCredentials = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filesystem credentials to be packaged along with the request.
|
|
|
|
*
|
|
|
|
* @since 4.2.0
|
|
|
|
*
|
|
|
|
* @var object
|
|
|
|
*/
|
|
|
|
wp.updates.filesystemCredentials = {
|
|
|
|
ftp: {
|
|
|
|
host: null,
|
|
|
|
username: null,
|
|
|
|
password: null,
|
|
|
|
connectionType: null
|
|
|
|
},
|
|
|
|
ssh: {
|
|
|
|
publicKey: null,
|
|
|
|
privateKey: null
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-02-05 05:19:23 +01:00
|
|
|
/**
|
|
|
|
* Flag if we're waiting for an install/update to complete.
|
|
|
|
*
|
|
|
|
* @since 4.2.0
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
wp.updates.updateLock = false;
|
|
|
|
|
2015-03-18 04:18:27 +01:00
|
|
|
/**
|
|
|
|
* * Flag if we've done an install or update successfully.
|
|
|
|
*
|
|
|
|
* @since 4.2.0
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
wp.updates.updateDoneSuccessfully = false;
|
|
|
|
|
2015-02-05 05:19:23 +01:00
|
|
|
/**
|
|
|
|
* If the user tries to install/update a plugin while an install/update is
|
|
|
|
* already happening, it can be placed in this queue to perform later.
|
|
|
|
*
|
|
|
|
* @since 4.2.0
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
wp.updates.updateQueue = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decrement update counts throughout the various menus.
|
|
|
|
*
|
|
|
|
* @since 3.9.0
|
2014-02-26 07:55:14 +01:00
|
|
|
*
|
|
|
|
* @param {string} updateType
|
|
|
|
*/
|
|
|
|
wp.updates.decrementCount = function( upgradeType ) {
|
2015-02-05 05:19:23 +01:00
|
|
|
var count,
|
|
|
|
pluginCount,
|
|
|
|
$adminBarUpdateCount = $( '#wp-admin-bar-updates .ab-label' ),
|
2015-02-05 20:52:22 +01:00
|
|
|
$dashboardNavMenuUpdateCount = $( 'a[href="update-core.php"] .update-plugins' ),
|
2015-02-05 05:19:23 +01:00
|
|
|
$pluginsMenuItem = $( '#menu-plugins' );
|
2014-02-26 07:55:14 +01:00
|
|
|
|
2015-02-05 05:19:23 +01:00
|
|
|
|
|
|
|
count = $adminBarUpdateCount.text();
|
2014-02-26 07:55:14 +01:00
|
|
|
count = parseInt( count, 10 ) - 1;
|
2014-10-18 21:55:18 +02:00
|
|
|
if ( count < 0 || isNaN( count ) ) {
|
2014-02-26 07:55:14 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-02-26 08:37:14 +01:00
|
|
|
$( '#wp-admin-bar-updates .ab-item' ).removeAttr( 'title' );
|
2015-02-05 05:19:23 +01:00
|
|
|
$adminBarUpdateCount.text( count );
|
|
|
|
|
2014-02-26 07:55:14 +01:00
|
|
|
|
2015-02-05 05:19:23 +01:00
|
|
|
$dashboardNavMenuUpdateCount.each( function( index, elem ) {
|
2014-02-26 07:55:14 +01:00
|
|
|
elem.className = elem.className.replace( /count-\d+/, 'count-' + count );
|
|
|
|
} );
|
2015-02-05 05:19:23 +01:00
|
|
|
$dashboardNavMenuUpdateCount.removeAttr( 'title' );
|
|
|
|
$dashboardNavMenuUpdateCount.find( '.update-count' ).text( count );
|
2014-02-26 07:55:14 +01:00
|
|
|
|
|
|
|
if ( 'plugin' === upgradeType ) {
|
2015-02-05 05:19:23 +01:00
|
|
|
pluginCount = $pluginsMenuItem.find( '.plugin-count' ).eq(0).text();
|
2014-02-26 07:55:14 +01:00
|
|
|
pluginCount = parseInt( pluginCount, 10 ) - 1;
|
2014-10-18 21:55:18 +02:00
|
|
|
if ( pluginCount < 0 || isNaN( pluginCount ) ) {
|
2014-02-26 07:55:14 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-02-05 05:19:23 +01:00
|
|
|
$pluginsMenuItem.find( '.plugin-count' ).text( pluginCount );
|
|
|
|
$pluginsMenuItem.find( '.update-plugins' ).each( function( index, elem ) {
|
2014-02-26 07:55:14 +01:00
|
|
|
elem.className = elem.className.replace( /count-\d+/, 'count-' + pluginCount );
|
|
|
|
} );
|
2015-02-05 05:19:23 +01:00
|
|
|
|
|
|
|
if (pluginCount > 0 ) {
|
|
|
|
$( '.subsubsub .upgrade .count' ).text( '(' + pluginCount + ')' );
|
|
|
|
} else {
|
|
|
|
$( '.subsubsub .upgrade' ).remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send an Ajax request to the server to update a plugin.
|
|
|
|
*
|
|
|
|
* @since 4.2.0
|
|
|
|
*
|
|
|
|
* @param {string} plugin
|
|
|
|
* @param {string} slug
|
|
|
|
*/
|
|
|
|
wp.updates.updatePlugin = function( plugin, slug ) {
|
|
|
|
var $message;
|
|
|
|
if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
|
2015-03-19 06:26:28 +01:00
|
|
|
$message = $( '[data-slug="' + slug + '"]' ).next().find( '.update-message' );
|
2015-02-05 05:19:23 +01:00
|
|
|
} else if ( 'plugin-install' === pagenow ) {
|
|
|
|
$message = $( '.plugin-card-' + slug ).find( '.update-now' );
|
|
|
|
}
|
|
|
|
|
|
|
|
$message.addClass( 'updating-message' );
|
|
|
|
$message.text( wp.updates.l10n.updating );
|
2015-03-01 20:11:27 +01:00
|
|
|
wp.a11y.speak( wp.updates.l10n.updatingMsg );
|
2015-02-05 05:19:23 +01:00
|
|
|
|
|
|
|
if ( wp.updates.updateLock ) {
|
|
|
|
wp.updates.updateQueue.push( {
|
|
|
|
type: 'update-plugin',
|
|
|
|
data: {
|
|
|
|
plugin: plugin,
|
|
|
|
slug: slug
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
return;
|
2014-02-26 07:55:14 +01:00
|
|
|
}
|
2015-02-05 05:19:23 +01:00
|
|
|
|
|
|
|
wp.updates.updateLock = true;
|
|
|
|
|
|
|
|
var data = {
|
2015-03-18 04:18:27 +01:00
|
|
|
_ajax_nonce: wp.updates.ajaxNonce,
|
|
|
|
plugin: plugin,
|
|
|
|
slug: slug,
|
|
|
|
username: wp.updates.filesystemCredentials.ftp.username,
|
|
|
|
password: wp.updates.filesystemCredentials.ftp.password,
|
|
|
|
hostname: wp.updates.filesystemCredentials.ftp.hostname,
|
|
|
|
connection_type: wp.updates.filesystemCredentials.ftp.connectionType,
|
|
|
|
public_key: wp.updates.filesystemCredentials.ssh.publicKey,
|
|
|
|
private_key: wp.updates.filesystemCredentials.ssh.privateKey
|
2015-02-05 05:19:23 +01:00
|
|
|
};
|
|
|
|
|
2015-02-11 06:06:28 +01:00
|
|
|
wp.ajax.post( 'update-plugin', data )
|
|
|
|
.done( wp.updates.updateSuccess )
|
2015-03-18 04:18:27 +01:00
|
|
|
.fail( wp.updates.updateError );
|
2015-02-05 20:52:22 +01:00
|
|
|
};
|
2015-02-05 05:19:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* On a successful plugin update, update the UI with the result.
|
|
|
|
*
|
|
|
|
* @since 4.2.0
|
|
|
|
*
|
|
|
|
* @param {object} response
|
|
|
|
*/
|
|
|
|
wp.updates.updateSuccess = function( response ) {
|
2015-03-19 06:26:28 +01:00
|
|
|
var $updateMessage;
|
2015-02-05 05:19:23 +01:00
|
|
|
if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
|
2015-03-19 06:26:28 +01:00
|
|
|
var $pluginRow = $( '[data-slug="' + response.slug + '"]' ).first();
|
|
|
|
$updateMessage = $pluginRow.next().find( '.update-message' );
|
|
|
|
$pluginRow.addClass( 'updated' ).removeClass( 'update' );
|
|
|
|
|
2015-03-18 04:18:27 +01:00
|
|
|
// Update the version number in the row.
|
2015-03-19 06:26:28 +01:00
|
|
|
var newText = $pluginRow.find('.plugin-version-author-uri').html().replace( response.oldVersion, response.newVersion );
|
|
|
|
$pluginRow.find('.plugin-version-author-uri').html( newText );
|
2015-02-05 05:19:23 +01:00
|
|
|
} else if ( 'plugin-install' === pagenow ) {
|
2015-03-19 06:26:28 +01:00
|
|
|
$updateMessage = $( '.plugin-card-' + response.slug ).find( '.update-now' );
|
|
|
|
$updateMessage.addClass( 'button-disabled' );
|
2015-02-05 05:19:23 +01:00
|
|
|
}
|
|
|
|
|
2015-03-19 06:26:28 +01:00
|
|
|
$updateMessage.removeClass( 'updating-message' ).addClass( 'updated-message' );
|
|
|
|
$updateMessage.text( wp.updates.l10n.updated );
|
2015-03-01 20:11:27 +01:00
|
|
|
wp.a11y.speak( wp.updates.l10n.updatedMsg );
|
2015-02-05 05:19:23 +01:00
|
|
|
|
|
|
|
wp.updates.decrementCount( 'plugin' );
|
2015-03-18 04:18:27 +01:00
|
|
|
|
|
|
|
wp.updates.updateDoneSuccessfully = true;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The lock can be released since the update was successful,
|
|
|
|
* and any other updates can commence.
|
|
|
|
*/
|
|
|
|
wp.updates.updateLock = false;
|
|
|
|
wp.updates.queueChecker();
|
2015-02-05 05:19:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On a plugin update error, update the UI appropriately.
|
|
|
|
*
|
|
|
|
* @since 4.2.0
|
|
|
|
*
|
|
|
|
* @param {object} response
|
|
|
|
*/
|
|
|
|
wp.updates.updateError = function( response ) {
|
|
|
|
var $message;
|
2015-03-18 04:18:27 +01:00
|
|
|
wp.updates.updateDoneSuccessfully = false;
|
|
|
|
if ( response.errorCode && response.errorCode == 'unable_to_connect_to_filesystem' ) {
|
|
|
|
wp.updates.credentialError( response, 'update-plugin' );
|
|
|
|
return;
|
|
|
|
}
|
2015-02-05 05:19:23 +01:00
|
|
|
if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
|
2015-03-19 06:26:28 +01:00
|
|
|
$message = $( '[data-slug="' + response.slug + '"]' ).next().find( '.update-message' );
|
2015-02-05 05:19:23 +01:00
|
|
|
} else if ( 'plugin-install' === pagenow ) {
|
2015-02-11 06:06:28 +01:00
|
|
|
$message = $( '.plugin-card-' + response.slug ).find( '.update-now' );
|
2015-02-05 05:19:23 +01:00
|
|
|
}
|
|
|
|
$message.removeClass( 'updating-message' );
|
|
|
|
$message.text( wp.updates.l10n.updateFailed );
|
2015-03-01 20:11:27 +01:00
|
|
|
wp.a11y.speak( wp.updates.l10n.updateFailed );
|
2015-03-18 04:18:27 +01:00
|
|
|
|
2015-02-05 05:19:23 +01:00
|
|
|
};
|
|
|
|
|
2015-02-11 06:06:28 +01:00
|
|
|
/**
|
2015-03-18 04:18:27 +01:00
|
|
|
* Show an error message in the request for credentials form.
|
2015-02-11 06:06:28 +01:00
|
|
|
*
|
2015-03-18 04:18:27 +01:00
|
|
|
* @param {string} message
|
2015-02-11 06:06:28 +01:00
|
|
|
* @since 4.2.0
|
|
|
|
*/
|
2015-03-18 04:18:27 +01:00
|
|
|
wp.updates.showErrorInCredentialsForm = function( message ) {
|
|
|
|
var $notificationDialog = $( '.notification-dialog' );
|
|
|
|
|
|
|
|
// Remove any existing error
|
|
|
|
$notificationDialog.find( '.error' ).remove();
|
2015-02-11 06:06:28 +01:00
|
|
|
|
2015-03-18 04:18:27 +01:00
|
|
|
$notificationDialog.find( 'h3' ).after( '<div class="error">' + message + '</div>' );
|
|
|
|
};
|
2015-02-11 06:06:28 +01:00
|
|
|
|
2015-02-05 05:19:23 +01:00
|
|
|
/**
|
|
|
|
* Send an Ajax request to the server to install a plugin.
|
|
|
|
*
|
|
|
|
* @since 4.2.0
|
|
|
|
*
|
|
|
|
* @param {string} slug
|
|
|
|
*/
|
|
|
|
wp.updates.installPlugin = function( slug ) {
|
|
|
|
var $message = $( '.plugin-card-' + slug ).find( '.install-now' );
|
|
|
|
|
|
|
|
$message.addClass( 'updating-message' );
|
|
|
|
$message.text( wp.updates.l10n.installing );
|
2015-03-01 20:11:27 +01:00
|
|
|
wp.a11y.speak( wp.updates.l10n.installingMsg );
|
2015-02-05 05:19:23 +01:00
|
|
|
|
|
|
|
if ( wp.updates.updateLock ) {
|
|
|
|
wp.updates.updateQueue.push( {
|
|
|
|
type: 'install-plugin',
|
|
|
|
data: {
|
|
|
|
slug: slug
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wp.updates.updateLock = true;
|
|
|
|
|
|
|
|
var data = {
|
2015-03-18 04:18:27 +01:00
|
|
|
_ajax_nonce: wp.updates.ajaxNonce,
|
|
|
|
slug: slug,
|
|
|
|
username: wp.updates.filesystemCredentials.ftp.username,
|
|
|
|
password: wp.updates.filesystemCredentials.ftp.password,
|
|
|
|
hostname: wp.updates.filesystemCredentials.ftp.hostname,
|
|
|
|
connection_type: wp.updates.filesystemCredentials.ftp.connectionType,
|
|
|
|
public_key: wp.updates.filesystemCredentials.ssh.publicKey,
|
|
|
|
private_key: wp.updates.filesystemCredentials.ssh.privateKey
|
2015-02-05 05:19:23 +01:00
|
|
|
};
|
|
|
|
|
2015-02-11 06:06:28 +01:00
|
|
|
wp.ajax.post( 'install-plugin', data )
|
|
|
|
.done( wp.updates.installSuccess )
|
2015-03-18 04:18:27 +01:00
|
|
|
.fail( wp.updates.installError );
|
2015-02-05 05:19:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On plugin install success, update the UI with the result.
|
|
|
|
*
|
|
|
|
* @since 4.2.0
|
|
|
|
*
|
|
|
|
* @param {object} response
|
|
|
|
*/
|
|
|
|
wp.updates.installSuccess = function( response ) {
|
2015-02-11 06:06:28 +01:00
|
|
|
var $message = $( '.plugin-card-' + response.slug ).find( '.install-now' );
|
2015-02-05 05:19:23 +01:00
|
|
|
|
|
|
|
$message.removeClass( 'updating-message' ).addClass( 'updated-message button-disabled' );
|
|
|
|
$message.text( wp.updates.l10n.installed );
|
2015-03-01 20:11:27 +01:00
|
|
|
wp.a11y.speak( wp.updates.l10n.installedMsg );
|
2015-03-18 04:18:27 +01:00
|
|
|
wp.updates.updateDoneSuccessfully = true;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The lock can be released since the update was successful,
|
|
|
|
* and any other updates can commence.
|
|
|
|
*/
|
|
|
|
wp.updates.updateLock = false;
|
|
|
|
wp.updates.queueChecker();
|
2015-02-05 05:19:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On plugin install failure, update the UI appropriately.
|
|
|
|
*
|
|
|
|
* @since 4.2.0
|
|
|
|
*
|
|
|
|
* @param {object} response
|
|
|
|
*/
|
|
|
|
wp.updates.installError = function( response ) {
|
2015-02-11 06:06:28 +01:00
|
|
|
var $message = $( '.plugin-card-' + response.slug ).find( '.install-now' );
|
2015-03-18 04:18:27 +01:00
|
|
|
wp.updates.updateDoneSuccessfully = false;
|
|
|
|
if ( response.errorCode && response.errorCode == 'unable_to_connect_to_filesystem' ) {
|
|
|
|
wp.updates.credentialError( response, 'install-plugin' );
|
|
|
|
return;
|
|
|
|
}
|
2015-02-05 05:19:23 +01:00
|
|
|
|
|
|
|
$message.removeClass( 'updating-message' );
|
|
|
|
$message.text( wp.updates.l10n.installNow );
|
2015-03-18 04:18:27 +01:00
|
|
|
|
|
|
|
wp.updates.updateLock = false;
|
2015-02-05 05:19:23 +01:00
|
|
|
};
|
|
|
|
|
2015-03-18 04:18:27 +01:00
|
|
|
/**
|
|
|
|
* Events that need to happen when there is a credential error
|
|
|
|
*
|
|
|
|
* @since 4.2.0
|
|
|
|
*/
|
|
|
|
wp.updates.credentialError = function( response, type ) {
|
|
|
|
wp.updates.updateQueue.push( {
|
|
|
|
'type': type,
|
|
|
|
'data': {
|
|
|
|
// Not cool that we're depending on response for this data.
|
|
|
|
// This would feel more whole in a view all tied together.
|
|
|
|
plugin: response.plugin,
|
|
|
|
slug: response.slug
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
wp.updates.showErrorInCredentialsForm( response.error );
|
|
|
|
wp.updates.requestFilesystemCredentials();
|
|
|
|
};
|
2015-02-05 05:19:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If an install/update job has been placed in the queue, queueChecker pulls it out and runs it.
|
|
|
|
*
|
|
|
|
* @since 4.2.0
|
|
|
|
*/
|
|
|
|
wp.updates.queueChecker = function() {
|
|
|
|
if ( wp.updates.updateLock || wp.updates.updateQueue.length <= 0 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var job = wp.updates.updateQueue.shift();
|
|
|
|
|
|
|
|
switch ( job.type ) {
|
|
|
|
case 'update-plugin':
|
|
|
|
wp.updates.updatePlugin( job.data.plugin, job.data.slug );
|
|
|
|
break;
|
|
|
|
case 'install-plugin':
|
|
|
|
wp.updates.installPlugin( job.data.slug );
|
|
|
|
break;
|
|
|
|
default:
|
2015-02-05 20:52:22 +01:00
|
|
|
window.console.log( 'Failed to exect queued update job.' );
|
|
|
|
window.console.log( job );
|
2015-02-05 05:19:23 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-18 04:18:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Request the users filesystem credentials if we don't have them already
|
|
|
|
*
|
|
|
|
* @since 4.2.0
|
|
|
|
*/
|
|
|
|
wp.updates.requestFilesystemCredentials = function() {
|
|
|
|
if ( wp.updates.updateDoneSuccessfully === false ) {
|
|
|
|
wp.updates.updateLock = true;
|
|
|
|
$( 'body' ).addClass( 'modal-open' );
|
|
|
|
$( '#request-filesystem-credentials-dialog' ).show();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-02-05 05:19:23 +01:00
|
|
|
$( document ).ready( function() {
|
2015-03-18 04:18:27 +01:00
|
|
|
/*
|
|
|
|
* Check whether a user needs to submit filesystem credentials based on whether
|
|
|
|
* the form was output on the page server-side.
|
|
|
|
*
|
|
|
|
* @see {wp_print_request_filesystem_credentials_modal() in PHP}
|
|
|
|
*/
|
|
|
|
wp.updates.shouldRequestFilesystemCredentials = ( $( '#request-filesystem-credentials-dialog' ).length <= 0 ) ? false : true;
|
|
|
|
|
|
|
|
// File system credentials form submit noop-er / handler.
|
|
|
|
$( '#request-filesystem-credentials-dialog form' ).on( 'submit', function() {
|
|
|
|
// Persist the credentials input by the user for the duration of the page load.
|
|
|
|
wp.updates.filesystemCredentials.ftp.hostname = $('#hostname').val();
|
|
|
|
wp.updates.filesystemCredentials.ftp.username = $('#username').val();
|
|
|
|
wp.updates.filesystemCredentials.ftp.password = $('#password').val();
|
|
|
|
wp.updates.filesystemCredentials.ftp.connectionType = $('input[name="connection_type"]:checked').val();
|
|
|
|
wp.updates.filesystemCredentials.ssh.publicKey = $('#public_key').val();
|
|
|
|
wp.updates.filesystemCredentials.ssh.privateKey = $('#private_key').val();
|
|
|
|
|
|
|
|
$( '#request-filesystem-credentials-dialog' ).hide();
|
|
|
|
$( 'body' ).removeClass( 'modal-open' );
|
|
|
|
|
|
|
|
// Unlock and invoke the queue.
|
|
|
|
wp.updates.updateLock = false;
|
|
|
|
wp.updates.queueChecker();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Click handler for plugin updates in List Table view.
|
2015-02-05 05:19:23 +01:00
|
|
|
$( '.plugin-update-tr .update-link' ).on( 'click', function( e ) {
|
|
|
|
e.preventDefault();
|
2015-03-18 04:18:27 +01:00
|
|
|
if ( wp.updates.shouldRequestFilesystemCredentials && ! wp.updates.updateLock ) {
|
|
|
|
wp.updates.requestFilesystemCredentials();
|
|
|
|
}
|
2015-02-05 05:19:23 +01:00
|
|
|
var $row = $( e.target ).parents( '.plugin-update-tr' );
|
|
|
|
wp.updates.updatePlugin( $row.data( 'plugin' ), $row.data( 'slug' ) );
|
|
|
|
} );
|
|
|
|
|
|
|
|
$( '#bulk-action-form' ).on( 'submit', function( e ) {
|
2015-02-05 20:52:22 +01:00
|
|
|
var $checkbox, plugin, slug;
|
2015-02-05 05:19:23 +01:00
|
|
|
|
|
|
|
if ( $( '#bulk-action-selector-top' ).val() == 'update-selected' ) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
$( 'input[name="checked[]"]:checked' ).each( function( index, elem ) {
|
|
|
|
$checkbox = $( elem );
|
|
|
|
plugin = $checkbox.val();
|
|
|
|
slug = $checkbox.parents( 'tr' ).prop( 'id' );
|
|
|
|
|
|
|
|
wp.updates.updatePlugin( plugin, slug );
|
|
|
|
|
|
|
|
$checkbox.attr( 'checked', false );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
$( '.plugin-card .update-now' ).on( 'click', function( e ) {
|
|
|
|
e.preventDefault();
|
2015-02-05 20:52:22 +01:00
|
|
|
var $button = $( e.target );
|
2015-02-05 05:19:23 +01:00
|
|
|
wp.updates.updatePlugin( $button.data( 'plugin' ), $button.data( 'slug' ) );
|
|
|
|
} );
|
|
|
|
|
|
|
|
$( '.plugin-card .install-now' ).on( 'click', function( e ) {
|
|
|
|
e.preventDefault();
|
2015-03-18 04:18:27 +01:00
|
|
|
if ( wp.updates.shouldRequestFilesystemCredentials && ! wp.updates.updateLock ) {
|
|
|
|
wp.updates.requestFilesystemCredentials();
|
|
|
|
}
|
2015-02-05 20:52:22 +01:00
|
|
|
var $button = $( e.target );
|
2015-02-05 05:19:23 +01:00
|
|
|
if ( $button.hasClass( 'button-disabled' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wp.updates.installPlugin( $button.data( 'slug' ) );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2014-02-26 07:55:14 +01:00
|
|
|
$( window ).on( 'message', function( e ) {
|
|
|
|
var event = e.originalEvent,
|
|
|
|
message,
|
|
|
|
loc = document.location,
|
|
|
|
expectedOrigin = loc.protocol + '//' + loc.hostname;
|
|
|
|
|
|
|
|
if ( event.origin !== expectedOrigin ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
message = $.parseJSON( event.data );
|
|
|
|
|
|
|
|
if ( typeof message.action === 'undefined' || message.action !== 'decrementUpdateCount' ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wp.updates.decrementCount( message.upgradeType );
|
|
|
|
|
|
|
|
} );
|
|
|
|
|
2015-02-05 20:52:22 +01:00
|
|
|
})( jQuery, window.wp, window.pagenow, window.ajaxurl );
|