Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Oct 11th, 2018 67 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. var thingEl = document.getElementById('thing');
  2.  
  3. thingEl.addEventListener(
  4.     'click',
  5.     getClickHandler(
  6.         function () {
  7.             console.log('click');
  8.         },
  9.         function () {
  10.             console.log('dblclick');
  11.         }
  12.     )
  13. );
  14.  
  15. function getClickHandler(onClick, onDblClick, delay) {
  16.     var timeoutID = null;
  17.     delay = delay || 250;
  18.     return function (event) {
  19.         if (!timeoutID) {
  20.             timeoutID = setTimeout(function () {
  21.                 onClick(event);
  22.                 timeoutID = null
  23.             }, delay);
  24.         } else {
  25.             timeoutID = clearTimeout(timeoutID);
  26.             onDblClick(event);
  27.         }
  28.     };
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top