javascript - 如何在 Etherpad 插件中捕获点击事件

标签 javascript etherpad

我正在开发一个 etherpad 插件,它在文本编辑期间提供特殊的自动完成功能。为此,我需要知道用户的插入符在哪里。但是,我不知道用户是否通过单击鼠标来移动插入符号,因为我找不到合适的 Hook 。

作为解决此问题的第一步,我想捕获鼠标单击事件。 (如果我能捕获点击事件,我仍然不确定如何找出插入符位置,但至少我知道何时处理它。)感谢任何帮助。

最佳答案

来自 ep_tasklist 插件 - https://raw.githubusercontent.com/JohnMcLear/ep_tasklist/master/static/js/ace_inner.js通过一些细微的修改,将此作为您想要完成的任务的引用点。

只需将点击监听器事件绑定(bind)到内部文档正文

exports.postAceInit = function(hook, context){
  context.ace.callWithAce(function(ace){
    var doc = ace.ace_getDocument();
    $(doc).find('#innerdocbody').on("click", underscore(SOMEFUNCTIONINCORRECTCONTEXT).bind(ace));
  }, 'myPlugin', true);
}

我假设您也需要保留 ace 的上下文,如果不需要,则不需要使用下划线绑定(bind)功能。浏览器

exports.postAceInit = function(hook, context){
  context.ace.callWithAce(function(ace){
    var doc = ace.ace_getDocument();
    $(doc).find('#innerdocbody').on("click", function(){
       console.log("hello world")
    });
  }, 'myPlugin', true);
}

关于javascript - 如何在 Etherpad 插件中捕获点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30797897/

相关文章:

javascript - NodeJS ES6 模块和 "default"导出/导入

node.js - 如何在 Sandstorm 上安装 Etherpad Lite 插件?

javascript - 无法在沙盒环境中加载 iframe

javascript - 根据从 nodejs 服务获取的数据以 Angular 2 动态更新 Chart js 图表

javascript - 如何求一个字符串中能被3整除的所有整数的总和?

javascript - jQuery 显示一个类并隐藏所有其他类

javascript - 单击浏览器后退按钮返回到 ajax 页面并使其看起来相同吗?

php - 在线 "diary"- 现有脚本/mysql/fwrite()?

etherpad - 是否可以通过 API 将标准 etherpad 作为文本文档读取?

Node.js:使用快速路由进行 url 重写以代理到 etherpad