2013-06-26 11 views

risposta

5

Puoi farlo modificando dragdrop.js come menzione here:

In Draggables:

register: function(draggable) { 
    if(this.drags.length == 0) { 
     this.eventMouseUp = this.endDrag.bindAsEventListener(this); 
     this.eventMouseMove = this.updateDrag.bindAsEventListener(this); 
     this.eventKeypress = this.keyPress.bindAsEventListener(this); 


     Event.observe(document, "mouseup", this.eventMouseUp); 
     Event.observe(document, "mousemove", this.eventMouseMove); 
     Event.observe(document, "keypress", this.eventKeypress); 


     Event.observe(document, "touchstart", this.eventKeypress); 
     Event.observe(document, "touchmove", this.eventMouseMove); 
     Event.observe(document, "touchend", this.eventMouseUp); 
    } 
    this.drags.push(draggable); 
    }, 


    unregister: function(draggable) { 
    this.drags = this.drags.reject(function(d) { return d==draggable }); 
    if(this.drags.length == 0) { 
     Event.stopObserving(document, "touchstart", this.eventKeypress); 
     Event.stopObserving(document, "touchmove", this.eventMouseMove); 
     Event.stopObserving(document, "touchend", this.eventMouseUp); 


     Event.stopObserving(document, "mouseup", this.eventMouseUp); 
     Event.stopObserving(document, "mousemove", this.eventMouseMove); 
     Event.stopObserving(document, "keypress", this.eventKeypress); 
    } 
    }, 

In Draggable:

initialize: 
... 
    this.eventMouseDown = this.initDrag.bindAsEventListener(this); 
    Event.observe(this.handle, "mousedown", this.eventMouseDown); 
     Event.observe(this.handle, "touchstart", this.eventMouseDown); 


    Draggables.register(this); 
    }, 


    destroy: function() { 
    Event.stopObserving(this.handle, "mousedown", this.eventMouseDown); 
    Event.stopObserving(this.handle, "touchstart", this.eventMouseDown); 
    Draggables.unregister(this); 
    }, 

... 

initDrag: function(event) { 
    if(!Object.isUndefined(Draggable._dragging[this.element]) && 
     Draggable._dragging[this.element]) return; 
    if(Event.isLeftClick(event) || event.type == "touchstart") { 

Insieme con editing prototype.js:

function pointerX(event) { 
    var docElement = document.documentElement, 
    body = document.body || { scrollLeft: 0 }; 


    if (event.changedTouches) return (event.changedTouches[0].clientX + 
     (docElement.scrollLeft || body.scrollLeft) - 
     (docElement.clientLeft || 0)); 


    return event.pageX || (event.clientX + 
     (docElement.scrollLeft || body.scrollLeft) - 
     (docElement.clientLeft || 0)); 
    } 


    function pointerY(event) { 
    var docElement = document.documentElement, 
    body = document.body || { scrollTop: 0 }; 


    if (event.changedTouches) return (event.changedTouches[0].clientY + 
     (docElement.scrollTop || body.scrollTop) - 
     (docElement.clientTop || 0)); 


    return event.pageY || (event.clientY + 
     (docElement.scrollTop || body.scrollTop) - 
     (docElement.clientTop || 0)); 
    } 
+0

che meritava un voto. scusate, ma dovevo menzionare il buon uso della semplice manipolazione dei metodi, se volete, ma non sarebbe considerato come modificare le funzionalità di base? se puoi aiutarmi a decidere, potrei passare al prototipo su un'altra app e questo è l'unico posto in cui potrei trovare qualcuno che ne parli. Dovrebbe funzionare bene male dare un vortice e vedere quanto in alto posso spingerlo fino alla stella centrale. :-) – blamb

0

Penso che tu debba usare la funzione parseInt per le coordinate X, Y, perché ho qualche problema con il browser Chrome su Android: mette qualcosa come il 23.45435435345345345345345 sulle coordinate.

//Add parseInt ----------------[start] 
if (event.changedTouches) return (parseInt(event.changedTouches[0].clientY + 
     (docElement.scrollTop || body.scrollTop) - 
     (docElement.clientTop || 0),10)); 
//Add parseInt ----------------[end]