diff --git a/js-tests/build/specs.js b/js-tests/build/specs.js index db4eaf24..ab7f8f34 100644 --- a/js-tests/build/specs.js +++ b/js-tests/build/specs.js @@ -1195,12 +1195,14 @@ var shortcodeViewConstructor = { if ( frame ) { frame.mediaController.setActionUpdate( currentShortcode ); + frame.mediaController.props.set( 'editor', wpActiveEditor ); frame.open(); } else { frame = wp.media.editor.open( window.wpActiveEditor, { frame : "post", state : 'shortcode-ui', currentShortcode : currentShortcode, + editor : wpActiveEditor, }); } diff --git a/js/build/shortcode-ui.js b/js/build/shortcode-ui.js index 1a040842..31726350 100644 --- a/js/build/shortcode-ui.js +++ b/js/build/shortcode-ui.js @@ -49,6 +49,7 @@ var MediaController = wp.media.controller.State.extend({ action: 'select', search: null, insertCallback: this.insertCallback, + editor: wpActiveEditor, }); this.props.on( 'change:action', this.refresh, this ); @@ -80,6 +81,8 @@ var MediaController = wp.media.controller.State.extend({ var shortcode = this.props.get( 'currentShortcode' ); var insertCallback = this.props.get( 'insertCallback' ); + this.setActiveEditor( this.props.get( 'editor' ) ); + if ( shortcode && insertCallback ) { insertCallback( shortcode ); } @@ -159,6 +162,15 @@ var MediaController = wp.media.controller.State.extend({ this.frame.$el.toggleClass( 'hide-menu', show ); }, + setActiveEditor: function( editorId ) { + var editor = tinymce.get( editorId ); + + if ( editor ) { + tinymce.setActive( editor ); + } + + window.wpActiveEditor = editorId; + }, }); sui.controllers.MediaController = MediaController; @@ -362,7 +374,8 @@ $(document).ready(function(){ options = { frame: 'post', state: 'shortcode-ui', - title: shortcodeUIData.strings.media_frame_title + title: shortcodeUIData.strings.media_frame_title, + editor: this.dataset.editor }; event.preventDefault(); @@ -374,6 +387,7 @@ $(document).ready(function(){ if ( frame ) { frame.mediaController.setActionSelect(); + frame.mediaController.props.set( 'editor', this.dataset.editor ); frame.open(); } else { frame = wp.media.editor.open( editor, options ); @@ -678,12 +692,14 @@ var shortcodeViewConstructor = { if ( frame ) { frame.mediaController.setActionUpdate( currentShortcode ); + frame.mediaController.props.set( 'editor', wpActiveEditor ); frame.open(); } else { frame = wp.media.editor.open( window.wpActiveEditor, { frame : "post", state : 'shortcode-ui', currentShortcode : currentShortcode, + editor : wpActiveEditor, }); } diff --git a/js/src/controllers/media-controller.js b/js/src/controllers/media-controller.js index 8c8d8979..88c0e8a3 100644 --- a/js/src/controllers/media-controller.js +++ b/js/src/controllers/media-controller.js @@ -12,6 +12,7 @@ var MediaController = wp.media.controller.State.extend({ action: 'select', search: null, insertCallback: this.insertCallback, + editor: wpActiveEditor, }); this.props.on( 'change:action', this.refresh, this ); @@ -43,6 +44,8 @@ var MediaController = wp.media.controller.State.extend({ var shortcode = this.props.get( 'currentShortcode' ); var insertCallback = this.props.get( 'insertCallback' ); + this.setActiveEditor( this.props.get( 'editor' ) ); + if ( shortcode && insertCallback ) { insertCallback( shortcode ); } @@ -122,6 +125,15 @@ var MediaController = wp.media.controller.State.extend({ this.frame.$el.toggleClass( 'hide-menu', show ); }, + setActiveEditor: function( editorId ) { + var editor = tinymce.get( editorId ); + + if ( editor ) { + tinymce.setActive( editor ); + } + + window.wpActiveEditor = editorId; + }, }); sui.controllers.MediaController = MediaController; diff --git a/js/src/shortcode-ui.js b/js/src/shortcode-ui.js index 03c13ffe..b4ccb780 100644 --- a/js/src/shortcode-ui.js +++ b/js/src/shortcode-ui.js @@ -30,7 +30,8 @@ $(document).ready(function(){ options = { frame: 'post', state: 'shortcode-ui', - title: shortcodeUIData.strings.media_frame_title + title: shortcodeUIData.strings.media_frame_title, + editor: this.dataset.editor }; event.preventDefault(); @@ -42,6 +43,7 @@ $(document).ready(function(){ if ( frame ) { frame.mediaController.setActionSelect(); + frame.mediaController.props.set( 'editor', this.dataset.editor ); frame.open(); } else { frame = wp.media.editor.open( editor, options ); diff --git a/js/src/utils/shortcode-view-constructor.js b/js/src/utils/shortcode-view-constructor.js index 2d0f6dde..8610c161 100644 --- a/js/src/utils/shortcode-view-constructor.js +++ b/js/src/utils/shortcode-view-constructor.js @@ -170,12 +170,14 @@ var shortcodeViewConstructor = { if ( frame ) { frame.mediaController.setActionUpdate( currentShortcode ); + frame.mediaController.props.set( 'editor', wpActiveEditor ); frame.open(); } else { frame = wp.media.editor.open( window.wpActiveEditor, { frame : "post", state : 'shortcode-ui', currentShortcode : currentShortcode, + editor : wpActiveEditor, }); }