Skip to content

Commit

Permalink
Create TinyMCE command for adding media
Browse files Browse the repository at this point in the history
The "add media" dialog appears after clicking on the "add media" icon in
the TinyMCE toolbar.

Previously, this occurred as a direct result of the `onclick` handler in
`editor.addButton()`. Because this meant that adding media was dependent
on clicking the button, it prevented being able to do so in other ways,
such as is the goal in #5071

This patch moves the code to cause the media dialog to appear into a new
command, which the button then calls when it's clicked.
  • Loading branch information
dmsnell committed Apr 28, 2016
1 parent bd4b946 commit e708dd1
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions client/components/tinymce/plugins/media/plugin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,28 +281,28 @@ function mediaButton( editor ) {
renderDropZone( { visible: event.type === 'dragend' } );
}

editor.addCommand( 'wpcom_add_media', () => {
var selectedSite = sites.getSelectedSite();
if ( selectedSite ) {
MediaActions.clearValidationErrors( selectedSite.ID );
}

renderModal( {
visible: true,
initialActiveView: MediaModalViews.LIST
} );
} );

editor.addButton( 'wpcom_add_media', {
classes: 'btn wpcom-icon-button media',

cmd: 'wpcom_add_media',
title: i18n.translate( 'Add Media' ),

onPostRender: function() {
this.innerHtml( ReactDomServer.renderToStaticMarkup(
<button type="button" role="presentation" tabIndex="-1">
<Gridicon icon="image-multiple" size={ 20 } nonStandardSize />
</button>
) );
},
onclick: function() {
var selectedSite = sites.getSelectedSite();
if ( selectedSite ) {
MediaActions.clearValidationErrors( selectedSite.ID );
}

renderModal( {
visible: true,
initialActiveView: MediaModalViews.LIST
} );
}
} );

Expand Down

0 comments on commit e708dd1

Please sign in to comment.