MDL-62319 assignfeedback_editpdf: Disable touch scrolling

Assignment editpdf canvas provides it's own scroll tool and the native browser one breaks
the rest of the tools for the canvas. Turn it off.
This commit is contained in:
Damyon Wiese
2018-10-11 13:33:14 +08:00
parent edbc4b5816
commit ffee9dcc59
5 changed files with 83 additions and 140 deletions
+1
View File
@@ -398,6 +398,7 @@ ul.assignfeedback_editpdf_menu {
position: relative;
margin-bottom: 1em;
top: 0;
max-height: 312px;
}
.assignfeedback_editpdf_widget .pageheader {
@@ -3500,14 +3500,6 @@ EDITOR.prototype = {
*/
collapsecomments: true,
/**
* Check if passive option is supported
* @property isPassiveSupported
* @type Boolean
* @public
*/
isPassiveSupported : false,
/**
* Called during the initialisation process of the object.
* @method initializer
@@ -4035,8 +4027,7 @@ EDITOR.prototype = {
if (this.get('readonly')) {
return;
}
// Check if passive option is supported for event listener
this.check_passive_supported();
this.disable_touch_scroll();
// Setup the tool buttons.
Y.each(TOOLSELECTOR, function(selector, tool) {
@@ -4132,15 +4123,6 @@ EDITOR.prototype = {
this.lastannotationtool = tool;
}
var useragent = navigator.userAgent;
if (useragent.includes("Safari")) {
if (tool === "drag") {
this.enable_touch_scroll();
} else {
this.disable_touch_scroll();
}
}
this.refresh_button_state();
},
@@ -4688,51 +4670,49 @@ EDITOR.prototype = {
},
/**
* Check if Passive option is support
* Test the browser support for options objects on event listeners.
* @return Boolean
*/
check_passive_supported : function() {
event_listener_options_supported: function() {
var passivesupported = false,
options,
testeventname = "testpassiveeventoptions";
// Options support testing example from:
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
try {
var options = Object.defineProperty && Object.defineProperty({}, 'passive', {
options = Object.defineProperty({}, "passive", {
get: function() {
this.isPassiveSupported = true;
}.bind(this)
passivesupported = true;
}
});
document.addEventListener('touchmove', options, options);
document.removeEventListener('touchmove', options, options);
} catch (err) {
this.isPassiveSupported = false;
// We use an event name that is not likely to conflict with any real event.
document.addEventListener(testeventname, options, options);
// We remove the event listener as we have tested the options already.
document.removeEventListener(testeventname, options, options);
} catch(err) {
// It's already false.
passivesupported = false;
}
return passivesupported;
},
/**
* Disable Touch Move scrolling
*/
disable_touch_scroll : function() {
var drawingregion = this.get_dialogue_element(SELECTOR.DRAWINGREGION);
drawingregion.setStyle('overflow', 'hidden');
if (this.isPassiveSupported) {
disable_touch_scroll: function() {
if (this.event_listener_options_supported()) {
document.addEventListener('touchmove', this.stop_touch_scroll, {passive: false});
}
},
/**
* Enable Touch Move scrolling
*/
enable_touch_scroll : function() {
var drawingregion = this.get_dialogue_element(SELECTOR.DRAWINGREGION);
drawingregion.setStyle('overflow', 'auto');
if (this.isPassiveSupported) {
document.removeEventListener('touchmove', this.stop_touch_scroll, {passive: false});
}
},
/**
* Stop Touch Scrolling
* @param {Object} e
*/
stop_touch_scroll : function(e) {
stop_touch_scroll: function(e) {
e.stopPropagation();
e.preventDefault();
}
@@ -4803,6 +4783,7 @@ M.assignfeedback_editpdf.editor.init = M.assignfeedback_editpdf.editor.init || f
return M.assignfeedback_editpdf.instance;
};
}, '@VERSION@', {
"requires": [
"base",
File diff suppressed because one or more lines are too long
@@ -3500,14 +3500,6 @@ EDITOR.prototype = {
*/
collapsecomments: true,
/**
* Check if passive option is supported
* @property isPassiveSupported
* @type Boolean
* @public
*/
isPassiveSupported : false,
/**
* Called during the initialisation process of the object.
* @method initializer
@@ -4035,8 +4027,7 @@ EDITOR.prototype = {
if (this.get('readonly')) {
return;
}
// Check if passive option is supported for event listener
this.check_passive_supported();
this.disable_touch_scroll();
// Setup the tool buttons.
Y.each(TOOLSELECTOR, function(selector, tool) {
@@ -4132,15 +4123,6 @@ EDITOR.prototype = {
this.lastannotationtool = tool;
}
var useragent = navigator.userAgent;
if (useragent.includes("Safari")) {
if (tool === "drag") {
this.enable_touch_scroll();
} else {
this.disable_touch_scroll();
}
}
this.refresh_button_state();
},
@@ -4688,51 +4670,49 @@ EDITOR.prototype = {
},
/**
* Check if Passive option is support
* Test the browser support for options objects on event listeners.
* @return Boolean
*/
check_passive_supported : function() {
event_listener_options_supported: function() {
var passivesupported = false,
options,
testeventname = "testpassiveeventoptions";
// Options support testing example from:
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
try {
var options = Object.defineProperty && Object.defineProperty({}, 'passive', {
options = Object.defineProperty({}, "passive", {
get: function() {
this.isPassiveSupported = true;
}.bind(this)
passivesupported = true;
}
});
document.addEventListener('touchmove', options, options);
document.removeEventListener('touchmove', options, options);
} catch (err) {
this.isPassiveSupported = false;
// We use an event name that is not likely to conflict with any real event.
document.addEventListener(testeventname, options, options);
// We remove the event listener as we have tested the options already.
document.removeEventListener(testeventname, options, options);
} catch(err) {
// It's already false.
passivesupported = false;
}
return passivesupported;
},
/**
* Disable Touch Move scrolling
*/
disable_touch_scroll : function() {
var drawingregion = this.get_dialogue_element(SELECTOR.DRAWINGREGION);
drawingregion.setStyle('overflow', 'hidden');
if (this.isPassiveSupported) {
disable_touch_scroll: function() {
if (this.event_listener_options_supported()) {
document.addEventListener('touchmove', this.stop_touch_scroll, {passive: false});
}
},
/**
* Enable Touch Move scrolling
*/
enable_touch_scroll : function() {
var drawingregion = this.get_dialogue_element(SELECTOR.DRAWINGREGION);
drawingregion.setStyle('overflow', 'auto');
if (this.isPassiveSupported) {
document.removeEventListener('touchmove', this.stop_touch_scroll, {passive: false});
}
},
/**
* Stop Touch Scrolling
* @param {Object} e
*/
stop_touch_scroll : function(e) {
stop_touch_scroll: function(e) {
e.stopPropagation();
e.preventDefault();
}
@@ -4803,6 +4783,7 @@ M.assignfeedback_editpdf.editor.init = M.assignfeedback_editpdf.editor.init || f
return M.assignfeedback_editpdf.instance;
};
}, '@VERSION@', {
"requires": [
"base",
+26 -46
View File
@@ -227,14 +227,6 @@ EDITOR.prototype = {
*/
collapsecomments: true,
/**
* Check if passive option is supported
* @property isPassiveSupported
* @type Boolean
* @public
*/
isPassiveSupported : false,
/**
* Called during the initialisation process of the object.
* @method initializer
@@ -762,8 +754,7 @@ EDITOR.prototype = {
if (this.get('readonly')) {
return;
}
// Check if passive option is supported for event listener
this.check_passive_supported();
this.disable_touch_scroll();
// Setup the tool buttons.
Y.each(TOOLSELECTOR, function(selector, tool) {
@@ -859,15 +850,6 @@ EDITOR.prototype = {
this.lastannotationtool = tool;
}
var useragent = navigator.userAgent;
if (useragent.includes("Safari")) {
if (tool === "drag") {
this.enable_touch_scroll();
} else {
this.disable_touch_scroll();
}
}
this.refresh_button_state();
},
@@ -1415,51 +1397,49 @@ EDITOR.prototype = {
},
/**
* Check if Passive option is support
* Test the browser support for options objects on event listeners.
* @return Boolean
*/
check_passive_supported : function() {
event_listener_options_supported: function() {
var passivesupported = false,
options,
testeventname = "testpassiveeventoptions";
// Options support testing example from:
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
try {
var options = Object.defineProperty && Object.defineProperty({}, 'passive', {
options = Object.defineProperty({}, "passive", {
get: function() {
this.isPassiveSupported = true;
}.bind(this)
passivesupported = true;
}
});
document.addEventListener('touchmove', options, options);
document.removeEventListener('touchmove', options, options);
} catch (err) {
this.isPassiveSupported = false;
// We use an event name that is not likely to conflict with any real event.
document.addEventListener(testeventname, options, options);
// We remove the event listener as we have tested the options already.
document.removeEventListener(testeventname, options, options);
} catch(err) {
// It's already false.
passivesupported = false;
}
return passivesupported;
},
/**
* Disable Touch Move scrolling
*/
disable_touch_scroll : function() {
var drawingregion = this.get_dialogue_element(SELECTOR.DRAWINGREGION);
drawingregion.setStyle('overflow', 'hidden');
if (this.isPassiveSupported) {
disable_touch_scroll: function() {
if (this.event_listener_options_supported()) {
document.addEventListener('touchmove', this.stop_touch_scroll, {passive: false});
}
},
/**
* Enable Touch Move scrolling
*/
enable_touch_scroll : function() {
var drawingregion = this.get_dialogue_element(SELECTOR.DRAWINGREGION);
drawingregion.setStyle('overflow', 'auto');
if (this.isPassiveSupported) {
document.removeEventListener('touchmove', this.stop_touch_scroll, {passive: false});
}
},
/**
* Stop Touch Scrolling
* @param {Object} e
*/
stop_touch_scroll : function(e) {
stop_touch_scroll: function(e) {
e.stopPropagation();
e.preventDefault();
}
@@ -1528,4 +1508,4 @@ M.assignfeedback_editpdf.editor.init = M.assignfeedback_editpdf.editor.init || f
M.assignfeedback_editpdf.instance = new EDITOR(params);
return M.assignfeedback_editpdf.instance;
};
};