Editor: run autosave when pressing Ctrl or Command + S in the Text editor, same as the Visual editor.

Fixes #31655.

git-svn-id: https://develop.svn.wordpress.org/trunk@32680 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2015-06-01 19:01:53 +00:00
parent 194d266afb
commit 40df2f48bf
1 changed files with 19 additions and 8 deletions

View File

@ -204,7 +204,7 @@ jQuery(document).ready( function($) {
var stamp, visibility, $submitButtons, updateVisibility, updateText,
sticky = '',
last = 0,
co = $('#content'),
$textarea = $('#content'),
$document = $(document),
$editSlugWrap = $('#edit-slug-box'),
postId = $('#post_ID').val() || 0,
@ -212,7 +212,8 @@ jQuery(document).ready( function($) {
releaseLock = true,
$postVisibilitySelect = $('#post-visibility-select'),
$timestampdiv = $('#timestampdiv'),
$postStatusSelect = $('#post-status-select');
$postStatusSelect = $('#post-status-select'),
isMac = window.navigator.platform ? window.navigator.platform.indexOf( 'Mac' ) !== -1 : false;
postboxes.add_postbox_toggles(pagenow);
@ -313,11 +314,10 @@ jQuery(document).ready( function($) {
// This code is meant to allow tabbing from Title to Post content.
$('#title').on( 'keydown.editor-focus', function( event ) {
var editor, $textarea;
var editor;
if ( event.keyCode === 9 && ! event.ctrlKey && ! event.altKey && ! event.shiftKey ) {
editor = typeof tinymce != 'undefined' && tinymce.get('content');
$textarea = $('#content');
if ( editor && ! editor.isHidden() ) {
editor.focus();
@ -790,16 +790,16 @@ jQuery(document).ready( function($) {
// word count
if ( typeof(wpWordCount) != 'undefined' ) {
$document.triggerHandler('wpcountwords', [ co.val() ]);
$document.triggerHandler('wpcountwords', [ $textarea.val() ]);
co.keyup( function(e) {
$textarea.keyup( function(e) {
var k = e.keyCode || e.charCode;
if ( k == last )
return true;
if ( 13 == k || 8 == last || 46 == last )
$document.triggerHandler('wpcountwords', [ co.val() ]);
$document.triggerHandler('wpcountwords', [ $textarea.val() ]);
last = k;
return true;
@ -835,7 +835,6 @@ jQuery(document).ready( function($) {
// Resize the visual and text editors
( function() {
var editor, offset, mce,
$textarea = $('textarea#content'),
$handle = $('#post-status-info'),
$postdivrich = $('#postdivrich');
@ -923,4 +922,16 @@ jQuery(document).ready( function($) {
}
});
}
// Save on pressing Ctrl/Command + S in the Text editor
$textarea.on( 'keydown.wp-autosave', function( event ) {
if ( event.which === 83 ) {
if ( event.shiftKey || event.altKey || ( isMac && ( ! event.metaKey || event.ctrlKey ) ) || ( ! isMac && ! event.ctrlKey ) ) {
return;
}
wp.autosave && wp.autosave.server.triggerSave();
event.preventDefault();
}
});
});