--- a/wp/wp-admin/js/post.js Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-admin/js/post.js Tue Dec 15 13:49:49 2020 +0100
@@ -4,18 +4,19 @@
* @output wp-admin/js/post.js
*/
- /* global postL10n, ajaxurl, wpAjax, setPostThumbnailL10n, postboxes, pagenow, tinymce, alert, deleteUserSetting */
+ /* global ajaxurl, wpAjax, postboxes, pagenow, tinymce, alert, deleteUserSetting, ClipboardJS */
/* global theList:true, theExtraList:true, getUserSetting, setUserSetting, commentReply, commentsBox */
/* global WPSetThumbnailHTML, wptitlehint */
-// Backwards compatibility: prevent fatal errors.
+// Backward compatibility: prevent fatal errors.
window.makeSlugeditClickable = window.editPermalink = function(){};
// Make sure the wp object exists.
window.wp = window.wp || {};
( function( $ ) {
- var titleHasFocus = false;
+ var titleHasFocus = false,
+ __ = wp.i18n.__;
/**
* Control loading of comments on the post and term edit pages.
@@ -29,13 +30,13 @@
st : 0,
/**
- * Fetch comments using AJAX and display them in the box.
+ * Fetch comments using Ajax and display them in the box.
*
* @memberof commentsBox
*
- * @param {int} total Total number of comments for this post.
- * @param {int} num Optional. Number of comments to fetch, defaults to 20.
- * @returns {boolean} Always returns false.
+ * @param {number} total Total number of comments for this post.
+ * @param {number} num Optional. Number of comments to fetch, defaults to 20.
+ * @return {boolean} Always returns false.
*/
get : function(total, num) {
var st = this.st, data;
@@ -73,11 +74,11 @@
if ( commentsBox.st > commentsBox.total )
$('#show-comments').hide();
else
- $('#show-comments').show().children('a').html(postL10n.showcomm);
+ $('#show-comments').show().children('a').text( __( 'Show more comments' ) );
return;
} else if ( 1 == r ) {
- $('#show-comments').html(postL10n.endcomm);
+ $('#show-comments').text( __( 'No more comments found.' ) );
return;
}
@@ -91,9 +92,9 @@
/**
* Load the next batch of comments.
*
- * @param {int} total Total number of comments to load.
+ * @memberof commentsBox
*
- * @memberof commentsBox
+ * @param {number} total Total number of comments to load.
*/
load: function(total){
this.st = jQuery('#the-comment-list tr.comment:visible').length;
@@ -115,7 +116,7 @@
/**
* Set the Image ID of the Featured Image
*
- * @param {int} id The post_id of the image to use as Featured Image.
+ * @param {number} id The post_id of the image to use as Featured Image.
*
* @global
*/
@@ -144,7 +145,7 @@
*/
function(str){
if ( str == '0' ) {
- alert( setPostThumbnailL10n.error );
+ alert( __( 'Could not set that as the thumbnail image. Try a different attachment.' ) );
} else {
WPSetThumbnailHTML(str);
}
@@ -200,7 +201,14 @@
}
if ( received.lock_error.avatar_src ) {
- avatar = $( '<img class="avatar avatar-64 photo" width="64" height="64" alt="" />' ).attr( 'src', received.lock_error.avatar_src.replace( /&/g, '&' ) );
+ avatar = $( '<img />', {
+ 'class': 'avatar avatar-64 photo',
+ width: 64,
+ height: 64,
+ alt: '',
+ src: received.lock_error.avatar_src,
+ srcset: received.lock_error.avatar_src_2x ? received.lock_error.avatar_src_2x + ' 2x' : undefined
+ } );
wrap.find('div.post-locked-avatar').empty().append( avatar );
}
@@ -288,7 +296,6 @@
*/
jQuery(document).ready( function($) {
var stamp, visibility, $submitButtons, updateVisibility, updateText,
- sticky = '',
$textarea = $('#content'),
$document = $(document),
postId = $('#post_ID').val() || 0,
@@ -297,7 +304,10 @@
$postVisibilitySelect = $('#post-visibility-select'),
$timestampdiv = $('#timestampdiv'),
$postStatusSelect = $('#post-status-select'),
- isMac = window.navigator.platform ? window.navigator.platform.indexOf( 'Mac' ) !== -1 : false;
+ isMac = window.navigator.platform ? window.navigator.platform.indexOf( 'Mac' ) !== -1 : false,
+ copyAttachmentURLClipboard = new ClipboardJS( '.copy-attachment-url.edit-media' ),
+ copyAttachmentURLSuccessTimeout,
+ __ = wp.i18n.__, _x = wp.i18n._x;
postboxes.add_postbox_toggles(pagenow);
@@ -309,24 +319,24 @@
// Post locks: contain focus inside the dialog. If the dialog is shown, focus the first item.
$('#post-lock-dialog .notification-dialog').on( 'keydown', function(e) {
- // Don't do anything when [tab] is pressed.
+ // Don't do anything when [Tab] is pressed.
if ( e.which != 9 )
return;
var target = $(e.target);
- // [shift] + [tab] on first tab cycles back to last tab.
+ // [Shift] + [Tab] on first tab cycles back to last tab.
if ( target.hasClass('wp-tab-first') && e.shiftKey ) {
$(this).find('.wp-tab-last').focus();
e.preventDefault();
- // [tab] on last tab cycles back to first tab.
+ // [Tab] on last tab cycles back to first tab.
} else if ( target.hasClass('wp-tab-last') && ! e.shiftKey ) {
$(this).find('.wp-tab-first').focus();
e.preventDefault();
}
}).filter(':visible').find('.wp-tab-first').focus();
- // Set the heartbeat interval to 15 sec. if post lock dialogs are enabled.
+ // Set the heartbeat interval to 15 seconds if post lock dialogs are enabled.
if ( wp.heartbeat && $('#post-lock-dialog').length ) {
wp.heartbeat.interval( 15 );
}
@@ -385,7 +395,7 @@
});
});
- // Submit the form saving a draft or an autosave, and show a preview in a new tab
+ // Submit the form saving a draft or an autosave, and show a preview in a new tab.
$('#post-preview').on( 'click.post-preview', function( event ) {
var $this = $(this),
$form = $('form#post'),
@@ -465,7 +475,7 @@
$submitButtons.removeClass( 'disabled' );
}
}).on( 'before-autosave.edit-post', function() {
- $( '.autosave-message' ).text( postL10n.savingText );
+ $( '.autosave-message' ).text( __( 'Saving Draft…' ) );
}).on( 'after-autosave.edit-post', function( event, data ) {
$( '.autosave-message' ).text( data.message );
@@ -484,7 +494,7 @@
if ( ( editor && ! editor.isHidden() && editor.isDirty() ) ||
( wp.autosave && wp.autosave.server.postChanged() ) ) {
- return postL10n.saveAlert;
+ return __( 'The changes you made will be lost if you navigate away from this page.' );
}
}).on( 'unload.edit-post', function( event ) {
if ( ! releaseLock ) {
@@ -534,7 +544,7 @@
});
});
- // Multiple Taxonomies.
+ // Multiple taxonomies.
if ( $('#tagsdiv-post_tag').length ) {
window.tagBox && window.tagBox.init();
} else {
@@ -559,7 +569,7 @@
settingName = 'cats';
}
- // TODO: move to jQuery 1.3+, support for multiple hierarchical taxonomies, see wp-lists.js
+ // @todo Move to jQuery 1.3+, support for multiple hierarchical taxonomies, see wp-lists.js.
$('a', '#' + taxonomy + '-tabs').click( function( e ) {
e.preventDefault();
var t = $(this).attr('href');
@@ -581,7 +591,7 @@
$( this ).val( '' ).removeClass( 'form-input-tip' );
});
- // On [enter] submit the taxonomy.
+ // On [Enter] submit the taxonomy.
$('#new' + taxonomy).keypress( function(event){
if( 13 === event.keyCode ) {
event.preventDefault();
@@ -599,7 +609,7 @@
*
* @param {Object} s Taxonomy object which will be added.
*
- * @returns {Object}
+ * @return {Object}
*/
catAddBefore = function( s ) {
if ( !$('#new'+taxonomy).val() ) {
@@ -620,7 +630,7 @@
* @param {Object} r Response.
* @param {Object} s Taxonomy data.
*
- * @returns void
+ * @return {void}
*/
catAddAfter = function( r, s ) {
var sup, drop = $('#new'+taxonomy+'_parent');
@@ -654,7 +664,7 @@
$('#in-' + taxonomy + '-' + id + ', #in-popular-' + taxonomy + '-' + id).prop( 'checked', c );
});
- }); // end cats
+ }); // End cats.
// Custom Fields postbox.
if ( $('#postcustom').length ) {
@@ -666,7 +676,7 @@
*
* @param {Object} s Request object.
*
- * @returns {Object} Data modified with post_ID attached.
+ * @return {Object} Data modified with post_ID attached.
*/
addBefore: function( s ) {
s.data += '&post_id=' + $('#post_ID').val();
@@ -695,7 +705,7 @@
*
* @ignore
*
- * @returns void
+ * @return {void}
*/
updateVisibility = function() {
// Show sticky for public posts.
@@ -719,7 +729,7 @@
*
* @ignore
*
- * @returns {boolean} False when an invalid timestamp has been selected, otherwise True.
+ * @return {boolean} False when an invalid timestamp has been selected, otherwise True.
*/
updateText = function() {
@@ -744,14 +754,14 @@
// Determine what the publish should be depending on the date and post status.
if ( attemptedDate > currentDate && $('#original_post_status').val() != 'future' ) {
- publishOn = postL10n.publishOnFuture;
- $('#publish').val( postL10n.schedule );
+ publishOn = __( 'Schedule for:' );
+ $('#publish').val( _x( 'Schedule', 'post action/button label' ) );
} else if ( attemptedDate <= currentDate && $('#original_post_status').val() != 'publish' ) {
- publishOn = postL10n.publishOn;
- $('#publish').val( postL10n.publish );
+ publishOn = __( 'Publish on:' );
+ $('#publish').val( __( 'Publish' ) );
} else {
- publishOn = postL10n.publishOnPast;
- $('#publish').val( postL10n.update );
+ publishOn = __( 'Published on:' );
+ $('#publish').val( __( 'Update' ) );
}
// If the date is the same, set it to trigger update events.
@@ -761,7 +771,8 @@
} else {
$('#timestamp').html(
'\n' + publishOn + ' <b>' +
- postL10n.dateFormat
+ // translators: 1: Month, 2: Day, 3: Year, 4: Hour, 5: Minute.
+ __( '%1$s %2$s, %3$s at %4$s:%5$s' )
.replace( '%1$s', $( 'option[value="' + mm + '"]', '#mm' ).attr( 'data-text' ) )
.replace( '%2$s', parseInt( jj, 10 ) )
.replace( '%3$s', aa )
@@ -773,11 +784,11 @@
// Add "privately published" to post status when applies.
if ( $postVisibilitySelect.find('input:radio:checked').val() == 'private' ) {
- $('#publish').val( postL10n.update );
+ $('#publish').val( __( 'Update' ) );
if ( 0 === optPublish.length ) {
- postStatus.append('<option value="publish">' + postL10n.privatelyPublished + '</option>');
+ postStatus.append('<option value="publish">' + __( 'Privately Published' ) + '</option>');
} else {
- optPublish.html( postL10n.privatelyPublished );
+ optPublish.html( __( 'Privately Published' ) );
}
$('option[value="publish"]', postStatus).prop('selected', true);
$('#misc-publishing-actions .edit-post-status').hide();
@@ -788,7 +799,7 @@
postStatus.val($('#hidden_post_status').val());
}
} else {
- optPublish.html( postL10n.published );
+ optPublish.html( __( 'Published' ) );
}
if ( postStatus.is(':hidden') )
$('#misc-publishing-actions .edit-post-status').show();
@@ -796,7 +807,8 @@
// Update "Status:" to currently selected status.
$('#post-status-display').text(
- wp.sanitize.stripTagsAndEncodeText( $('option:selected', postStatus).text() ) // Remove any potential tags from post status text.
+ // Remove any potential tags from post status text.
+ wp.sanitize.stripTagsAndEncodeText( $('option:selected', postStatus).text() )
);
// Show or hide the "Save Draft" button.
@@ -805,9 +817,9 @@
} else {
$('#save-post').show();
if ( $('option:selected', postStatus).val() == 'pending' ) {
- $('#save-post').show().val( postL10n.savePending );
+ $('#save-post').show().val( __( 'Save as Pending' ) );
} else {
- $('#save-post').show().val( postL10n.saveDraft );
+ $('#save-post').show().val( __( 'Save Draft' ) );
}
}
return true;
@@ -838,22 +850,30 @@
});
// Set the selected visibility as current.
- $postVisibilitySelect.find('.save-post-visibility').click( function( event ) { // crazyhorse - multiple ok cancels
+ $postVisibilitySelect.find('.save-post-visibility').click( function( event ) { // Crazyhorse - multiple OK cancels.
+ var visibilityLabel = '', selectedVisibility = $postVisibilitySelect.find('input:radio:checked').val();
+
$postVisibilitySelect.slideUp('fast');
$('#visibility .edit-visibility').show().focus();
updateText();
- if ( $postVisibilitySelect.find('input:radio:checked').val() != 'public' ) {
+ if ( 'public' !== selectedVisibility ) {
$('#sticky').prop('checked', false);
}
- if ( $('#sticky').prop('checked') ) {
- sticky = 'Sticky';
- } else {
- sticky = '';
+ switch ( selectedVisibility ) {
+ case 'public':
+ visibilityLabel = $( '#sticky' ).prop( 'checked' ) ? __( 'Public, Sticky' ) : __( 'Public' );
+ break;
+ case 'private':
+ visibilityLabel = __( 'Private' );
+ break;
+ case 'password':
+ visibilityLabel = __( 'Password Protected' );
+ break;
}
- $('#post-visibility-display').html( postL10n[ $postVisibilitySelect.find('input:radio:checked').val() + sticky ] );
+ $('#post-visibility-display').text( visibilityLabel );
event.preventDefault();
});
@@ -886,7 +906,7 @@
});
// Save the changed timestamp.
- $timestampdiv.find('.save-timestamp').click( function( event ) { // crazyhorse - multiple ok cancels
+ $timestampdiv.find('.save-timestamp').click( function( event ) { // Crazyhorse - multiple OK cancels.
if ( updateText() ) {
$timestampdiv.slideUp('fast');
$timestampdiv.siblings('a.edit-timestamp').show().focus();
@@ -937,11 +957,11 @@
/**
* Handle the editing of the post_name. Create the required HTML elements and
- * update the changes via AJAX.
+ * update the changes via Ajax.
*
* @global
*
- * @returns void
+ * @return {void}
*/
function editPermalink() {
var i, slug_value,
@@ -966,7 +986,7 @@
$el = $( '#editable-post-name' );
revert_e = $el.html();
- buttons.html( '<button type="button" class="save button button-small">' + postL10n.ok + '</button> <button type="button" class="cancel button-link">' + postL10n.cancel + '</button>' );
+ buttons.html( '<button type="button" class="save button button-small">' + __( 'OK' ) + '</button> <button type="button" class="cancel button-link">' + __( 'Cancel' ) + '</button>' );
// Save permalink changes.
buttons.children( '.save' ).click( function() {
@@ -999,7 +1019,7 @@
permalink.html(permalinkOrig);
real_slug.val(new_slug);
$( '.edit-slug' ).focus();
- wp.a11y.speak( postL10n.permalinkSaved );
+ wp.a11y.speak( __( 'Permalink saved' ) );
}
);
});
@@ -1023,12 +1043,12 @@
$el.html( '<input type="text" id="new-post-slug" value="' + slug_value + '" autocomplete="off" />' ).children( 'input' ).keydown( function( e ) {
var key = e.which;
- // On [enter], just save the new slug, don't save the post.
+ // On [Enter], just save the new slug, don't save the post.
if ( 13 === key ) {
e.preventDefault();
buttons.children( '.save' ).click();
}
- // On [esc] cancel the editing.
+ // On [Esc] cancel the editing.
if ( 27 === key ) {
buttons.children( '.cancel' ).click();
}
@@ -1051,7 +1071,7 @@
*
* @global
*
- * @returns void
+ * @return {void}
*/
window.wptitlehint = function( id ) {
id = id || 'title';
@@ -1173,7 +1193,7 @@
}
});
- // When changing page template, change the editor body class
+ // When changing page template, change the editor body class.
$( '#page_template' ).on( 'change.set-editor-class', function() {
var editor, body, pageTemplate = $( this ).val() || '';
@@ -1191,9 +1211,9 @@
}
- // Save on pressing [ctrl]/[command] + [s] in the Text editor.
+ // Save on pressing [Ctrl]/[Command] + [S] in the Text editor.
$textarea.on( 'keydown.wp-autosave', function( event ) {
- // Key [s] has code 83.
+ // Key [S] has code 83.
if ( event.which === 83 ) {
if ( event.shiftKey || event.altKey || ( isMac && ( ! event.metaKey || event.ctrlKey ) ) || ( ! isMac && ! event.ctrlKey ) ) {
return;
@@ -1216,7 +1236,38 @@
window.history.replaceState( null, null, location );
});
}
-});
+
+ /**
+ * Copies the attachment URL in the Edit Media page to the clipboard.
+ *
+ * @since 5.5.0
+ *
+ * @param {MouseEvent} event A click event.
+ *
+ * @return {void}
+ */
+ copyAttachmentURLClipboard.on( 'success', function( event ) {
+ var triggerElement = $( event.trigger ),
+ successElement = $( '.success', triggerElement.closest( '.copy-to-clipboard-container' ) );
+
+ // Clear the selection and move focus back to the trigger.
+ event.clearSelection();
+ // Handle ClipboardJS focus bug, see https://github.com/zenorocha/clipboard.js/issues/680
+ triggerElement.focus();
+
+ // Show success visual feedback.
+ clearTimeout( copyAttachmentURLSuccessTimeout );
+ successElement.removeClass( 'hidden' );
+
+ // Hide success visual feedback after 3 seconds since last success.
+ copyAttachmentURLSuccessTimeout = setTimeout( function() {
+ successElement.addClass( 'hidden' );
+ }, 3000 );
+
+ // Handle success audible feedback.
+ wp.a11y.speak( __( 'The file URL has been copied to your clipboard' ) );
+ } );
+} );
/**
* TinyMCE word count display