2015-06-12 52 views
1

我正在研究一個etherpad插件,它在文本編輯過程中提供了一種特殊的自動完成功能。爲此,我需要知道用戶的脫字符號在哪裏。不過,我不知道用戶是否用鼠標點擊移動了插入符號,因爲我找不到適當的鉤子。如何捕捉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); 
} 

我以爲你neeed保持王牌的情況下也是如此,如果不是你不需要使用下劃線的綁定功能。 IE

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