jquery 可排序的 TinyMCE 实例
我感到困惑和沮丧,所以是时候寻求帮助了。做了很多谷歌搜索,但尚未找到适合我的解决方案。
我拥有的是一大堆可以使用 Jquery sortable 进行排序的 div,其中一些 div 包含一个 TinyMCE 实例。这一切都很好,直到您尝试移动包含 TinyMCE 实例的 div - 当您这样做时,TinyMCE 似乎会刷新自身并创建一个新实例,然后您会因此丢失数据等。然后整个页面会中断,因为 javascript 不再有效:)。在此期间,我在 Firebug 中遇到了 javascript 构造函数错误等。
我决定最好的方法是,当 div 开始被拖动时,从文本区域中删除tinymce,当它被放置在新位置时,将tinymce 重新插入。
我可以很好地删除它,但无法将其添加回来 -当我收到更多构造函数错误时。
注意:TinyMCE 会自动添加到我正在使用的系统内的所有文本区域,因此尽量避免与 TinyMCE 发生混淆。
在下面的代码中,我只是针对特定的文本区域 ID 进行测试。
$cols.sortable({
cursor: 'move',
revert: true,
opacity: 0.6,
placeholder: 'widgetplaceholder',
forcePlaceholderSize: true,
connectWith: cols,
zIndex:9000,
cancel: ".collapsable_box_editpanel_groups, .collapsable_box_content",
start: function(e, ui) {
// removes tinymce ok from textarea
tinyMCE.execCommand( 'mceRemoveControl', false, 'textarea1' );
},
stop: function(e,ui) {
// breaks here - constructor error
tinyMCE.execCommand( 'mceAddControl', true, 'textarea1' );
$(this).sortable( "refresh" );
}
});
还有其他人有其他解决方案吗?如果您需要更多信息,请告诉我:)
I'm stumped and frustrated so time to ask for help. Done a lot of googling but yet to find a solution that works for me.
What I have is a whole bunch of divs that can be sorted using Jquery sortable, some of divs contain a TinyMCE instance. Which is all fine until you try to move a div that contains a TinyMCE instance - when you do TinyMCE seems to refresh itself and creates a new instance which you then therefore lose the data etc. And then the whole page breaks as the javascript no longer works :). During this time I get javascript constructor errors etc in Firebug.
What I have decided the best way to go is when the div starts to get dragged remove tinymce from the text area and when it is placed in it's new position insert tinymce back in.
I can remove it fine but having trouble adding it back in - as I get more constructor errors.
Note: TinyMCE automatically gets added to all my text areas within the system I'm using so trying to avoid messing with TinyMCE.
In the code below I'm simply targeting a specific textarea id for testing purposes.
$cols.sortable({
cursor: 'move',
revert: true,
opacity: 0.6,
placeholder: 'widgetplaceholder',
forcePlaceholderSize: true,
connectWith: cols,
zIndex:9000,
cancel: ".collapsable_box_editpanel_groups, .collapsable_box_content",
start: function(e, ui) {
// removes tinymce ok from textarea
tinyMCE.execCommand( 'mceRemoveControl', false, 'textarea1' );
},
stop: function(e,ui) {
// breaks here - constructor error
tinyMCE.execCommand( 'mceAddControl', true, 'textarea1' );
$(this).sortable( "refresh" );
}
});
Anybody else have any other solutions? If you need more information please let me :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
嘿,如果您的 MCE 实例中已经有数据,为了避免丢失它,您可以尝试以下操作:
在我的例子中,我将所有 MCE 实例分类为 .tinyMCE
Hey if you already have data in your MCE instances, to avoid losing it, you can try this:
In my case i classed all MCE Instances with .tinyMCE
适用于 TinyMCE 版本 4
For version 4 of TinyMCE
好吧,对于 TinyMce v.4+,这个问题的一个稳定解决方案是:
如果您的文本区域应用了不止一种类型的设置,则必须在每次重置之前声明
tinymce.init(settings)
,否则最后应用的一项将适用于所有人。改变设置的一个简单方法是在文本区域上设置设置类型的标志,例如:
然后使用加载器函数来分发必要的函数:
Well, a stable solution of this problem, for TinyMce v.4+ is :
If your textarea have more than one type of settings applied, you must declare
tinymce.init(settings)
before each reset, otherwise the last one applied will apply to all.An easy way to variate settings is to set a flag of settings type on your textarea such as :
<textarea data-type="settings_one"></textarea>
<textarea data-type="settings_two"></textarea>
and then use a loader function which will distrubute the necessary one :
对于任何尝试动态分配“textarea1”的人来说,可拖动对象位于 ui 对象中,作为 ui.item。对于每个可排序的一个文本区域:
For anyone trying to dynamically assign "textarea1", the draggable is in the ui object as ui.item. For one textarea per sortable:
我最终只是销毁并重新创建了可排序 stop() 事件上的编辑:
就像一个魅力,可能是比其他建议更好的选择,在 start() 事件上销毁编辑器,然后在 stop() 上重新创建 - 因为这您仍然在拖动具有视觉吸引力的编辑器。 PS使用TinyMCE 4.5.2
I ended up just destroying and recreating the edit on sortable stop() event:
Works like a charm and is probably a better option than other suggestions to destroy the editor on start() event and then re-create on stop() - because this way you are still dragging visually appealing editor. P.S. Using TinyMCE 4.5.2
不,没有其他解决方案。这就是它需要完成的方式。
当操作包含tinymce实例的dom元素时,您需要停用它们,并在使用
mceRemoveControl
和mceAddControl
完成dom操作后重新激活它们。No, there is no other solution. This is the way it needs to be done.
When manipulatin dom elements containing tinymce instances you need to deactivate them and reactivate them when you are done with the dom operation using
mceRemoveControl
andmceAddControl
.我有一个包含多个段落的动态表单,所有这些段落都可以使用 TinyMCE 进行编辑。为了允许对段落进行重新排序,我添加了用于上下移动文本区域的按钮。
我设法使用按钮上的 alt="textareaid" 向上或向下移动文本区域,并使用此 textareaid 执行 mceRemoveEditor 和 mceAddEditor 命令,使其正常工作。文本区域必须位于 class="textarea_container" 的 div 中。
I have a dynamic form with multiple paragraphs that can all be edited with TinyMCE. To allow re-sorting of the paragraphs, I added buttons that move the textareas up and down.
I managed to get it to work using an alt="textareaid" on the button that moves a textarea up or down, and using this textareaid for the mceRemoveEditor and mceAddEditor commands. The textarea has to be in a div with class="textarea_container".
对我来说有效的解决方案就在这里。 适用于 TinyMCE 版本 4
所以我在结合上述一些解决方案后得出了这个最终的解决方案。感谢@Honorable Chow,@pragmar @Sonicdesign 那么你们的解决方案对我来说并不奏效,所以我修改了它们。这是我的代码,对我来说效果很好。
For me worked solution is here. For version 4 of TinyMCE
So I came to this final solution after combining some of above solutions. Thanks to @Honorable Chow , @pragmar @Sonicdesign Well your solutions didn't worked for me as they are, so I modified them. Here is my code which is worked fine for me.
我能够解决类似的问题:
tinymce.activeEditor.setMode('readonly');
和
tinymce.activeEditor.setMode('design');
这适用于版本 4.3.x
I has able to solve similar problem with:
tinymce.activeEditor.setMode('readonly');
and
tinymce.activeEditor.setMode('design');
this works for version 4.3.x
我已经做了
i have done
这非常好用,我只用过一个编辑器。非常感谢 :) 。
This works great just I used for one editor. Thank you very much :) .