--- a/wp/wp-admin/js/theme-plugin-editor.js Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-admin/js/theme-plugin-editor.js Tue Dec 15 13:49:49 2020 +0100
@@ -10,17 +10,10 @@
wp.themePluginEditor = (function( $ ) {
'use strict';
- var component, TreeLinks;
+ var component, TreeLinks,
+ __ = wp.i18n.__, _n = wp.i18n._n, sprintf = wp.i18n.sprintf;
component = {
- l10n: {
- lintError: {
- singular: '',
- plural: ''
- },
- saveAlert: '',
- saveError: ''
- },
codeEditor: {},
instance: null,
noticeElements: {},
@@ -34,9 +27,9 @@
* @since 4.9.0
*
* @param {jQuery} form - Form element.
- * @param {object} settings - Settings.
- * @param {object|boolean} settings.codeEditor - Code editor settings (or `false` if syntax highlighting is disabled).
- * @returns {void}
+ * @param {Object} settings - Settings.
+ * @param {Object|boolean} settings.codeEditor - Code editor settings (or `false` if syntax highlighting is disabled).
+ * @return {void}
*/
component.init = function init( form, settings ) {
@@ -75,7 +68,7 @@
$( window ).on( 'beforeunload', function() {
if ( component.dirty ) {
- return component.l10n.saveAlert;
+ return __( 'The changes you made will be lost if you navigate away from this page.' );
}
return undefined;
} );
@@ -94,7 +87,7 @@
* Set up and display the warning modal.
*
* @since 4.9.0
- * @returns {void}
+ * @return {void}
*/
component.showWarning = function() {
// Get the text within the modal.
@@ -124,8 +117,8 @@
* Constrain tabbing within the warning modal.
*
* @since 4.9.0
- * @param {object} event jQuery event object.
- * @returns {void}
+ * @param {Object} event jQuery event object.
+ * @return {void}
*/
component.constrainTabbing = function( event ) {
var firstTabbable, lastTabbable;
@@ -150,7 +143,7 @@
* Dismiss the warning modal.
*
* @since 4.9.0
- * @returns {void}
+ * @return {void}
*/
component.dismissWarning = function() {
@@ -168,7 +161,7 @@
* Callback for when a change happens.
*
* @since 4.9.0
- * @returns {void}
+ * @return {void}
*/
component.onChange = function() {
component.dirty = true;
@@ -180,7 +173,7 @@
*
* @since 4.9.0
* @param {jQuery.Event} event - Event.
- * @returns {void}
+ * @return {void}
*/
component.submit = function( event ) {
var data = {}, request;
@@ -233,7 +226,7 @@
var notice = $.extend(
{
code: 'save_error',
- message: component.l10n.saveError
+ message: __( 'Something went wrong. Your change may not have been saved. Please try again. There is also a chance that you may need to manually fix and upload the file over FTP.' )
},
response,
{
@@ -261,13 +254,13 @@
*
* @since 4.9.0
*
- * @param {object} notice - Notice.
+ * @param {Object} notice - Notice.
* @param {string} notice.code - Code.
* @param {string} notice.type - Type.
* @param {string} notice.message - Message.
* @param {boolean} [notice.dismissible=false] - Dismissible.
* @param {Function} [notice.onDismiss] - Callback for when a user dismisses the notice.
- * @returns {jQuery} Notice element.
+ * @return {jQuery} Notice element.
*/
component.addNotice = function( notice ) {
var noticeElement;
@@ -303,7 +296,7 @@
* @since 4.9.0
*
* @param {string} code - Notice code.
- * @returns {boolean} Whether a notice was removed.
+ * @return {boolean} Whether a notice was removed.
*/
component.removeNotice = function( code ) {
if ( component.noticeElements[ code ] ) {
@@ -320,7 +313,7 @@
* Initialize code editor.
*
* @since 4.9.0
- * @returns {void}
+ * @return {void}
*/
component.initCodeEditor = function initCodeEditor() {
var codeEditorSettings, editor;
@@ -332,7 +325,7 @@
*
* @since 4.9.0
*
- * @returns {void}
+ * @return {void}
*/
codeEditorSettings.onTabPrevious = function() {
$( '#templateside' ).find( ':tabbable' ).last().focus();
@@ -343,7 +336,7 @@
*
* @since 4.9.0
*
- * @returns {void}
+ * @return {void}
*/
codeEditorSettings.onTabNext = function() {
$( '#template' ).find( ':tabbable:not(.CodeMirror-code)' ).first().focus();
@@ -355,7 +348,7 @@
* @since 4.9.0
*
* @param {Array} errors - List of linting errors.
- * @returns {void}
+ * @return {void}
*/
codeEditorSettings.onChangeLintingErrors = function( errors ) {
component.lintErrors = errors;
@@ -372,23 +365,26 @@
* @since 4.9.0
*
* @param {Array} errorAnnotations - Error annotations.
- * @returns {void}
+ * @return {void}
*/
codeEditorSettings.onUpdateErrorNotice = function onUpdateErrorNotice( errorAnnotations ) {
- var message, noticeElement;
+ var noticeElement;
component.submitButton.toggleClass( 'disabled', errorAnnotations.length > 0 );
if ( 0 !== errorAnnotations.length ) {
- if ( 1 === errorAnnotations.length ) {
- message = component.l10n.lintError.singular.replace( '%d', '1' );
- } else {
- message = component.l10n.lintError.plural.replace( '%d', String( errorAnnotations.length ) );
- }
noticeElement = component.addNotice({
code: 'lint_errors',
type: 'error',
- message: message,
+ message: sprintf(
+ /* translators: %s: Error count. */
+ _n(
+ 'There is %s error which must be fixed before you can update this file.',
+ 'There are %s errors which must be fixed before you can update this file.',
+ errorAnnotations.length
+ ),
+ String( errorAnnotations.length )
+ ),
dismissible: false
});
noticeElement.find( 'input[type=checkbox]' ).on( 'click', function() {
@@ -424,7 +420,7 @@
* Initialization of the file browser's folder states.
*
* @since 4.9.0
- * @returns {void}
+ * @return {void}
*/
component.initFileBrowser = function initFileBrowser() {
@@ -491,7 +487,7 @@
var TreeitemLink = function (node, treeObj, group) {
- // Check whether node is a DOM element
+ // Check whether node is a DOM element.
if (typeof node !== 'object') {
return;
}
@@ -696,7 +692,7 @@
TreeitemLink.prototype.handleClick = function (event) {
- // only process click events that directly happened on this treeitem
+ // Only process click events that directly happened on this treeitem.
if (event.target !== this.domNode && event.target !== this.domNode.firstElementChild) {
return;
}
@@ -773,7 +769,7 @@
*/
var TreeLinks = function (node) {
- // Check whether node is a DOM element
+ // Check whether node is a DOM element.
if (typeof node !== 'object') {
return;
}
@@ -812,7 +808,7 @@
}
}
- // initialize pop up menus
+ // Initialize pop up menus.
if (!this.domNode.getAttribute('role')) {
this.domNode.setAttribute('role', 'tree');
}
@@ -964,16 +960,16 @@
var start, index;
_char = _char.toLowerCase();
- // Get start index for search based on position of currentItem
+ // Get start index for search based on position of currentItem.
start = this.treeitems.indexOf(currentItem) + 1;
if (start === this.treeitems.length) {
start = 0;
}
- // Check remaining slots in the menu
+ // Check remaining slots in the menu.
index = this.getIndexFirstChars(start, _char);
- // If not found in remaining slots, check from beginning
+ // If not found in remaining slots, check from beginning.
if (index === -1) {
index = this.getIndexFirstChars(0, _char);
}
@@ -1004,3 +1000,27 @@
return component;
})( jQuery );
+
+/**
+ * Removed in 5.5.0, needed for back-compatibility.
+ *
+ * @since 4.9.0
+ * @deprecated 5.5.0
+ *
+ * @type {object}
+ */
+wp.themePluginEditor.l10n = wp.themePluginEditor.l10n || {
+ saveAlert: '',
+ saveError: '',
+ lintError: {
+ alternative: 'wp.i18n',
+ func: function() {
+ return {
+ singular: '',
+ plural: ''
+ };
+ }
+ }
+};
+
+wp.themePluginEditor.l10n = window.wp.deprecateL10nObject( 'wp.themePluginEditor.l10n', wp.themePluginEditor.l10n );