Make WordPress Core

Changeset 32680


Ignore:
Timestamp:
06/01/2015 07:01:53 PM (10 years ago)
Author:
azaozz
Message:

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

File:
1 edited

Legend:

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

    r31996 r32680  
    205205        sticky = '',
    206206        last = 0,
    207         co = $('#content'),
     207        $textarea = $('#content'),
    208208        $document = $(document),
    209209        $editSlugWrap = $('#edit-slug-box'),
     
    213213        $postVisibilitySelect = $('#post-visibility-select'),
    214214        $timestampdiv = $('#timestampdiv'),
    215         $postStatusSelect = $('#post-status-select');
     215        $postStatusSelect = $('#post-status-select'),
     216        isMac = window.navigator.platform ? window.navigator.platform.indexOf( 'Mac' ) !== -1 : false;
    216217
    217218    postboxes.add_postbox_toggles(pagenow);
     
    314315    // This code is meant to allow tabbing from Title to Post content.
    315316    $('#title').on( 'keydown.editor-focus', function( event ) {
    316         var editor, $textarea;
     317        var editor;
    317318
    318319        if ( event.keyCode === 9 && ! event.ctrlKey && ! event.altKey && ! event.shiftKey ) {
    319320            editor = typeof tinymce != 'undefined' && tinymce.get('content');
    320             $textarea = $('#content');
    321321
    322322            if ( editor && ! editor.isHidden() ) {
     
    791791    // word count
    792792    if ( typeof(wpWordCount) != 'undefined' ) {
    793         $document.triggerHandler('wpcountwords', [ co.val() ]);
    794 
    795         co.keyup( function(e) {
     793        $document.triggerHandler('wpcountwords', [ $textarea.val() ]);
     794
     795        $textarea.keyup( function(e) {
    796796            var k = e.keyCode || e.charCode;
    797797
     
    800800
    801801            if ( 13 == k || 8 == last || 46 == last )
    802                 $document.triggerHandler('wpcountwords', [ co.val() ]);
     802                $document.triggerHandler('wpcountwords', [ $textarea.val() ]);
    803803
    804804            last = k;
     
    836836    ( function() {
    837837        var editor, offset, mce,
    838             $textarea = $('textarea#content'),
    839838            $handle = $('#post-status-info'),
    840839            $postdivrich = $('#postdivrich');
     
    924923        });
    925924    }
     925
     926    // Save on pressing Ctrl/Command + S in the Text editor
     927    $textarea.on( 'keydown.wp-autosave', function( event ) {
     928        if ( event.which === 83 ) {
     929            if ( event.shiftKey || event.altKey || ( isMac && ( ! event.metaKey || event.ctrlKey ) ) || ( ! isMac && ! event.ctrlKey ) ) {
     930                return;
     931            }
     932
     933            wp.autosave && wp.autosave.server.triggerSave();
     934            event.preventDefault();
     935        }
     936    });
    926937});
Note: See TracChangeset for help on using the changeset viewer.