'use strict';

class LongPress {
  constructor() {
    this.interval = 500
    this.callback = function(){}
  }
  SetInterval(s) {
    this.interval = s
  }
  SetCallback(f) {
    this.callback = f
  }
  SetElement(d) {
    var self = this
      this.elem = d
      this.elem.addEventListener("touchstart", this.startTimer.bind(this), false)
      this.elem.addEventListener("mousedown", this.startTimer.bind(this), false)
      this.elem.addEventListener("touchmove", this.clearTimer.bind(this), false)
      this.elem.addEventListener("mouseout", this.clearTimer.bind(this), false)
      this.elem.addEventListener("touchend", this.clearTimer.bind(this), false)
      this.elem.addEventListener("mouseup", this.clearTimer.bind(this), false)
      this.elem.addEventListener("touchcancel", this.clearTimer.bind(this), false)
  }
  startTimer() {
    (function() {
      this.elem.classList.remove("pressed")
      this.elem.classList.add("pressing")
      this.timer = window.setTimeout(function(){
        this.callback()
        this.elem.classList.add("pressed")
        this.elem.classList.remove("pressing")
      }.bind(this), this.interval)
    }.bind(this))()
  }
  clearTimer() {
    if(this.timer != undefined) {
      window.clearTimeout((function() {
        this.elem.classList.remove("pressing")
        return this.timer
      }.bind(this))())
    }
  }
}

@@ -455,18 +455,19 @@
 r(%22touch
-mo
+lea
 ve%22, thi
@@ -833,24 +833,25 @@
  startTimer(
+e
 ) %7B%0A    (fun
@@ -856,24 +856,51 @@
 unction() %7B%0A
+      console.log(%22start%22)%0A
       this.e
@@ -1191,16 +1191,39 @@
 his))()%0A
+    e.preventDefault()%0A
   %7D%0A  cl
@@ -1279,88 +1279,86 @@
     
-window.clearTimeout((function() %7B%0A        this.elem.classList.remove(%22pressing%22)
+this.elem.classList.remove(%22pressing%22)%0A      window.clearTimeout((function() %7B
 %0A   

Fix touch device bug