Maharshi
Maharshi

Reputation: 1198

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. Currently, I am binding click event and double click event to the 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. Both codes execute when I double click on the element.

Any solution for CKEditor for above case?

My question is related to CKeditor plugin. So I have to bind proper (built-in) events for click and double click.

Upvotes: 2

Views: 1421

Answers (1)

Abdullah Shoaib
Abdullah Shoaib

Reputation: 464

Try this. It will work. For CKeditor you can replace editor.on('dblclick', function (evt) { line with this line 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);

Upvotes: 3

Related Questions