【问题标题】:How to catch click events in an Etherpad plugin如何在 Etherpad 插件中捕获点击事件
【发布时间】:2015-06-12 07:46:52
【问题描述】:

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

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

【问题讨论】:

    标签: javascript etherpad


    【解决方案1】:

    来自 ep_tasklist 插件 - https://raw.githubusercontent.com/JohnMcLear/ep_tasklist/master/static/js/ace_inner.js 进行了一些小的修改,将其用作您要完成的工作的参考点。

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

    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 的上下文,否则您不需要使用下划线绑定功能。浏览器

    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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多