Skip to content

Commit

Permalink
end timer when second click
Browse files Browse the repository at this point in the history
  • Loading branch information
plantain-00 committed Feb 7, 2017
1 parent 385f96c commit 4f5902f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,23 @@ import "tslib";

export class DoubleClick {
clicked = false;
timer: null | number = null;

constructor(private timeout = 300) { }

onclick(singleClick: () => void) {
if (!this.clicked) {
this.clicked = true;
singleClick();
setTimeout(() => {
this.timer = setTimeout(() => {
this.clicked = false;
}, this.timeout);
} else {
this.clicked = false;
if (this.timer) {
clearTimeout(this.timer);
this.timer = null;
}
}
}
}
Expand Down

0 comments on commit 4f5902f

Please sign in to comment.