Skip to content

Commit

Permalink
MDL-62319 assignfeedback_editpdf: Disable touch scrolling
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Damyon Wiese committed Oct 11, 2018
1 parent edbc4b5 commit ffee9dc
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 140 deletions.
1 change: 1 addition & 0 deletions mod/assign/feedback/editpdf/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ ul.assignfeedback_editpdf_menu {
position: relative;
margin-bottom: 1em;
top: 0;
max-height: 312px;
}

.assignfeedback_editpdf_widget .pageheader {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
},

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -4803,6 +4783,7 @@ M.assignfeedback_editpdf.editor.init = M.assignfeedback_editpdf.editor.init || f
return M.assignfeedback_editpdf.instance;
};


}, '@VERSION@', {
"requires": [
"base",
Expand Down
Loading

0 comments on commit ffee9dc

Please sign in to comment.