Guest User

Untitled

a guest
Oct 11th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  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. }
Add Comment
Please, Sign In to add comment