diff -r 34716fd837a4 -r be944660c56a wp/wp-admin/js/post.js --- a/wp/wp-admin/js/post.js Tue Dec 15 15:52:01 2020 +0100 +++ b/wp/wp-admin/js/post.js Wed Sep 21 18:19:35 2022 +0200 @@ -68,7 +68,7 @@ $('#the-comment-list').append( r.responses[0].data ); theList = theExtraList = null; - $( 'a[className*=\':\']' ).unbind(); + $( 'a[className*=\':\']' ).off(); // If the offset is over the total number of comments we cannot fetch any more, so hide the button. if ( commentsBox.st > commentsBox.total ) @@ -213,7 +213,7 @@ } wrap.show().find('.currently-editing').text( received.lock_error.text ); - wrap.find('.wp-tab-first').focus(); + wrap.find('.wp-tab-first').trigger( 'focus' ); } } else if ( received.new_lock ) { $('#active_post_lock').val( received.new_lock ); @@ -260,7 +260,9 @@ timeout = window.setTimeout( function(){ check = true; }, 300000 ); } - $(document).on( 'heartbeat-send.wp-refresh-nonces', function( e, data ) { + $( function() { + schedule(); + }).on( 'heartbeat-send.wp-refresh-nonces', function( e, data ) { var post_id, $authCheck = $('#wp-auth-check-wrap'); @@ -286,15 +288,13 @@ if ( nonces.heartbeatNonce ) window.heartbeatSettings.nonce = nonces.heartbeatNonce; } - }).ready( function() { - schedule(); }); }(jQuery)); /** * All post and postbox controls and functionality. */ -jQuery(document).ready( function($) { +jQuery( function($) { var stamp, visibility, $submitButtons, updateVisibility, updateText, $textarea = $('#content'), $document = $(document), @@ -327,14 +327,14 @@ // [Shift] + [Tab] on first tab cycles back to last tab. if ( target.hasClass('wp-tab-first') && e.shiftKey ) { - $(this).find('.wp-tab-last').focus(); + $(this).find('.wp-tab-last').trigger( 'focus' ); e.preventDefault(); // [Tab] on last tab cycles back to first tab. } else if ( target.hasClass('wp-tab-last') && ! e.shiftKey ) { - $(this).find('.wp-tab-first').focus(); + $(this).find('.wp-tab-first').trigger( 'focus' ); e.preventDefault(); } - }).filter(':visible').find('.wp-tab-first').focus(); + }).filter(':visible').find('.wp-tab-first').trigger( 'focus' ); // Set the heartbeat interval to 15 seconds if post lock dialogs are enabled. if ( wp.heartbeat && $('#post-lock-dialog').length ) { @@ -414,7 +414,7 @@ } $previewField.val('dopreview'); - $form.attr( 'target', target ).submit().attr( 'target', '' ); + $form.attr( 'target', target ).trigger( 'submit' ).attr( 'target', '' ); // Workaround for WebKit bug preventing a form submitting twice to the same action. // https://bugs.webkit.org/show_bug.cgi?id=28633 @@ -437,7 +437,7 @@ if ( editor && ! editor.isHidden() ) { editor.focus(); } else if ( $textarea.length ) { - $textarea.focus(); + $textarea.trigger( 'focus' ); } else { return; } @@ -448,7 +448,7 @@ // Auto save new posts after a title is typed. if ( $( '#auto_draft' ).val() ) { - $( '#title' ).blur( function() { + $( '#title' ).on( 'blur', function() { var cancel; if ( ! this.value || $('#edit-slug-box > *').length ) { @@ -488,12 +488,20 @@ * When the user is trying to load another page, or reloads current page * show a confirmation dialog when there are unsaved changes. */ - $(window).on( 'beforeunload.edit-post', function() { - var editor = typeof tinymce !== 'undefined' && tinymce.get('content'); + $( window ).on( 'beforeunload.edit-post', function( event ) { + var editor = window.tinymce && window.tinymce.get( 'content' ); + var changed = false; - if ( ( editor && ! editor.isHidden() && editor.isDirty() ) || - ( wp.autosave && wp.autosave.server.postChanged() ) ) { + if ( wp.autosave ) { + changed = wp.autosave.server.postChanged(); + } else if ( editor ) { + changed = ( ! editor.isHidden() && editor.isDirty() ); + } + if ( changed ) { + event.preventDefault(); + // The return string is needed for browser compat. + // See https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event. return __( 'The changes you made will be lost if you navigate away from this page.' ); } }).on( 'unload.edit-post', function( event ) { @@ -570,7 +578,7 @@ } // @todo Move to jQuery 1.3+, support for multiple hierarchical taxonomies, see wp-lists.js. - $('a', '#' + taxonomy + '-tabs').click( function( e ) { + $('a', '#' + taxonomy + '-tabs').on( 'click', function( e ) { e.preventDefault(); var t = $(this).attr('href'); $(this).parent().addClass('tabs').siblings('li').removeClass('tabs'); @@ -584,7 +592,7 @@ }); if ( getUserSetting( settingName ) ) - $('a[href="#' + taxonomy + '-pop"]', '#' + taxonomy + '-tabs').click(); + $('a[href="#' + taxonomy + '-pop"]', '#' + taxonomy + '-tabs').trigger( 'click' ); // Add category button controls. $('#new' + taxonomy).one( 'focus', function() { @@ -592,16 +600,16 @@ }); // On [Enter] submit the taxonomy. - $('#new' + taxonomy).keypress( function(event){ + $('#new' + taxonomy).on( 'keypress', function(event){ if( 13 === event.keyCode ) { event.preventDefault(); - $('#' + taxonomy + '-add-submit').click(); + $('#' + taxonomy + '-add-submit').trigger( 'click' ); } }); // After submitting a new taxonomy, re-focus the input field. - $('#' + taxonomy + '-add-submit').click( function() { - $('#new' + taxonomy).focus(); + $('#' + taxonomy + '-add-submit').on( 'click', function() { + $('#new' + taxonomy).trigger( 'focus' ); }); /** @@ -650,11 +658,11 @@ }); // Add new taxonomy button toggles input form visibility. - $('#' + taxonomy + '-add-toggle').click( function( e ) { + $('#' + taxonomy + '-add-toggle').on( 'click', function( e ) { e.preventDefault(); $('#' + taxonomy + '-adder').toggleClass( 'wp-hidden-children' ); - $('a[href="#' + taxonomy + '-all"]', '#' + taxonomy + '-tabs').click(); - $('#new'+taxonomy).focus(); + $('a[href="#' + taxonomy + '-all"]', '#' + taxonomy + '-tabs').trigger( 'click' ); + $('#new'+taxonomy).trigger( 'focus' ); }); // Sync checked items between "All {taxonomy}" and "Most used" lists. @@ -826,35 +834,35 @@ }; // Show the visibility options and hide the toggle button when opened. - $( '#visibility .edit-visibility').click( function( e ) { + $( '#visibility .edit-visibility').on( 'click', function( e ) { e.preventDefault(); if ( $postVisibilitySelect.is(':hidden') ) { updateVisibility(); $postVisibilitySelect.slideDown( 'fast', function() { - $postVisibilitySelect.find( 'input[type="radio"]' ).first().focus(); + $postVisibilitySelect.find( 'input[type="radio"]' ).first().trigger( 'focus' ); } ); $(this).hide(); } }); // Cancel visibility selection area and hide it from view. - $postVisibilitySelect.find('.cancel-post-visibility').click( function( event ) { + $postVisibilitySelect.find('.cancel-post-visibility').on( 'click', function( event ) { $postVisibilitySelect.slideUp('fast'); $('#visibility-radio-' + $('#hidden-post-visibility').val()).prop('checked', true); $('#post_password').val($('#hidden-post-password').val()); $('#sticky').prop('checked', $('#hidden-post-sticky').prop('checked')); $('#post-visibility-display').html(visibility); - $('#visibility .edit-visibility').show().focus(); + $('#visibility .edit-visibility').show().trigger( 'focus' ); updateText(); event.preventDefault(); }); // Set the selected visibility as current. - $postVisibilitySelect.find('.save-post-visibility').click( function( event ) { // Crazyhorse - multiple OK cancels. + $postVisibilitySelect.find('.save-post-visibility').on( 'click', function( event ) { // Crazyhorse - multiple OK cancels. var visibilityLabel = '', selectedVisibility = $postVisibilitySelect.find('input:radio:checked').val(); $postVisibilitySelect.slideUp('fast'); - $('#visibility .edit-visibility').show().focus(); + $('#visibility .edit-visibility').show().trigger( 'focus' ); updateText(); if ( 'public' !== selectedVisibility ) { @@ -878,15 +886,15 @@ }); // When the selection changes, update labels. - $postVisibilitySelect.find('input:radio').change( function() { + $postVisibilitySelect.find('input:radio').on( 'change', function() { updateVisibility(); }); // Edit publish time click. - $timestampdiv.siblings('a.edit-timestamp').click( function( event ) { + $timestampdiv.siblings('a.edit-timestamp').on( 'click', function( event ) { if ( $timestampdiv.is( ':hidden' ) ) { $timestampdiv.slideDown( 'fast', function() { - $( 'input, select', $timestampdiv.find( '.timestamp-wrap' ) ).first().focus(); + $( 'input, select', $timestampdiv.find( '.timestamp-wrap' ) ).first().trigger( 'focus' ); } ); $(this).hide(); } @@ -894,8 +902,8 @@ }); // Cancel editing the publish time and hide the settings. - $timestampdiv.find('.cancel-timestamp').click( function( event ) { - $timestampdiv.slideUp('fast').siblings('a.edit-timestamp').show().focus(); + $timestampdiv.find('.cancel-timestamp').on( 'click', function( event ) { + $timestampdiv.slideUp('fast').siblings('a.edit-timestamp').show().trigger( 'focus' ); $('#mm').val($('#hidden_mm').val()); $('#jj').val($('#hidden_jj').val()); $('#aa').val($('#hidden_aa').val()); @@ -906,10 +914,10 @@ }); // Save the changed timestamp. - $timestampdiv.find('.save-timestamp').click( function( event ) { // Crazyhorse - multiple OK cancels. + $timestampdiv.find('.save-timestamp').on( 'click', function( event ) { // Crazyhorse - multiple OK cancels. if ( updateText() ) { $timestampdiv.slideUp('fast'); - $timestampdiv.siblings('a.edit-timestamp').show().focus(); + $timestampdiv.siblings('a.edit-timestamp').show().trigger( 'focus' ); } event.preventDefault(); }); @@ -929,10 +937,10 @@ }); // Post Status edit click. - $postStatusSelect.siblings('a.edit-post-status').click( function( event ) { + $postStatusSelect.siblings('a.edit-post-status').on( 'click', function( event ) { if ( $postStatusSelect.is( ':hidden' ) ) { $postStatusSelect.slideDown( 'fast', function() { - $postStatusSelect.find('select').focus(); + $postStatusSelect.find('select').trigger( 'focus' ); } ); $(this).hide(); } @@ -940,15 +948,15 @@ }); // Save the Post Status changes and hide the options. - $postStatusSelect.find('.save-post-status').click( function( event ) { - $postStatusSelect.slideUp( 'fast' ).siblings( 'a.edit-post-status' ).show().focus(); + $postStatusSelect.find('.save-post-status').on( 'click', function( event ) { + $postStatusSelect.slideUp( 'fast' ).siblings( 'a.edit-post-status' ).show().trigger( 'focus' ); updateText(); event.preventDefault(); }); // Cancel Post Status editing and hide the options. - $postStatusSelect.find('.cancel-post-status').click( function( event ) { - $postStatusSelect.slideUp( 'fast' ).siblings( 'a.edit-post-status' ).show().focus(); + $postStatusSelect.find('.cancel-post-status').on( 'click', function( event ) { + $postStatusSelect.slideUp( 'fast' ).siblings( 'a.edit-post-status' ).show().trigger( 'focus' ); $('#post_status').val( $('#hidden_post_status').val() ); updateText(); event.preventDefault(); @@ -989,11 +997,11 @@ buttons.html( ' ' ); // Save permalink changes. - buttons.children( '.save' ).click( function() { + buttons.children( '.save' ).on( 'click', function() { var new_slug = $el.children( 'input' ).val(); if ( new_slug == $('#editable-post-name-full').text() ) { - buttons.children('.cancel').click(); + buttons.children('.cancel').trigger( 'click' ); return; } @@ -1018,20 +1026,20 @@ buttons.html(buttonsOrig); permalink.html(permalinkOrig); real_slug.val(new_slug); - $( '.edit-slug' ).focus(); + $( '.edit-slug' ).trigger( 'focus' ); wp.a11y.speak( __( 'Permalink saved' ) ); } ); }); // Cancel editing of permalink. - buttons.children( '.cancel' ).click( function() { + buttons.children( '.cancel' ).on( 'click', function() { $('#view-post-btn').show(); $el.html(revert_e); buttons.html(buttonsOrig); permalink.html(permalinkOrig); real_slug.val(revert_slug); - $( '.edit-slug' ).focus(); + $( '.edit-slug' ).trigger( 'focus' ); }); // If more than 1/4th of 'full' is '%', make it empty. @@ -1041,20 +1049,20 @@ } slug_value = ( c > full.length / 4 ) ? '' : full; - $el.html( '' ).children( 'input' ).keydown( function( e ) { + $el.html( '' ).children( 'input' ).on( 'keydown', function( e ) { var key = e.which; // On [Enter], just save the new slug, don't save the post. if ( 13 === key ) { e.preventDefault(); - buttons.children( '.save' ).click(); + buttons.children( '.save' ).trigger( 'click' ); } // On [Esc] cancel the editing. if ( 27 === key ) { - buttons.children( '.cancel' ).click(); + buttons.children( '.cancel' ).trigger( 'click' ); } - } ).keyup( function() { + } ).on( 'keyup', function() { real_slug.val( this.value ); - }).focus(); + }).trigger( 'focus' ); } $( '#titlediv' ).on( 'click', '.edit-slug', function() { @@ -1146,7 +1154,7 @@ height = parseInt( $('#content_ifr').css('height'), 10 ) + toolbarHeight - 28; } else { - $textarea.focus(); + $textarea.trigger( 'focus' ); height = parseInt( $textarea.css('height'), 10 ); } @@ -1169,7 +1177,7 @@ } else { mce = false; offset = $textarea.height() - event.pageY; - $textarea.blur(); + $textarea.trigger( 'blur' ); } $document.on( 'mousemove.wp-editor-resize', dragging ) @@ -1253,7 +1261,7 @@ // 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(); + triggerElement.trigger( 'focus' ); // Show success visual feedback. clearTimeout( copyAttachmentURLSuccessTimeout );