risposta

2

L'ho risolto da solo. È facile come mappare gli eventi del mouse per toccare gli eventi.

Quindi la soluzione è di cercare & sostituire:

mousedown -> touchstart 
mouseup -> touchend 
mousemove -> touchmove 
10

qui era la mia soluzione per rendere gli eventi supporto touch Mootools trascinare. Questo metodo non mi ha richiesto di modificare i file di mootools più da quando ho usato Class.refactor (Questo è stato testato soltanto con Mootools V.1.3.1) - è anche non rompe i soliti eventi click

Class.refactor(Drag, 
    { 
     attach: function(){ 
      this.handles.addEvent('touchstart', this.bound.start); 
      return this.previous.apply(this, arguments); 
     }, 

     detach: function(){ 
      this.handles.removeEvent('touchstart', this.bound.start); 
      return this.previous.apply(this, arguments); 
     }, 

     start: function(event){ 
      document.body.addEvents({ 
       touchmove: this.bound.check, 
       touchend: this.bound.cancel 
      }); 
      this.previous.apply(this, arguments); 
     }, 

     check: function(event){ 
      if (this.options.preventDefault) event.preventDefault(); 
      var distance = Math.round(Math.sqrt(Math.pow(event.page.x - this.mouse.start.x, 2) + Math.pow(event.page.y - this.mouse.start.y, 2))); 
      if (distance > this.options.snap){ 
       this.cancel(); 
       this.document.addEvents({ 
        mousemove: this.bound.drag, 
        mouseup: this.bound.stop 
       }); 
       document.body.addEvents({ 
        touchmove: this.bound.drag, 
        touchend: this.bound.stop 
       }); 
       this.fireEvent('start', [this.element, event]).fireEvent('snap', this.element); 
      } 
     }, 

     cancel: function(event){ 
      document.body.removeEvents({ 
       touchmove: this.bound.check, 
       touchend: this.bound.cancel 
      }); 
      return this.previous.apply(this, arguments); 
     }, 

     stop: function(event){ 
      document.body.removeEvents({ 
       touchmove: this.bound.drag, 
       touchend: this.bound.stop 
      }); 
      return this.previous.apply(this, arguments); 
     } 
    }); 
+0

impressionante, +1 - se questo è stato testato in produzione e funziona, perché non modificare le classi originali e inviare una richiesta pull a mootools-more, invece? i dispositivi touch sono molto più diffusi e questo è utile per avere subito fuori dalla scatola. –

+0

Grande !! sai come disabilitare lo scorrimento mentre trascini l'evento touch? La mia finestra scorre allo stesso tempo mentre trascina ... – Sergio

+0

In realtà c'è un problema a causa di un bug di Android, vedi http://uihacker.blogspot.it/2011/01/android-touchmove-event-bug.html e http :? //code.google.com/p/android/issues/detail id = 5491. Fondamentalmente è necessario chiamare event.preventDefault() nel callback touchmove, quindi aggiustare le cose per rimuovere correttamente il gestore di eventi – abidibo

Problemi correlati