Editor: improve attaching a callback on editor init.

See #42029
Built from https://develop.svn.wordpress.org/trunk@41646


git-svn-id: http://core.svn.wordpress.org/trunk@41480 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz
2017-09-29 19:12:47 +00:00
parent e4bd7a86a6
commit 309c5559b4
3 changed files with 11 additions and 29 deletions

View File

@@ -119,31 +119,7 @@ window.wp = window.wp || {};
// Restore the selection
focusHTMLBookmarkInVisualEditor( editor );
} else {
/**
* TinyMCE is still not loaded. In order to restore the selection
* when the editor loads, a `on('init')` event is added, that will
* do the restoration.
*
* To achieve that, the initialization config is cloned and extended
* to include the `setup` method, which makes it possible to add the
* `on('init')` event.
*
* Cloning is used to prevent modification of the original init config,
* which may cause unwanted side effects.
*/
var tinyMCEConfig = $.extend(
{},
window.tinyMCEPreInit.mceInit[ id ],
{
setup: function( editor ) {
editor.on( 'init', function( event ) {
focusHTMLBookmarkInVisualEditor( event.target );
});
}
}
);
tinymce.init( tinyMCEConfig );
tinymce.init( window.tinyMCEPreInit.mceInit[ id ] );
}
wrap.removeClass( 'html-active' ).addClass( 'tmce-active' );
@@ -726,8 +702,7 @@ window.wp = window.wp || {};
editor.$( startNode ).before( startElement[0] );
editor.$( startNode ).after( endElement[0] );
}
else {
} else {
boundaryRange.collapse( false );
boundaryRange.insertNode( endElement[0] );
@@ -838,6 +813,13 @@ window.wp = window.wp || {};
textArea.setSelectionRange( start, end );
}
// Restore the selection when the editor is initialized. Needed when the Text editor is the default.
$( document ).on( 'tinymce-editor-init.keep-scroll-position', function( event, editor ) {
if ( editor.$( '.mce_SELRES_start' ).length ) {
focusHTMLBookmarkInVisualEditor( editor );
}
} );
/**
* @summary Replaces <p> tags with two line breaks. "Opposite" of wpautop().
*

File diff suppressed because one or more lines are too long

View File

@@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.9-alpha-41645';
$wp_version = '4.9-alpha-41646';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.