带 ajax 选项卡的 TinyMCE
我正在使用 JQuery UI 1.8 的选项卡组件,并且通过 ajax(html 内容)加载选项卡的内容。在其中一个选项卡中,我使用tinyMCE组件,当我第一次加载该选项卡时,tiny会正确初始化,但如果我导航到其他选项卡并再次调用该选项卡,tiny就会崩溃。
当tiny_mce.js 的导入位于选项卡内容之外时,就会发生这种情况。当我将导入移至选项卡调用时,微小的未加载,因为它似乎未初始化。
问题是:如何在ajax选项卡中初始化tiny?
提前致谢。
I'm using tabs component of JQuery UI 1.8, and I'm loading content of tabs via ajax (html content). In one of this tabs I'm using tinyMCE component, and when I load this tab the first time, the tiny initializates correctly but if I navegate to other tab and I recall the tab again the tiny breaks down.
This occurs when the import of tiny_mce.js is outside the contents of tabs. When I move the import into tab call, the tiny didn't load because it seems to be not initialized.
The question is: how can initialize tiny in an ajax tab?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
当我在使用 TinyMCE 并在 ajax 加载选项卡之间切换时遇到类似问题时,我在 Ready4State 所以我想我会分享,因为我希望它能帮助其他人。
这将删除页面上所有 TinyMCE 实例。
然后您就可以安全地重新初始化 TinyMCE。
就我个人而言,我在使用 switch 语句处理每个 ui.index 之前执行上述代码,并且我有一个执行 TinyMCE 初始化的函数。所以我只是在每个相关的 case 语句中调用该函数。
希望这对其他人有帮助。
When I was having similar problems with TinyMCE and switching between ajax loaded tabs I found this wonderful piece of code at Ready4State so I thought I would share as I hope it helps others.
This will remove all instances of TinyMCE on the page.
Then you can safely reinitialize TinyMCE.
Personally I carry out the above code before using a switch statement to handle each ui.index, and I have a function that performs the initialisation for TinyMCE. So I just call that function in each of the relevant case statements.
Hope this helps someone else.
每次切换回带有编辑器的选项卡时,可能值得重新初始化微型 MCE。您可以在选项卡对象上使用“select”事件。
在重新初始化之前,您可能必须销毁编辑器的任何先前实例/引用。
It might be worth re-initialising tiny MCE every time you switch back to the tab with the editor in. You can use the "select" event on the tab object.
You may have to destroy any previous instances of / references to the editor before re-initialising.
在切换到另一个选项卡之前,您需要关闭 tinymce 实例,否则具有该 id 的编辑器元素将被阻止。
在切换选项卡之前删除控件
You need to shut down your tinymce instances before you switch to another tab else the editor element with that id will be blocked.
Remove the control before you switch the tab using
我找到了解决问题的方法。 tinymce的初始化必须在jquery tabs的load事件中进行,如下所示:
我希望这对其他人有帮助。另外,如果通过ajax加载textarea的内容,则
不需要命令:。
I found the solution to my problem. The initialization of tinymce must be in load event of jquery tabs, like this:
I hope this helps others. Besides, if the content of the textarea is load via ajax, the command:
is not necesary.
好吧,今天花了 3 个小时解决同样的问题...使用 Jquery UI 1.10 和 TinyMCE 4。
问题是,当取消选择时,ajax 面板的内容不会从 DOM 中删除,而只是隐藏。这意味着文本区域在 DOM 中的出现可能会超过 1 倍(导航面板)。 =>微小的 MCE 之死...
Jquery 1.10 中没有事件来捕捉“未选择的面板”。您必须处理加载前事件。
因此,我们的想法是在加载面板之前清空每个“ajax 加载”面板。代码:
注意我还没有找到区分“ajax加载面板”和“预加载面板”的方法...
这很遗憾,因为您必须将每个“预加载面板”id 添加到代码中......
无论如何,这解决了微小的 MCE 问题。无需初始化加载事件,并使用 mceRemoveControl/mceAddControl 命令。
只需在“ajax加载选项卡面板”视图中初始化tinyMCE编辑:
Well, spent 3 hours on the same problem today... with Jquery UI 1.10 and TinyMCE 4.
The problem is, when unselected, the content of the ajax panel isnt removed from the DOM but just hidden. That means the textarea could be more than 1 time in the DOM (navigating the panels). => Death of tiny MCE...
There is no event in Jquery 1.10 to catch an "unselected panel". You have to deal with the before load event.
So the idea is to empty each "ajax loaded" panel before to load a panel. The code :
Note i havn't find the way to make the difference between "ajax loaded panels" and "pre-loaded panels"...
That's a shame because you have to add each "pre-loaded panel" ids into the code...
Anyway, that resolve the tiny MCE problem. No need to init into the load event, and use the mceRemoveControl/mceAddControl commands.
Just init the tinyMCE edit in the "ajax loaded tab panel" view :