Last active
July 28, 2020 14:11
-
-
Save unknownuser88/8284954 to your computer and use it in GitHub Desktop.
mobile drag & drop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).on('pageshow', '#index', function(){ | |
$(".dragzones").draggable({ | |
start: handleDragStart, | |
cursor: 'move', | |
revert: "invalid", | |
}); | |
$(".dropzones").droppable({ | |
drop: handleDropEvent, | |
tolerance: "touch", | |
}); | |
}); | |
function handleDragStart (event, ui) { } | |
function handleDropEvent (event, ui) { | |
if (ui.draggable.element !== undefined) { | |
ui.draggable.element.droppable('enable'); | |
} | |
$(this).droppable('disable'); | |
ui.draggable.position({of: $(this),my: 'left top',at: 'left top'}); | |
ui.draggable.draggable('option', 'revert', "invalid"); | |
ui.draggable.element = $(this); | |
} | |
/iPad|iPhone|Android/.test( navigator.userAgent ) && (function( $ ) { | |
var proto = $.ui.mouse.prototype, | |
_mouseInit = proto._mouseInit; | |
$.extend( proto, { | |
_mouseInit: function() { | |
this.element | |
.bind( "touchstart." + this.widgetName, $.proxy( this, "_touchStart" ) ); | |
_mouseInit.apply( this, arguments ); | |
}, | |
_touchStart: function( event ) { | |
this.element | |
.bind( "touchmove." + this.widgetName, $.proxy( this, "_touchMove" ) ) | |
.bind( "touchend." + this.widgetName, $.proxy( this, "_touchEnd" ) ); | |
this._modifyEvent( event ); | |
$( document ).trigger($.Event("mouseup")); //reset mouseHandled flag in ui.mouse | |
this._mouseDown( event ); | |
//return false; | |
}, | |
_touchMove: function( event ) { | |
this._modifyEvent( event ); | |
this._mouseMove( event ); | |
}, | |
_touchEnd: function( event ) { | |
this.element | |
.unbind( "touchmove." + this.widgetName ) | |
.unbind( "touchend." + this.widgetName ); | |
this._mouseUp( event ); | |
}, | |
_modifyEvent: function( event ) { | |
event.which = 1; | |
var target = event.originalEvent.targetTouches[0]; | |
event.pageX = target.clientX; | |
event.pageY = target.clientY; | |
} | |
}); | |
})( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment