Make WordPress Core

Changeset 32098


Ignore:
Timestamp:
04/09/2015 07:06:41 PM (11 years ago)
Author:
azaozz
Message:

Press This:

  • Fix focusing the Standard Editor link after saving draft, if the user has not focused another element.
  • Reset the Save Draft button on node change in the editor.

See #31923.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/press-this.js

    r32092 r32098  
    77                var editor, $mediaList, $mediaThumbWrap,
    88                        saveAlert             = false,
     9                        editLinkVisible       = false,
    910                        textarea              = document.createElement( 'textarea' ),
    1011                        sidebarIsOpen         = false,
     
    103104                function showSpinner() {
    104105                        $( '.spinner' ).addClass( 'is-active' );
    105                         $( '.post-actions button' ).each( function() {
    106                                 $( this ).attr( 'disabled', 'disabled' );
    107                         } );
     106                        $( '.post-actions button' ).attr( 'disabled', 'disabled' );
    108107                }
    109108
     
    113112                function hideSpinner() {
    114113                        $( '.spinner' ).removeClass( 'is-active' );
    115                         $( '.post-actions button' ).each( function() {
    116                                 $( this ).removeAttr( 'disabled' );
    117                         } );
     114                        $( '.post-actions button' ).removeAttr( 'disabled' );
    118115                }
    119116
     
    167164                 */
    168165                function submitPost( action ) {
    169                         var data;
     166                        var data,
     167                                keepFocus = $( document.activeElement ).hasClass( 'draft-button' );
    170168
    171169                        saveAlert = false;
     
    187185                                clearNotices();
    188186                        }).done( function( response ) {
    189                                 var $link, $button, keepFocus;
     187                                var $link, $button;
    190188
    191189                                if ( ! response.success ) {
     
    204202                                        $link = $( '.edit-post-link' );
    205203                                        $button = $( '.draft-button' );
    206 
    207                                         if ( document.activeElement && document.activeElement.className.indexOf( 'draft-button' ) > -1 ) {
    208                                                 keepFocus = true;
    209                                         }
     204                                        editLinkVisible = true;
    210205
    211206                                        $button.fadeOut( 200, function() {
    212207                                                $button.removeClass( 'is-saving' );
    213                                                 $link.fadeIn( 200 );
    214 
    215                                                 if ( keepFocus ) {
    216                                                         $link.focus();
    217                                                 }
     208                                                $link.fadeIn( 200, function() {
     209                                                        var active = document.activeElement;
     210                                                        // Different browsers move the focus to different places when the button is disabled.
     211                                                        if ( keepFocus && ( active === $button[0] || $( active ).hasClass( 'post-actions' ) || active.nodeName === 'BODY' ) ) {
     212                                                                $link.focus();
     213                                                        }
     214                                                });
    218215                                        });
    219216                                }
     
    224221
    225222                function resetDraftButton() {
    226                         $( '.edit-post-link' ).fadeOut( 200, function() {
    227                                 $( '.draft-button' ).removeClass( 'is-saving' ).fadeIn( 200 );
    228                         });
     223                        if ( editLinkVisible ) {
     224                                editLinkVisible = false;
     225
     226                                $( '.edit-post-link' ).fadeOut( 200, function() {
     227                                        $( '.draft-button' ).removeClass( 'is-saving' ).fadeIn( 200 );
     228                                });
     229                        }
    229230                }
    230231
     
    656657                                editor = ed;
    657658
    658                                 function focus() {
     659                                editor.on( 'nodechange', function() {
    659660                                        hasSetFocus = true;
    660661                                        resetDraftButton();
    661                                 }
    662 
    663                                 if ( window.tinymce.Env.iOS ) {
    664                                         editor.on( 'click', focus );
    665                                 } else {
    666                                         editor.on( 'focus', focus );
    667                                 }
     662                                } );
    668663                        }).on( 'click.press-this keypress.press-this', '.suggested-media-thumbnail', function( event ) {
    669664                                if ( event.type === 'click' || event.keyCode === 13 ) {
Note: See TracChangeset for help on using the changeset viewer.