简体   繁体   English

TinyMCE自动保存插件和localStorage

[英]TinyMCE autosave plugin and localStorage

By default, TinyMCE's autosave plugin stores the editor's text in localStorage. 默认情况下,TinyMCE的自动保存插件将编辑器的文本存储在localStorage中。 Is there a way to tell it to use a different storage engine? 有没有办法告诉它使用其他存储引擎? Ultimately what I want to do is set up a listener on the storeDraft event so I can persist the contents to our server so the user can access the contents even after the autosave_retention limit has been surpassed. 最终,我想做的是在storeDraft事件上设置一个侦听器,这样我就可以将内容持久保存到我们的服务器,以便即使超过了autosave_retention限制,用户也可以访问内容。 I know that I can set the autosave_rentention to 0 but even when I do I can see that it still writes the data to localStorage -- it just removes it (though, sometimes not immediately and it seems like a page reload short circuits that in some cases). 我知道我可以将autosave_rentention设置为0,但是即使我这样做,我仍然可以看到它仍然将数据写入localStorage -只是将其删除(尽管有时不是立即,而且似乎页面重新加载时出现短路,在某些情况下例)。

So basically, I'd like to hit 2 birds with one stone. 所以基本上,我想用一块石头打两只鸟。 I'd like to stop TinyMCE from storing the data in localStorage and, if I can specify a different "data store", then perhaps I can point it to my ajax handler which will persist to the back end. 我想停止TinyMCE将数据存储在localStorage中,如果可以指定其他“数据存储”,那么也许可以将其指向我的ajax处理程序,该处理程序将一直保留到后端。

Any advice would be greatly appreciated! 任何建议将不胜感激!

thnx, 日Thnx,
Christoph 克里斯托夫

The autosave plugin is designed to work with local storage and has no option to change to a different storage mechanism. autosave插件旨在与本地存储一起使用,并且没有选择更改为其他存储机制的选项。 If you want to store the data on your server you would typically that with some custom code that uses either (a) TinyMCE events or (b) a timer to get the editor's current content and then send it to the server. 如果要将数据存储在服务器上,通常可以使用一些自定义代码,这些代码使用(a)TinyMCE事件或(b)计时器来获取编辑器的当前内容,然后将其发送到服务器。

If you want to use TinyMCE events ( https://www.tiny.cloud/docs/advanced/events/#editorevents ) to trigger this process you would have code along these lines: 如果要使用TinyMCE事件( https://www.tiny.cloud/docs/advanced/events/#editorevents )触发此过程,则可以使用以下代码:

tinymce.init({
    selector: "textarea",
    ...
    setup: function (editor) {
      editor.on('init change NodeChange Dirty', function (e) {
        // 1. use getContent() to extract the editor's current HTML 
        // 2. send the HTML to your server
      });
    }
});

If you want to use a basic timer (eg setTimeout() ) you would use that to trigger the same two actions as the sample code above. 如果要使用基本计时器(例如setTimeout() ),则可以使用它触发与上面的示例代码相同的两个操作。

In theory you could modify the autosave plugin to send data to your server as opposed to storing the data in local storage but I think you can do what you need in a far simpler way without needing to dig into the ~200 lines of code in the existing plugin. 从理论上讲,您可以修改autosave插件以将数据发送到服务器,而不是将数据存储在本地存储中,但是我认为您可以用一种更简单的方式来完成所需的操作,而无需深入研究〜200行代码。现有的插件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM