Make WordPress Core

Changeset 32092


Ignore:
Timestamp:
04/08/2015 11:13:35 PM (12 years ago)
Author:
azaozz
Message:

Press This:

  • When saving a draft change the text of the Save Draft button to Saving...
  • On success, hide the button and show Edit Post link in its place. If the user focuses the title or the editor, hide the link and show the button again.

Fixes #31923.

Location:
trunk/src/wp-admin
Files:
3 edited

Legend:

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

    r32051 r32092  
    342342.button-subtle:focus,
    343343.button-subtle:hover,
    344 .button-subtle:active {
     344.button-subtle:active,
     345.edit-post-link:focus,
     346.edit-post-link:hover,
     347.edit-post-link:active {
    345348        color: #00a0d2;
    346349}
    347350
    348351.button-subtle:focus,
    349 .button-subtle:active {
     352.button-subtle:active,
     353.edit-post-link:focus,
     354.edit-post-link:active {
    350355        outline: 0;
    351356        text-decoration: underline;
    … …  
    13741379        opacity: 0.7;
    13751380        filter: alpha(opacity=70);
    1376         line-height: 30px;
    1377         vertical-align: baseline;
     1381        line-height: 1;
     1382        vertical-align: middle;
    13781383}
    13791384
    … …  
    17351740        float: right;
    17361741        margin: 14px 30px 14px 0;
    1737         font-size: 0;
     1742        font-size: 13px;
    17381743}
    17391744
    … …  
    17421747                margin: 10px 10px 10px 0;
    17431748        }
     1749}
     1750
     1751.edit-post-link {
     1752        font-size: 13px;
     1753        display: inline-block;
     1754        text-decoration: none;
     1755        padding: 0 10px;
     1756}
     1757
     1758.draft-button.is-hidden,
     1759.draft-button .saving-draft,
     1760.draft-button.is-saving .save-draft {
     1761        display: none;
     1762}
     1763
     1764.draft-button.is-saving .saving-draft {
     1765        display: inline;
    17441766}
    17451767
  • trunk/src/wp-admin/includes/class-wp-press-this.php

    r32014 r32092  
    14311431                <div class="post-actions">
    14321432                        <span class="spinner">&nbsp;</span>
    1433                         <button type="button" class="button-subtle draft-button"><?php _e( 'Save Draft' ); ?></button>
     1433                        <button type="button" class="button-subtle draft-button" aria-live="polite">
     1434                                <span class="save-draft"><?php _e( 'Save Draft' ); ?></span>
     1435                                <span class="saving-draft"><?php _e( 'Saving...' ); ?></span>
     1436                        </button>
     1437                        <a href="<?php echo esc_url( get_edit_post_link( $post_ID ) ); ?>" class="edit-post-link" style="display: none;" target="_blank"><?php _e( 'Edit Post' ); ?></a>
    14341438                        <button type="button" class="button-subtle preview-button"><?php _e( 'Preview' ); ?></button>
    14351439                        <button type="button" class="button-primary publish-button"><?php echo ( current_user_can( 'publish_posts' ) ) ? __( 'Publish' ) : __( 'Submit for Review' ); ?></button>
  • trunk/src/wp-admin/js/press-this.js

    r31996 r32092  
    185185                        }).always( function() {
    186186                                hideSpinner();
     187                                clearNotices();
    187188                        }).done( function( response ) {
     189                                var $link, $button, keepFocus;
     190
    188191                                if ( ! response.success ) {
    189192                                        renderError( response.data.errorMessage );
    … …  
    199202                                        }
    200203                                } else if ( response.data.postSaved ) {
    201                                         // show "success" message?
     204                                        $link = $( '.edit-post-link' );
     205                                        $button = $( '.draft-button' );
     206
     207                                        if ( document.activeElement && document.activeElement.className.indexOf( 'draft-button' ) > -1 ) {
     208                                                keepFocus = true;
     209                                        }
     210
     211                                        $button.fadeOut( 200, function() {
     212                                                $button.removeClass( 'is-saving' );
     213                                                $link.fadeIn( 200 );
     214
     215                                                if ( keepFocus ) {
     216                                                        $link.focus();
     217                                                }
     218                                        });
    202219                                }
    203220                        }).fail( function() {
    204221                                renderError( __( 'serverError' ) );
     222                        });
     223                }
     224
     225                function resetDraftButton() {
     226                        $( '.edit-post-link' ).fadeOut( 200, function() {
     227                                $( '.draft-button' ).removeClass( 'is-saving' ).fadeIn( 200 );
    205228                        });
    206229                }
    … …  
    327350                function renderError( msg ) {
    328351                        renderNotice( msg, true );
     352                }
     353
     354                function clearNotices() {
     355                        $( 'div.alerts' ).empty();
    329356                }
    330357
    … …  
    528555                        $titleField.on( 'focus', function() {
    529556                                $placeholder.addClass( 'is-hidden' );
     557                                resetDraftButton();
    530558                        }).on( 'blur', function() {
    531559                                if ( ! $titleField.text() && ! $titleField.html() ) {
    … …  
    624652                 * Set app events and other state monitoring related code.
    625653                 */
    626                 function monitor(){
     654                function monitor() {
    627655                        $( document ).on( 'tinymce-editor-init', function( event, ed ) {
    628656                                editor = ed;
    629657
    630                                 ed.on( 'focus', function() {
     658                                function focus() {
    631659                                        hasSetFocus = true;
    632                                 } );
     660                                        resetDraftButton();
     661                                }
     662
     663                                if ( window.tinymce.Env.iOS ) {
     664                                        editor.on( 'click', focus );
     665                                } else {
     666                                        editor.on( 'focus', focus );
     667                                }
    633668                        }).on( 'click.press-this keypress.press-this', '.suggested-media-thumbnail', function( event ) {
    634669                                if ( event.type === 'click' || event.keyCode === 13 ) {
    … …  
    638673
    639674                        // Publish, Draft and Preview buttons
    640 
    641675                        $( '.post-actions' ).on( 'click.press-this', function( event ) {
    642                                 var $target = $( event.target );
    643 
    644                                 if ( $target.hasClass( 'draft-button' ) ) {
    645                                         submitPost( 'draft' );
    646                                 } else if ( $target.hasClass( 'publish-button' ) ) {
    647                                         submitPost( 'publish' );
    648                                 } else if ( $target.hasClass( 'preview-button' ) ) {
    649                                         prepareFormData();
    650                                         window.opener && window.opener.focus();
    651 
    652                                         $( '#wp-preview' ).val( 'dopreview' );
    653                                         $( '#pressthis-form' ).attr( 'target', '_blank' ).submit().attr( 'target', '' );
    654                                         $( '#wp-preview' ).val( '' );
     676                                var $target = $( event.target ),
     677                                        $button = $target.closest( 'button' );
     678
     679                                if ( $button.length ) {
     680                                        if ( $button.hasClass( 'draft-button' ) ) {
     681                                                $button.addClass( 'is-saving' );
     682                                                submitPost( 'draft' );
     683                                        } else if ( $button.hasClass( 'publish-button' ) ) {
     684                                                submitPost( 'publish' );
     685                                        } else if ( $button.hasClass( 'preview-button' ) ) {
     686                                                prepareFormData();
     687                                                window.opener && window.opener.focus();
     688
     689                                                $( '#wp-preview' ).val( 'dopreview' );
     690                                                $( '#pressthis-form' ).attr( 'target', '_blank' ).submit().attr( 'target', '' );
     691                                                $( '#wp-preview' ).val( '' );
     692                                        }
     693                                } else if ( $target.hasClass( 'edit-post-link' ) && window.opener ) {
     694                                        window.opener.focus();
     695                                        window.self.close();
    655696                                }
    656697                        });
Note: See TracChangeset for help on using the changeset viewer.