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.
Built from https://develop.svn.wordpress.org/trunk@32098


git-svn-id: http://core.svn.wordpress.org/trunk@32077 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2015-04-09 19:07:28 +00:00
parent 5a547231b7
commit 923ca312e4
3 changed files with 25 additions and 30 deletions

View File

@ -6,6 +6,7 @@
var PressThis = function() {
var editor, $mediaList, $mediaThumbWrap,
saveAlert = false,
editLinkVisible = false,
textarea = document.createElement( 'textarea' ),
sidebarIsOpen = false,
settings = window.wpPressThisConfig || {},
@ -102,9 +103,7 @@
*/
function showSpinner() {
$( '.spinner' ).addClass( 'is-active' );
$( '.post-actions button' ).each( function() {
$( this ).attr( 'disabled', 'disabled' );
} );
$( '.post-actions button' ).attr( 'disabled', 'disabled' );
}
/**
@ -112,9 +111,7 @@
*/
function hideSpinner() {
$( '.spinner' ).removeClass( 'is-active' );
$( '.post-actions button' ).each( function() {
$( this ).removeAttr( 'disabled' );
} );
$( '.post-actions button' ).removeAttr( 'disabled' );
}
/**
@ -166,7 +163,8 @@
* @param action string publish|draft
*/
function submitPost( action ) {
var data;
var data,
keepFocus = $( document.activeElement ).hasClass( 'draft-button' );
saveAlert = false;
showSpinner();
@ -186,7 +184,7 @@
hideSpinner();
clearNotices();
}).done( function( response ) {
var $link, $button, keepFocus;
var $link, $button;
if ( ! response.success ) {
renderError( response.data.errorMessage );
@ -203,18 +201,17 @@
} else if ( response.data.postSaved ) {
$link = $( '.edit-post-link' );
$button = $( '.draft-button' );
if ( document.activeElement && document.activeElement.className.indexOf( 'draft-button' ) > -1 ) {
keepFocus = true;
}
editLinkVisible = true;
$button.fadeOut( 200, function() {
$button.removeClass( 'is-saving' );
$link.fadeIn( 200 );
if ( keepFocus ) {
$link.focus();
}
$link.fadeIn( 200, function() {
var active = document.activeElement;
// Different browsers move the focus to different places when the button is disabled.
if ( keepFocus && ( active === $button[0] || $( active ).hasClass( 'post-actions' ) || active.nodeName === 'BODY' ) ) {
$link.focus();
}
});
});
}
}).fail( function() {
@ -223,9 +220,13 @@
}
function resetDraftButton() {
$( '.edit-post-link' ).fadeOut( 200, function() {
$( '.draft-button' ).removeClass( 'is-saving' ).fadeIn( 200 );
});
if ( editLinkVisible ) {
editLinkVisible = false;
$( '.edit-post-link' ).fadeOut( 200, function() {
$( '.draft-button' ).removeClass( 'is-saving' ).fadeIn( 200 );
});
}
}
/**
@ -655,16 +656,10 @@
$( document ).on( 'tinymce-editor-init', function( event, ed ) {
editor = ed;
function focus() {
editor.on( 'nodechange', function() {
hasSetFocus = true;
resetDraftButton();
}
if ( window.tinymce.Env.iOS ) {
editor.on( 'click', focus );
} else {
editor.on( 'focus', focus );
}
} );
}).on( 'click.press-this keypress.press-this', '.suggested-media-thumbnail', function( event ) {
if ( event.type === 'click' || event.keyCode === 13 ) {
insertSelectedMedia( $( this ) );

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.2-beta4-32097';
$wp_version = '4.2-beta4-32098';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.