Debounce 不适用于 TinyMCE 事件
我正在尝试使用 Ben Alman 的 jquery 插件 debounce,这将限制我的函数被调用的次数。 https://github.com/cowboy/jquery-throttle-debounce
但是,saveEditor 得到的是每次调用(并且在一次按键期间多次调用。主要问题是 saveEditor 被多次调用。我想将其限制为每次延迟只调用一次。这就是我使用该插件的原因。如果有人有更好的 :
这是我在TinyMCE初始化期间的代码
'config' => 'setup : $.debounce(1000, true, function(ed) {
ed.onEvent.add(function(ed, e) {
if( ((e.ctrlKey==true || e.metaKey==true)))
{
saveEditor(this.editorId);
e.returnValue = false;
e.preventDefault();
}
});
ed.onClick.add(function(ed) {
lastClickedEditor = this.editorId;
});
})
I'm trying to use Ben Alman's jquery plugin debounce which will limit the times my function will get called. https://github.com/cowboy/jquery-throttle-debounce
However, saveEditor get's called each time(and many times during one keypress. The main issue is that saveEditor is getting called multiple times. I want to limit it to only be called once every delay. That's why I'm using the plugin. If anyone has a better implementation, please share.
Here is my code during TinyMCE initialization:
'config' => 'setup : $.debounce(1000, true, function(ed) {
ed.onEvent.add(function(ed, e) {
if( ((e.ctrlKey==true || e.metaKey==true)))
{
saveEditor(this.editorId);
e.returnValue = false;
e.preventDefault();
}
});
ed.onClick.add(function(ed) {
lastClickedEditor = this.editorId;
});
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不知何故,看起来好像页面上的每个编辑器实例都调用了保存操作。
我不知道你的函数调用
saveEditor(this.editorId);
会做什么(?)。但使用editor.save();
可以只保存一个编辑器(API 链接)。Somehow it looks as if the save operation gets called for every editor instance on your page.
I do not know what your function call
saveEditor(this.editorId);
does (?). But it is possible to have only one editor save usingeditor.save();
(link to API).