/** custom drag event for touch devices used in scrollbars. for better touch event handling and extra options a more advanced solution such as hammer.js is recommended. */ //based on but not dependent on jquery mobile /* * jquery mobile v1.3.2 * http://jquerymobile.com * * copyright 2010, 2013 jquery foundation, inc. and other contributors * released under the mit license. * http://jquery.org/license * */ (function($ , undefined) { if(!ace.vars['touch']) return; var touchstartevent = "touchstart mspointerdown pointerdown",// : "mousedown", touchstopevent = "touchend touchcancel mspointerup mspointercancel pointerup pointercancel",// : "mouseup", touchmoveevent = "touchmove mspointermove mspointerhover pointermove";// : "mousemove"; $.event.special.ace_drag = { setup: function() { var min_threshold = 0; var $this = $(this); $this.on(touchstartevent, function(event) { var data = event.originalevent.touches ? event.originalevent.touches[ 0 ] : event, start = { //time: date.now(), coords: [ data.pagex, data.pagey ], origin: $(event.target) }, stop; //start.origin.trigger({'type' : 'ace_dragstart', 'start':(start || [-1,-1])}); var direction = false, dx = 0, dy = 0; function movehandler(event) { if (!start) { return; } var data = event.originalevent.touches ? event.originalevent.touches[ 0 ] : event; stop = { coords: [ data.pagex, data.pagey ] }; // prevent scrolling //if ( math.abs(start.coords[1] - stop.coords[1]) > 0 || math.abs(start.coords[0] - stop.coords[01]) > 0 ) { //event.preventdefault(); //} if (start && stop) { dx = 0; dy = 0; direction = ( math.abs(dy = start.coords[ 1 ] - stop.coords[ 1 ]) > min_threshold && math.abs(dx = start.coords[ 0 ] - stop.coords[ 0 ]) <= math.abs(dy) ) ? (dy > 0 ? 'up' : 'down') : ( math.abs(dx = start.coords[ 0 ] - stop.coords[ 0 ]) > min_threshold && math.abs( dy ) <= math.abs(dx) ) ? (dx > 0 ? 'left' : 'right') : false; if( direction !== false ) { var retval = {cancel: false} start.origin.trigger({ 'type': 'ace_drag', //'start': start.coords, //'stop': stop.coords, 'direction': direction, 'dx': dx, 'dy': dy, 'retval': retval }) // prevent document scrolling unless retval.cancel == true if( retval.cancel == false ) event.preventdefault(); } } start.coords[0] = stop.coords[0]; start.coords[1] = stop.coords[1]; } $this .on(touchmoveevent, movehandler) .one(touchstopevent, function(event) { $this.off(touchmoveevent, movehandler); //start.origin.trigger({'type' : 'ace_dragend', 'stop':(stop || [-1,-1])}); start = stop = undefined; }); }); } } })(window.jquery);