Skip to content

Commit

Permalink
MDL-71344 questions: Improve event handler for Drag n Drop family
Browse files Browse the repository at this point in the history
  • Loading branch information
HuongNV13 committed Oct 11, 2021
1 parent 0850628 commit 06858a5
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 13 deletions.
2 changes: 1 addition & 1 deletion question/type/ddimageortext/amd/build/question.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion question/type/ddimageortext/amd/build/question.min.js.map

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions question/type/ddimageortext/amd/src/question.js
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion question/type/ddmarker/amd/build/question.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion question/type/ddmarker/amd/build/question.min.js.map

Large diffs are not rendered by default.

20 changes: 17 additions & 3 deletions question/type/ddmarker/amd/src/question.js
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion question/type/ddwtos/amd/build/ddwtos.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion question/type/ddwtos/amd/build/ddwtos.min.js.map

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions question/type/ddwtos/amd/src/ddwtos.js
Expand Up @@ -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.
*/
Expand All @@ -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',
Expand Down

0 comments on commit 06858a5

Please sign in to comment.