From 40df2f48bf9768a88fec08df2bb375072a973c67 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Mon, 1 Jun 2015 19:01:53 +0000 Subject: [PATCH] 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 --- src/wp-admin/js/post.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/wp-admin/js/post.js b/src/wp-admin/js/post.js index 8dfdf3715f..ae0c094bd5 100644 --- a/src/wp-admin/js/post.js +++ b/src/wp-admin/js/post.js @@ -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(); + } + }); });