-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create TinyMCE command for adding media #5092
Conversation
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.
Code looks good and I didn't find any regressions. There is nothing on TinyMCE's documentation warning about collisions between buttons and commands. I don't think it will be an issue. |
Done! thanks for the suggestion |
@@ -281,28 +281,28 @@ function mediaButton( editor ) { | |||
renderDropZone( { visible: event.type === 'dragend' } ); | |||
} | |||
|
|||
editor.addCommand( 'wpcomAddMedia', () => { | |||
var selectedSite = sites.getSelectedSite(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for the var over a const?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gwwar just because I was trying not to change the code
you think I should change it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's already mixed usage in the file, so either way works with me. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be fine to change I think.
@gwwar @dmsnell This is an in-progress feature related to #307, feature-flagged by |
Looks good 👍 |
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 ineditor.addButton()
. Because this meant that adding media was dependenton 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.
Testing
There are no visual or functional changes here. Try to edit a post and add media. Click on the "add media" button. Test any other existing ways you know of to add media into a post to make sure this doesn't introduce any regressions.
Questions
Is it wrong to name the action the same thing as the button? Do they live in different namespaces or will we inadvertently cause collisions by doing this?- I have renamed the command based on a suggestion from @rodrigoi - it is nowwpcomAddMedia
cc: @aduth