1
0
mirror of https://github.com/moodle/moodle.git synced 2025-04-14 04:52:36 +02:00

MDL-71344 questions: Improve event handler for Drag n Drop family

This commit is contained in:
Huong Nguyen 2021-08-12 16:15:58 +07:00
parent e746dc75af
commit b39f98243a
9 changed files with 55 additions and 13 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -947,6 +947,12 @@ define(['jquery', 'core/dragdrop', 'core/key_codes'], function($, dragDrop, keys
*/
eventHandlersInitialised: false,
/**
* {Object} ensures that the drag event handlers are only initialised once per question,
* indexed by containerId (id on the .que div).
*/
dragEventHandlersInitialised: {},
/**
* {boolean} is printing or not.
*/
@ -977,14 +983,22 @@ define(['jquery', 'core/dragdrop', 'core/key_codes'], function($, dragDrop, keys
questionManager.setupEventHandlers();
questionManager.eventHandlersInitialised = true;
}
if (!questionManager.dragEventHandlersInitialised.hasOwnProperty(containerId)) {
questionManager.dragEventHandlersInitialised[containerId] = true;
// We do not use the body event here to prevent the other event on Mobile device, such as scroll event.
var questionContainer = document.getElementById(containerId);
if (questionContainer.classList.contains('ddimageortext') &&
!questionContainer.classList.contains('qtype_ddimageortext-readonly')) {
// TODO: Convert all the jQuery selectors and events to native Javascript.
questionManager.addEventHandlersToDrag($(questionContainer).find('.draghome'));
}
}
},
/**
* Set up the event handlers that make this question type work. (Done once per page.)
*/
setupEventHandlers: function() {
// We do not use the body event here to prevent the other event on Mobile device, such as scroll event.
questionManager.addEventHandlersToDrag($('.que.ddimageortext:not(.qtype_ddimageortext-readonly) .draghome'));
$('body')
.on('keydown',
'.que.ddimageortext:not(.qtype_ddimageortext-readonly) .dropzones .dropzone',

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -682,6 +682,12 @@ define(['jquery', 'core/dragdrop', 'qtype_ddmarker/shapes', 'core/key_codes'], f
*/
eventHandlersInitialised: false,
/**
* {Object} ensures that the marker event handlers are only initialised once per question,
* indexed by containerId (id on the .que div).
*/
markerEventHandlersInitialised: {},
/**
* {boolean} is printing or not.
*/
@ -711,15 +717,23 @@ define(['jquery', 'core/dragdrop', 'qtype_ddmarker/shapes', 'core/key_codes'], f
questionManager.setupEventHandlers();
questionManager.eventHandlersInitialised = true;
}
if (!questionManager.markerEventHandlersInitialised.hasOwnProperty(containerId)) {
questionManager.markerEventHandlersInitialised[containerId] = true;
// We do not use the body event here to prevent the other event on Mobile device, such as scroll event.
var questionContainer = document.getElementById(containerId);
if (questionContainer.classList.contains('ddmarker') &&
!questionContainer.classList.contains('qtype_ddmarker-readonly')) {
// TODO: Convert all the jQuery selectors and events to native Javascript.
questionManager.addEventHandlersToMarker($(questionContainer).find('div.draghomes .marker'));
questionManager.addEventHandlersToMarker($(questionContainer).find('div.droparea .marker'));
}
}
},
/**
* Set up the event handlers that make this question type work. (Done once per page.)
*/
setupEventHandlers: function() {
// We do not use the body event here to prevent the other event on Mobile device, such as scroll event.
questionManager.addEventHandlersToMarker($('.que.ddmarker:not(.qtype_ddmarker-readonly) div.draghomes .marker'));
questionManager.addEventHandlersToMarker($('.que.ddmarker:not(.qtype_ddmarker-readonly) div.droparea .marker'));
$(window).on('resize', function() {
questionManager.handleWindowResize(false);
});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -734,6 +734,12 @@ define(['jquery', 'core/dragdrop', 'core/key_codes'], function($, dragDrop, keys
*/
eventHandlersInitialised: false,
/**
* {Object} ensures that the drag event handlers are only initialised once per question,
* indexed by containerId (id on the .que div).
*/
dragEventHandlersInitialised: {},
/**
* {boolean} is keyboard navigation or not.
*/
@ -756,14 +762,22 @@ define(['jquery', 'core/dragdrop', 'core/key_codes'], function($, dragDrop, keys
questionManager.setupEventHandlers();
questionManager.eventHandlersInitialised = true;
}
if (!questionManager.dragEventHandlersInitialised.hasOwnProperty(containerId)) {
questionManager.dragEventHandlersInitialised[containerId] = true;
// We do not use the body event here to prevent the other event on Mobile device, such as scroll event.
var questionContainer = document.getElementById(containerId);
if (questionContainer.classList.contains('ddwtos') &&
!questionContainer.classList.contains('qtype_ddwtos-readonly')) {
// TODO: Convert all the jQuery selectors and events to native Javascript.
questionManager.addEventHandlersToDrag($(questionContainer).find('span.draghome'));
}
}
},
/**
* Set up the event handlers that make this question type work. (Done once per page.)
*/
setupEventHandlers: function() {
// We do not use the body event here to prevent the other event on Mobile device, such as scroll event.
questionManager.addEventHandlersToDrag($('.que.ddwtos:not(.qtype_ddwtos-readonly) span.draghome'));
$('body')
.on('keydown',
'.que.ddwtos:not(.qtype_ddwtos-readonly) span.drop',