TinyMCE select text and activate link dialogue with javascript

坚强是说给别人听的谎言 提交于 2019-12-11 04:19:46

问题


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 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.


回答1:


You'll need to enable the button:

tinyMCE.activeEditor.controlManager.get('link').setDisabled(false)



回答2:


This solved my problem:

tinymce.activeEditor.nodeChanged();



来源:https://stackoverflow.com/questions/5917349/tinymce-select-text-and-activate-link-dialogue-with-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!