Skip to content

Commit

Permalink
Merge pull request #746 from wp-shortcake/set-active-editor
Browse files Browse the repository at this point in the history
Set active editor
  • Loading branch information
goldenapples authored Sep 12, 2017
2 parents cf2782b + db25c16 commit 4628855
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions js-tests/build/specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}

Expand Down
18 changes: 17 additions & 1 deletion js/build/shortcode-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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 );
Expand Down Expand Up @@ -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,
});
}

Expand Down
12 changes: 12 additions & 0 deletions js/src/controllers/media-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion js/src/shortcode-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 );
Expand Down
2 changes: 2 additions & 0 deletions js/src/utils/shortcode-view-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}

Expand Down

0 comments on commit 4628855

Please sign in to comment.