6 */ |
6 */ |
7 |
7 |
8 /* global pagenow */ |
8 /* global pagenow */ |
9 |
9 |
10 /** |
10 /** |
11 * @param {jQuery} $ jQuery object. |
11 * @param {jQuery} $ jQuery object. |
12 * @param {object} wp WP object. |
12 * @param {object} wp WP object. |
13 * @param {object} settings WP Updates settings. |
13 * @param {object} settings WP Updates settings. |
14 * @param {string} settings.ajax_nonce Ajax nonce. |
14 * @param {string} settings.ajax_nonce Ajax nonce. |
15 * @param {object=} settings.plugins Base names of plugins in their different states. |
15 * @param {object=} settings.plugins Base names of plugins in their different states. |
16 * @param {Array} settings.plugins.all Base names of all plugins. |
16 * @param {Array} settings.plugins.all Base names of all plugins. |
17 * @param {Array} settings.plugins.active Base names of active plugins. |
17 * @param {Array} settings.plugins.active Base names of active plugins. |
18 * @param {Array} settings.plugins.inactive Base names of inactive plugins. |
18 * @param {Array} settings.plugins.inactive Base names of inactive plugins. |
19 * @param {Array} settings.plugins.upgrade Base names of plugins with updates available. |
19 * @param {Array} settings.plugins.upgrade Base names of plugins with updates available. |
20 * @param {Array} settings.plugins.recently_activated Base names of recently activated plugins. |
20 * @param {Array} settings.plugins.recently_activated Base names of recently activated plugins. |
21 * @param {object=} settings.themes Plugin/theme status information or null. |
21 * @param {Array} settings.plugins['auto-update-enabled'] Base names of plugins set to auto-update. |
22 * @param {number} settings.themes.all Amount of all themes. |
22 * @param {Array} settings.plugins['auto-update-disabled'] Base names of plugins set to not auto-update. |
23 * @param {number} settings.themes.upgrade Amount of themes with updates available. |
23 * @param {object=} settings.themes Slugs of themes in their different states. |
24 * @param {number} settings.themes.disabled Amount of disabled themes. |
24 * @param {Array} settings.themes.all Slugs of all themes. |
25 * @param {object=} settings.totals Combined information for available update counts. |
25 * @param {Array} settings.themes.upgrade Slugs of themes with updates available. |
26 * @param {number} settings.totals.count Holds the amount of available updates. |
26 * @param {Arrat} settings.themes.disabled Slugs of disabled themes. |
|
27 * @param {Array} settings.themes['auto-update-enabled'] Slugs of themes set to auto-update. |
|
28 * @param {Array} settings.themes['auto-update-disabled'] Slugs of themes set to not auto-update. |
|
29 * @param {object=} settings.totals Combined information for available update counts. |
|
30 * @param {number} settings.totals.count Holds the amount of available updates. |
27 */ |
31 */ |
28 (function( $, wp, settings ) { |
32 (function( $, wp, settings ) { |
29 var $document = $( document ), |
33 var $document = $( document ), |
30 __ = wp.i18n.__, |
34 __ = wp.i18n.__, |
31 _x = wp.i18n._x, |
35 _x = wp.i18n._x, |
113 autoUpdatesDisabling: '', |
117 autoUpdatesDisabling: '', |
114 autoUpdatesDisabled: '', |
118 autoUpdatesDisabled: '', |
115 autoUpdatesError: '' |
119 autoUpdatesError: '' |
116 }; |
120 }; |
117 |
121 |
118 wp.updates.l10n = window.wp.deprecateL10nObject( 'wp.updates.l10n', wp.updates.l10n ); |
122 wp.updates.l10n = window.wp.deprecateL10nObject( 'wp.updates.l10n', wp.updates.l10n, '5.5.0' ); |
119 |
123 |
120 /** |
124 /** |
121 * User nonce for ajax calls. |
125 * User nonce for ajax calls. |
122 * |
126 * |
123 * @since 4.2.0 |
127 * @since 4.2.0 |
437 * @param {updatePluginError=} args.error Optional. Error callback. Default: wp.updates.updatePluginError |
441 * @param {updatePluginError=} args.error Optional. Error callback. Default: wp.updates.updatePluginError |
438 * @return {$.promise} A jQuery promise that represents the request, |
442 * @return {$.promise} A jQuery promise that represents the request, |
439 * decorated with an abort() method. |
443 * decorated with an abort() method. |
440 */ |
444 */ |
441 wp.updates.updatePlugin = function( args ) { |
445 wp.updates.updatePlugin = function( args ) { |
442 var $updateRow, $card, $message, message; |
446 var $updateRow, $card, $message, message, |
|
447 $adminBarUpdates = $( '#wp-admin-bar-updates' ); |
443 |
448 |
444 args = _.extend( { |
449 args = _.extend( { |
445 success: wp.updates.updatePluginSuccess, |
450 success: wp.updates.updatePluginSuccess, |
446 error: wp.updates.updatePluginError |
451 error: wp.updates.updatePluginError |
447 }, args ); |
452 }, args ); |
465 |
470 |
466 // Remove previous error messages, if any. |
471 // Remove previous error messages, if any. |
467 $card.removeClass( 'plugin-card-update-failed' ).find( '.notice.notice-error' ).remove(); |
472 $card.removeClass( 'plugin-card-update-failed' ).find( '.notice.notice-error' ).remove(); |
468 } |
473 } |
469 |
474 |
|
475 $adminBarUpdates.addClass( 'spin' ); |
|
476 |
470 if ( $message.html() !== __( 'Updating...' ) ) { |
477 if ( $message.html() !== __( 'Updating...' ) ) { |
471 $message.data( 'originaltext', $message.html() ); |
478 $message.data( 'originaltext', $message.html() ); |
472 } |
479 } |
473 |
480 |
474 $message |
481 $message |
493 * @param {string} response.pluginName Name of the plugin to be updated. |
500 * @param {string} response.pluginName Name of the plugin to be updated. |
494 * @param {string} response.oldVersion Old version of the plugin. |
501 * @param {string} response.oldVersion Old version of the plugin. |
495 * @param {string} response.newVersion New version of the plugin. |
502 * @param {string} response.newVersion New version of the plugin. |
496 */ |
503 */ |
497 wp.updates.updatePluginSuccess = function( response ) { |
504 wp.updates.updatePluginSuccess = function( response ) { |
498 var $pluginRow, $updateMessage, newText; |
505 var $pluginRow, $updateMessage, newText, |
|
506 $adminBarUpdates = $( '#wp-admin-bar-updates' ); |
499 |
507 |
500 if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) { |
508 if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) { |
501 $pluginRow = $( 'tr[data-plugin="' + response.plugin + '"]' ) |
509 $pluginRow = $( 'tr[data-plugin="' + response.plugin + '"]' ) |
502 .removeClass( 'update' ) |
510 .removeClass( 'update' ) |
503 .addClass( 'updated' ); |
511 .addClass( 'updated' ); |
547 * @param {string=} response.pluginName Optional. Name of the plugin to be updated. |
557 * @param {string=} response.pluginName Optional. Name of the plugin to be updated. |
548 * @param {string} response.errorCode Error code for the error that occurred. |
558 * @param {string} response.errorCode Error code for the error that occurred. |
549 * @param {string} response.errorMessage The error that occurred. |
559 * @param {string} response.errorMessage The error that occurred. |
550 */ |
560 */ |
551 wp.updates.updatePluginError = function( response ) { |
561 wp.updates.updatePluginError = function( response ) { |
552 var $card, $message, errorMessage; |
562 var $card, $message, errorMessage, |
|
563 $adminBarUpdates = $( '#wp-admin-bar-updates' ); |
553 |
564 |
554 if ( ! wp.updates.isValidResponse( response, 'update' ) ) { |
565 if ( ! wp.updates.isValidResponse( response, 'update' ) ) { |
555 return; |
566 return; |
556 } |
567 } |
557 |
568 |
616 |
627 |
617 // Use same delay as the total duration of the notice fadeTo + slideUp animation. |
628 // Use same delay as the total duration of the notice fadeTo + slideUp animation. |
618 setTimeout( function() { |
629 setTimeout( function() { |
619 $card |
630 $card |
620 .removeClass( 'plugin-card-update-failed' ) |
631 .removeClass( 'plugin-card-update-failed' ) |
621 .find( '.column-name a' ).focus(); |
632 .find( '.column-name a' ).trigger( 'focus' ); |
622 |
633 |
623 $card.find( '.update-now' ) |
634 $card.find( '.update-now' ) |
624 .attr( 'aria-label', false ) |
635 .attr( 'aria-label', false ) |
625 .text( __( 'Update Now' ) ); |
636 .text( __( 'Update Now' ) ); |
626 }, 200 ); |
637 }, 200 ); |
627 } ); |
638 } ); |
628 } |
639 } |
|
640 |
|
641 $adminBarUpdates.removeClass( 'spin' ); |
629 |
642 |
630 wp.a11y.speak( errorMessage, 'assertive' ); |
643 wp.a11y.speak( errorMessage, 'assertive' ); |
631 |
644 |
632 $document.trigger( 'wp-plugin-update-error', response ); |
645 $document.trigger( 'wp-plugin-update-error', response ); |
633 }; |
646 }; |
786 |
799 |
787 // Use same delay as the total duration of the notice fadeTo + slideUp animation. |
800 // Use same delay as the total duration of the notice fadeTo + slideUp animation. |
788 setTimeout( function() { |
801 setTimeout( function() { |
789 $card |
802 $card |
790 .removeClass( 'plugin-card-update-failed' ) |
803 .removeClass( 'plugin-card-update-failed' ) |
791 .find( '.column-name a' ).focus(); |
804 .find( '.column-name a' ).trigger( 'focus' ); |
792 }, 200 ); |
805 }, 200 ); |
793 } ); |
806 } ); |
794 |
807 |
795 $button |
808 $button |
796 .removeClass( 'updating-message' ).addClass( 'button-disabled' ) |
809 .removeClass( 'updating-message' ).addClass( 'button-disabled' ) |
1005 } else { |
1018 } else { |
1006 $views.find( '.recently_activated' ).remove(); |
1019 $views.find( '.recently_activated' ).remove(); |
1007 } |
1020 } |
1008 } |
1021 } |
1009 |
1022 |
|
1023 if ( -1 !== _.indexOf( plugins['auto-update-enabled'], response.plugin ) ) { |
|
1024 plugins['auto-update-enabled'] = _.without( plugins['auto-update-enabled'], response.plugin ); |
|
1025 if ( plugins['auto-update-enabled'].length ) { |
|
1026 $views.find( '.auto-update-enabled .count' ).text( '(' + plugins['auto-update-enabled'].length + ')' ); |
|
1027 } else { |
|
1028 $views.find( '.auto-update-enabled' ).remove(); |
|
1029 } |
|
1030 } |
|
1031 |
|
1032 if ( -1 !== _.indexOf( plugins['auto-update-disabled'], response.plugin ) ) { |
|
1033 plugins['auto-update-disabled'] = _.without( plugins['auto-update-disabled'], response.plugin ); |
|
1034 if ( plugins['auto-update-disabled'].length ) { |
|
1035 $views.find( '.auto-update-disabled .count' ).text( '(' + plugins['auto-update-disabled'].length + ')' ); |
|
1036 } else { |
|
1037 $views.find( '.auto-update-disabled' ).remove(); |
|
1038 } |
|
1039 } |
|
1040 |
1010 plugins.all = _.without( plugins.all, response.plugin ); |
1041 plugins.all = _.without( plugins.all, response.plugin ); |
1011 |
1042 |
1012 if ( plugins.all.length ) { |
1043 if ( plugins.all.length ) { |
1013 $views.find( '.all .count' ).text( '(' + plugins.all.length + ')' ); |
1044 $views.find( '.all .count' ).text( '(' + plugins.all.length + ')' ); |
1014 } else { |
1045 } else { |
1182 } else { |
1213 } else { |
1183 $notice = $( '.theme-info .notice' ).add( $theme.find( '.update-message' ) ); |
1214 $notice = $( '.theme-info .notice' ).add( $theme.find( '.update-message' ) ); |
1184 |
1215 |
1185 // Focus on Customize button after updating. |
1216 // Focus on Customize button after updating. |
1186 if ( isModalOpen ) { |
1217 if ( isModalOpen ) { |
1187 $( '.load-customize:visible' ).focus(); |
1218 $( '.load-customize:visible' ).trigger( 'focus' ); |
1188 $( '.theme-info .theme-autoupdate' ).find( '.auto-update-time' ).empty(); |
1219 $( '.theme-info .theme-autoupdate' ).find( '.auto-update-time' ).empty(); |
1189 } else { |
1220 } else { |
1190 $theme.find( '.load-customize' ).focus(); |
1221 $theme.find( '.load-customize' ).trigger( 'focus' ); |
1191 } |
1222 } |
1192 } |
1223 } |
1193 |
1224 |
1194 wp.updates.addAdminNotice( _.extend( { selector: $notice }, updatedMessage ) ); |
1225 wp.updates.addAdminNotice( _.extend( { selector: $notice }, updatedMessage ) ); |
1195 wp.a11y.speak( __( 'Update completed successfully.' ) ); |
1226 wp.a11y.speak( __( 'Update completed successfully.' ) ); |
1238 if ( 'themes-network' === pagenow ) { |
1269 if ( 'themes-network' === pagenow ) { |
1239 $notice = $theme.find( '.update-message ' ); |
1270 $notice = $theme.find( '.update-message ' ); |
1240 } else { |
1271 } else { |
1241 $notice = $( '.theme-info .notice' ).add( $theme.find( '.notice' ) ); |
1272 $notice = $( '.theme-info .notice' ).add( $theme.find( '.notice' ) ); |
1242 |
1273 |
1243 $( 'body.modal-open' ).length ? $( '.load-customize:visible' ).focus() : $theme.find( '.load-customize' ).focus(); |
1274 $( 'body.modal-open' ).length ? $( '.load-customize:visible' ).trigger( 'focus' ) : $theme.find( '.load-customize' ).trigger( 'focus'); |
1244 } |
1275 } |
1245 |
1276 |
1246 wp.updates.addAdminNotice( { |
1277 wp.updates.addAdminNotice( { |
1247 selector: $notice, |
1278 selector: $notice, |
1248 className: 'update-message notice-error notice-alt is-dismissible', |
1279 className: 'update-message notice-error notice-alt is-dismissible', |
1503 |
1534 |
1504 // Removes the theme and updates rows. |
1535 // Removes the theme and updates rows. |
1505 $themeRows.css( { backgroundColor: '#faafaa' } ).fadeOut( 350, function() { |
1536 $themeRows.css( { backgroundColor: '#faafaa' } ).fadeOut( 350, function() { |
1506 var $views = $( '.subsubsub' ), |
1537 var $views = $( '.subsubsub' ), |
1507 $themeRow = $( this ), |
1538 $themeRow = $( this ), |
1508 totals = settings.themes, |
1539 themes = settings.themes, |
1509 deletedRow = wp.template( 'item-deleted-row' ); |
1540 deletedRow = wp.template( 'item-deleted-row' ); |
1510 |
1541 |
1511 if ( ! $themeRow.hasClass( 'plugin-update-tr' ) ) { |
1542 if ( ! $themeRow.hasClass( 'plugin-update-tr' ) ) { |
1512 $themeRow.after( |
1543 $themeRow.after( |
1513 deletedRow( { |
1544 deletedRow( { |
1519 } |
1550 } |
1520 |
1551 |
1521 $themeRow.remove(); |
1552 $themeRow.remove(); |
1522 |
1553 |
1523 // Remove theme from update count. |
1554 // Remove theme from update count. |
1524 if ( $themeRow.hasClass( 'update' ) ) { |
1555 if ( -1 !== _.indexOf( themes.upgrade, response.slug ) ) { |
1525 totals.upgrade--; |
1556 themes.upgrade = _.without( themes.upgrade, response.slug ); |
1526 wp.updates.decrementCount( 'theme' ); |
1557 wp.updates.decrementCount( 'theme' ); |
1527 } |
1558 } |
1528 |
1559 |
1529 // Remove from views. |
1560 // Remove from views. |
1530 if ( $themeRow.hasClass( 'inactive' ) ) { |
1561 if ( -1 !== _.indexOf( themes.disabled, response.slug ) ) { |
1531 totals.disabled--; |
1562 themes.disabled = _.without( themes.disabled, response.slug ); |
1532 if ( totals.disabled ) { |
1563 if ( themes.disabled.length ) { |
1533 $views.find( '.disabled .count' ).text( '(' + totals.disabled + ')' ); |
1564 $views.find( '.disabled .count' ).text( '(' + themes.disabled.length + ')' ); |
1534 } else { |
1565 } else { |
1535 $views.find( '.disabled' ).remove(); |
1566 $views.find( '.disabled' ).remove(); |
1536 } |
1567 } |
1537 } |
1568 } |
1538 |
1569 |
|
1570 if ( -1 !== _.indexOf( themes['auto-update-enabled'], response.slug ) ) { |
|
1571 themes['auto-update-enabled'] = _.without( themes['auto-update-enabled'], response.slug ); |
|
1572 if ( themes['auto-update-enabled'].length ) { |
|
1573 $views.find( '.auto-update-enabled .count' ).text( '(' + themes['auto-update-enabled'].length + ')' ); |
|
1574 } else { |
|
1575 $views.find( '.auto-update-enabled' ).remove(); |
|
1576 } |
|
1577 } |
|
1578 |
|
1579 if ( -1 !== _.indexOf( themes['auto-update-disabled'], response.slug ) ) { |
|
1580 themes['auto-update-disabled'] = _.without( themes['auto-update-disabled'], response.slug ); |
|
1581 if ( themes['auto-update-disabled'].length ) { |
|
1582 $views.find( '.auto-update-disabled .count' ).text( '(' + themes['auto-update-disabled'].length + ')' ); |
|
1583 } else { |
|
1584 $views.find( '.auto-update-disabled' ).remove(); |
|
1585 } |
|
1586 } |
|
1587 |
|
1588 themes.all = _.without( themes.all, response.slug ); |
|
1589 |
1539 // There is always at least one theme available. |
1590 // There is always at least one theme available. |
1540 $views.find( '.all .count' ).text( '(' + --totals.all + ')' ); |
1591 $views.find( '.all .count' ).text( '(' + themes.all.length + ')' ); |
1541 } ); |
1592 } ); |
1542 } |
1593 } |
1543 |
1594 |
1544 wp.a11y.speak( _x( 'Deleted!', 'theme' ) ); |
1595 wp.a11y.speak( _x( 'Deleted!', 'theme' ) ); |
1545 |
1596 |
1715 wp.updates.requestForCredentialsModalCancel(); |
1766 wp.updates.requestForCredentialsModalCancel(); |
1716 } else if ( 9 === event.keyCode ) { |
1767 } else if ( 9 === event.keyCode ) { |
1717 |
1768 |
1718 // #upgrade button must always be the last focus-able element in the dialog. |
1769 // #upgrade button must always be the last focus-able element in the dialog. |
1719 if ( 'upgrade' === event.target.id && ! event.shiftKey ) { |
1770 if ( 'upgrade' === event.target.id && ! event.shiftKey ) { |
1720 $( '#hostname' ).focus(); |
1771 $( '#hostname' ).trigger( 'focus' ); |
1721 |
1772 |
1722 event.preventDefault(); |
1773 event.preventDefault(); |
1723 } else if ( 'hostname' === event.target.id && event.shiftKey ) { |
1774 } else if ( 'hostname' === event.target.id && event.shiftKey ) { |
1724 $( '#upgrade' ).focus(); |
1775 $( '#upgrade' ).trigger( 'focus' ); |
1725 |
1776 |
1726 event.preventDefault(); |
1777 event.preventDefault(); |
1727 } |
1778 } |
1728 } |
1779 } |
1729 }; |
1780 }; |
1736 wp.updates.requestForCredentialsModalOpen = function() { |
1787 wp.updates.requestForCredentialsModalOpen = function() { |
1737 var $modal = $( '#request-filesystem-credentials-dialog' ); |
1788 var $modal = $( '#request-filesystem-credentials-dialog' ); |
1738 |
1789 |
1739 $( 'body' ).addClass( 'modal-open' ); |
1790 $( 'body' ).addClass( 'modal-open' ); |
1740 $modal.show(); |
1791 $modal.show(); |
1741 $modal.find( 'input:enabled:first' ).focus(); |
1792 $modal.find( 'input:enabled:first' ).trigger( 'focus' ); |
1742 $modal.on( 'keydown', wp.updates.keydown ); |
1793 $modal.on( 'keydown', wp.updates.keydown ); |
1743 }; |
1794 }; |
1744 |
1795 |
1745 /** |
1796 /** |
1746 * Closes the request for credentials modal. |
1797 * Closes the request for credentials modal. |
1750 wp.updates.requestForCredentialsModalClose = function() { |
1801 wp.updates.requestForCredentialsModalClose = function() { |
1751 $( '#request-filesystem-credentials-dialog' ).hide(); |
1802 $( '#request-filesystem-credentials-dialog' ).hide(); |
1752 $( 'body' ).removeClass( 'modal-open' ); |
1803 $( 'body' ).removeClass( 'modal-open' ); |
1753 |
1804 |
1754 if ( wp.updates.$elToReturnFocusToFromCredentialsModal ) { |
1805 if ( wp.updates.$elToReturnFocusToFromCredentialsModal ) { |
1755 wp.updates.$elToReturnFocusToFromCredentialsModal.focus(); |
1806 wp.updates.$elToReturnFocusToFromCredentialsModal.trigger( 'focus' ); |
1756 } |
1807 } |
1757 }; |
1808 }; |
1758 |
1809 |
1759 /** |
1810 /** |
1760 * Takes care of the steps that need to happen when the modal is canceled out. |
1811 * Takes care of the steps that need to happen when the modal is canceled out. |
2578 |
2629 |
2579 // Can we just ditch this whole subtitle business? |
2630 // Can we just ditch this whole subtitle business? |
2580 var $subTitle = $( '<span />' ).addClass( 'subtitle' ).html( |
2631 var $subTitle = $( '<span />' ).addClass( 'subtitle' ).html( |
2581 sprintf( |
2632 sprintf( |
2582 /* translators: %s: Search query. */ |
2633 /* translators: %s: Search query. */ |
2583 __( 'Search results for “%s”' ), |
2634 __( 'Search results for: %s' ), |
2584 _.escape( data.s ) |
2635 '<strong>' + _.escape( data.s ) + '</strong>' |
2585 ) ), |
2636 ) ), |
2586 $oldSubTitle = $( '.wrap .subtitle' ); |
2637 $oldSubTitle = $( '.wrap .subtitle' ); |
2587 |
2638 |
2588 if ( ! data.s.length ) { |
2639 if ( ! data.s.length ) { |
2589 $oldSubTitle.remove(); |
2640 $oldSubTitle.remove(); |