TinyMCE select text and activate link dialogue with javascript
I'm trying to write an automated (using cucumber/capybara/selenium) test that will select some text in a tinymce box, click the link button, and open 开发者_C百科the link selection page.
But the link button only becomes active when some text is selected...so round one:
tinyMCE.activeEditor.selection.select(tinyMCE.activeEditor.dom.select('p')[0]);
This selects the text of the first paragraph (good enough for my purposes) but the link box is still disabled. So then I tried to manually activate it:
tinyMCE.activeEditor.controlManager.setActive('link', true);
This still didn't enable the link button. As a last ditch effort, I tried to modify the classes:
$("#mce_generic_html_link").removeClass("mceButtonDisabled");
$("#mce_generic_html_link").addClass("mceButtonEnabled");
But that didn't help either.
You'll need to enable the button:
tinyMCE.activeEditor.controlManager.get('link').setDisabled(false)
This solved my problem:
tinymce.activeEditor.nodeChanged();
精彩评论