Merge branch 'MDL-69930-310' of https://github.com/HuongNV13/moodle into MOODLE_310_S...
authorJun Pataleta <jun@moodle.com>
Tue, 10 Nov 2020 06:08:57 +0000 (14:08 +0800)
committerJun Pataleta <jun@moodle.com>
Tue, 10 Nov 2020 06:08:57 +0000 (14:08 +0800)
# Conflicts:
# question/type/ddimageortext/amd/build/question.min.js
# question/type/ddimageortext/amd/build/question.min.js.map
# question/type/ddimageortext/amd/src/question.js

question/type/ddimageortext/amd/build/question.min.js
question/type/ddimageortext/amd/build/question.min.js.map
question/type/ddimageortext/amd/src/question.js

index ddab8b6..7bebe76 100644 (file)
Binary files a/question/type/ddimageortext/amd/build/question.min.js and b/question/type/ddimageortext/amd/build/question.min.js differ
index e731d71..801f740 100644 (file)
Binary files a/question/type/ddimageortext/amd/build/question.min.js.map and b/question/type/ddimageortext/amd/build/question.min.js.map differ
index bdd8d17..c62e611 100644 (file)
@@ -377,7 +377,7 @@ define(['jquery', 'core/dragdrop', 'core/key_codes'], function($, dragDrop, keys
         });
         this.getRoot().find('.draghome.placed.group' + this.getGroup(drag)).not('.beingdragged').each(function(i, dropNode) {
             var drop = $(dropNode);
-            if (thisQ.isPointInDrop(pageX, pageY, drop) && !highlighted) {
+            if (thisQ.isPointInDrop(pageX, pageY, drop) && !highlighted && !thisQ.isDragSameAsDrop(drag, drop)) {
                 highlighted = true;
                 drop.addClass('valid-drag-over-drop');
             } else {
@@ -417,7 +417,7 @@ define(['jquery', 'core/dragdrop', 'core/key_codes'], function($, dragDrop, keys
             // Looking for drag that was dropped on a placed drag.
             root.find('.draghome.placed.group' + this.getGroup(drag)).not('.beingdragged').each(function(i, placedNode) {
                 var placedDrag = $(placedNode);
-                if (!thisQ.isPointInDrop(pageX, pageY, placedDrag)) {
+                if (!thisQ.isPointInDrop(pageX, pageY, placedDrag) || thisQ.isDragSameAsDrop(drag, placedDrag)) {
                     // Not this placed drag.
                     return true;
                 }
@@ -925,6 +925,17 @@ define(['jquery', 'core/dragdrop', 'core/key_codes'], function($, dragDrop, keys
         return zIndex;
     };
 
+    /**
+     * Check that the drag is drop to it's clone.
+     *
+     * @param {jQuery} drag The drag.
+     * @param {jQuery} drop The drop.
+     * @returns {boolean}
+     */
+    DragDropOntoImageQuestion.prototype.isDragSameAsDrop = function(drag, drop) {
+        return this.getChoice(drag) === this.getChoice(drop) && this.getGroup(drag) === this.getGroup(drop);
+    };
+
     /**
      * Singleton object that handles all the DragDropOntoImageQuestions
      * on the page, and deals with event dispatching.
@@ -1004,6 +1015,8 @@ define(['jquery', 'core/dragdrop', 'core/key_codes'], function($, dragDrop, keys
          * @param {jQuery} element Element to bind the event
          */
         addEventHandlersToDrag: function(element) {
+            // Unbind all the mousedown and touchstart events to prevent double binding.
+            element.unbind('mousedown touchstart');
             element.on('mousedown touchstart', questionManager.handleDragStart);
         },