Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var thingEl = document.getElementById('thing');
- thingEl.addEventListener(
- 'click',
- getClickHandler(
- function () {
- console.log('click');
- },
- function () {
- console.log('dblclick');
- }
- )
- );
- function getClickHandler(onClick, onDblClick, delay) {
- var timeoutID = null;
- delay = delay || 250;
- return function (event) {
- if (!timeoutID) {
- timeoutID = setTimeout(function () {
- onClick(event);
- timeoutID = null
- }, delay);
- } else {
- timeoutID = clearTimeout(timeoutID);
- onDblClick(event);
- }
- };
- }
Add Comment
Please, Sign In to add comment