Make WordPress Core

Changeset 41646


Ignore:
Timestamp:
09/29/2017 07:11:08 PM (8 years ago)
Author:
azaozz
Message:

Editor: improve attaching a callback on editor init.

See #42029

File:
1 edited

Legend:

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

    r41645 r41646  
    120120                    focusHTMLBookmarkInVisualEditor( editor );
    121121                } else {
    122                     /**
    123                      * TinyMCE is still not loaded. In order to restore the selection
    124                      * when the editor loads, a `on('init')` event is added, that will
    125                      * do the restoration.
    126                      *
    127                      * To achieve that, the initialization config is cloned and extended
    128                      * to include the `setup` method, which makes it possible to add the
    129                      * `on('init')` event.
    130                      *
    131                      * Cloning is used to prevent modification of the original init config,
    132                      * which may cause unwanted side effects.
    133                      */
    134                     var tinyMCEConfig = $.extend(
    135                         {},
    136                         window.tinyMCEPreInit.mceInit[ id ],
    137                         {
    138                             setup: function( editor ) {
    139                                 editor.on( 'init', function( event ) {
    140                                     focusHTMLBookmarkInVisualEditor( event.target );
    141                                 });
    142                             }
    143                         }
    144                     );
    145 
    146                     tinymce.init( tinyMCEConfig );
     122                    tinymce.init( window.tinyMCEPreInit.mceInit[ id ] );
    147123                }
    148124
     
    727703                editor.$( startNode ).before( startElement[0] );
    728704                editor.$( startNode ).after( endElement[0] );
    729             }
    730             else {
     705            } else {
    731706                boundaryRange.collapse( false );
    732707                boundaryRange.insertNode( endElement[0] );
     
    838813            textArea.setSelectionRange( start, end );
    839814        }
     815
     816        // Restore the selection when the editor is initialized. Needed when the Text editor is the default.
     817        $( document ).on( 'tinymce-editor-init.keep-scroll-position', function( event, editor ) {
     818            if ( editor.$( '.mce_SELRES_start' ).length ) {
     819                focusHTMLBookmarkInVisualEditor( editor );
     820            }
     821        } );
    840822
    841823        /**
Note: See TracChangeset for help on using the changeset viewer.