Tuesday, 25 December 2012

Detecting double click in an element

I'm working on an attendance audit screen which allows the user to single click to confirm the selection and double click to create a report. After I googled for the solution, I found the following solution in stackoverflow.com

Below is the code:

// Someone has created the solution as a delegate to ease the implementation.
 $.singleDoubleClick = function (singleClk, doubleClk) {
            return (function () {
                var alreadyclicked = false;
                var alreadyclickedTimeout;

                return function (e) {
                    if (alreadyclicked) {
                        // double
                        alreadyclicked = false;
                        alreadyclickedTimeout && clearTimeout(alreadyclickedTimeout);
                        doubleClk && doubleClk(e);
                    } else {
                        // single
                        alreadyclicked = true;
                        alreadyclickedTimeout = setTimeout(function () {
                            alreadyclicked = false;
                            singleClk && singleClk(e);
                        }, 300);
                    }
                }
            })();
        }

// call this in the document ready:
$('.profile').bind('click', $.singleDoubleClick(confirmSelection, createReport));


We are moving

We are moving this blog to our new blog site: https://ciysys.com/blog/nodejs.htm