简体   繁体   English

如何在CKeditor中的同一元素上绑定单击和双击事件

[英]How to bind click and double click events on the same element in CKeditor

I am having an issue with CKeditor click event and double-click events. 我在CKeditor click事件和双击事件方面遇到问题。 Currently, I am binding click event and double click event to the CKEditor dom. 当前,我将单击事件和双击事件绑定到CKEditor dom。

    editor.on('doubleclick', function (evt) {
        console.log("doubleclicked");
        //Some ajax calls
    }, null, null, 999 );
    editor.on('click', function (evt) {
        console.log("clicked");
        //Some ajax calls
    }, null, null);

An issue with above code is, it fires click event first as well when I double-click the element. 上面的代码有一个问题,当我双击该元素时,它也会首先触发click事件。 Both codes execute when I double click on the element. 当我双击该元素时,两个代码都会执行。

Any solution for CKEditor for above case? 以上情况的CKEditor有解决方案吗?

My question is related to CKeditor plugin. 我的问题与CKeditor插件有关。 So I have to bind proper (built-in) events for click and double click. 因此,我必须为单击和双击绑定适当的(内置)事件。

Try this. 尝试这个。 It will work. 它会工作。 For CKeditor you can replace editor.on('dblclick', function (evt) { line with this line editor.on('doubleclick', function (evt) { 对于CKeditor,您可以用该行editor.on('doubleclick', function (evt) { editor.on('dblclick', function (evt) {替换行editor.on('doubleclick', function (evt) {

Check this link. 检查此链接。

    function singleClick(e) {
       console.log('single click');
   }

   function doubleClick(e) {
       console.log('double click');
   }

   editor.on('dblclick', function (evt) {
        $(this).data('double', 2);
        doubleClick.call(this, evt);
        //Some ajax calls
    }, null, null, 999 );
    editor.on('click', function (evt) {
        var that = this;
        setTimeout(function() {
            var dblclick = parseInt($(that).data('double'), 10);
            if (dblclick > 0) {
                $(that).data('double', dblclick-1);
            } else {
                singleClick.call(that, evt);
            }
        }, 300);
        //Some ajax calls
    }, null, null);

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

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