MDL-47494 ddmarker: Fix drag and drop on Android touch devices. #85111
The original idea for this fix came from Davo Smith.
This commit is contained in:
Vendored
+38
@@ -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;
|
||||
|
||||
+2
-2
File diff suppressed because one or more lines are too long
+38
@@ -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;
|
||||
|
||||
@@ -306,6 +306,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.
|
||||
@@ -332,6 +333,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,
|
||||
@@ -358,7 +392,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;
|
||||
|
||||
Reference in New Issue
Block a user