Permalink
Browse files

MDL-47494 ddmarker: Fix drag and drop on Android touch devices. #85111

The original idea for this fix came from Davo Smith.
  • Loading branch information...
mkassaei authored and timhunt committed Jun 16, 2015
1 parent 16f1bce commit e76deaac51a97eb021cfba49ac742ec5716ffa2e
@@ -308,6 +308,7 @@ var DDMARKER_QUESTION = function() {
* This is the code for question rendering.
*/
Y.extend(DDMARKER_QUESTION, M.qtype_ddmarker.dd_base_class, {
touchscrolldisable: null,
pendingid: '',
initializer : function() {
this.pendingid = 'qtype_ddmarker-' + Math.random().toString(36).slice(2); // Random string.
@@ -334,6 +335,39 @@ Y.extend(DDMARKER_QUESTION, M.qtype_ddmarker.dd_base_class, {
}
return drag;
},
/**
* prevent_touchmove_from_scrolling allows users of touch screen devices to
* use drag and drop and normal scrolling at the same time. I.e.when
* touching and dragging a draggable item, the screen does not scroll, but
* you can scroll by touching other area of the screen apart from the
* draggable items.
*/
prevent_touchmove_from_scrolling : function(drag) {
var touchstart = (Y.UA.ie) ? 'MSPointerStart' : 'touchstart';
var touchend = (Y.UA.ie) ? 'MSPointerEnd' : 'touchend';
var touchmove = (Y.UA.ie) ? 'MSPointerMove' : 'touchmove';
// Disable scrolling when touching the draggable items.
drag.on(touchstart, function() {
if (this.touchscrolldisable) {
return; // Already disabled.
}
this.touchscrolldisable = Y.one('body').on(touchmove, function(e) {
e = e || window.event;
e.preventDefault();
});
}, this);
// Allow scrolling after releasing the draggable items.
drag.on(touchend, function() {
if (this.touchscrolldisable) {
this.touchscrolldisable.detach();
this.touchscrolldisable = null;
}
}, this);
},
draggable : function (drag) {
var dd = new Y.DD.Drag({
node: drag,
@@ -360,7 +394,11 @@ Y.extend(DDMARKER_QUESTION, M.qtype_ddmarker.dd_base_class, {
//--- keyboard accessibility
drag.set('tabIndex', 0);
drag.on('dragchange', this.drop_zone_key_press, this);
// Prevent scrolling whilst dragging on Adroid devices.
this.prevent_touchmove_from_scrolling(drag);
},
save_all_xy_for_choice: function (choiceno, dropped) {
var coords = [];
var bgimgxy;
Oops, something went wrong.

0 comments on commit e76deaa

Please sign in to comment.