MDL-70580 core: Tree nodes should check if they were clicked directly
authorAndrew Nicols <andrew@nicols.co.uk>
Mon, 11 Jan 2021 05:33:22 +0000 (13:33 +0800)
committerPaul Holden <paulh@moodle.com>
Mon, 11 Jan 2021 23:43:28 +0000 (23:43 +0000)
lib/amd/build/tree.min.js
lib/amd/build/tree.min.js.map
lib/amd/src/tree.js

index d92786b..ea1b92d 100644 (file)
Binary files a/lib/amd/build/tree.min.js and b/lib/amd/build/tree.min.js differ
index 3eed2c1..a78d746 100644 (file)
Binary files a/lib/amd/build/tree.min.js.map and b/lib/amd/build/tree.min.js.map differ
index 4ba8615..1a97cac 100644 (file)
@@ -349,12 +349,12 @@ define(['jquery'], function($) {
      * Handle a key down event - ie navigate the tree.
      *
      * @method handleKeyDown
      * Handle a key down event - ie navigate the tree.
      *
      * @method handleKeyDown
-     * @param {Object} item is the jquery id of the parent item of the group.
      * @param {Event} e The event.
      */
      // This function should be simplified. In the meantime..
      // eslint-disable-next-line complexity
      * @param {Event} e The event.
      */
      // This function should be simplified. In the meantime..
      // eslint-disable-next-line complexity
-    Tree.prototype.handleKeyDown = function(item, e) {
+    Tree.prototype.handleKeyDown = function(e) {
+        var item = $(e.target);
         var currentIndex = this.getVisibleItems().index(item);
 
         if ((e.altKey || e.ctrlKey || e.metaKey) || (e.shiftKey && e.keyCode != this.keys.tab)) {
         var currentIndex = this.getVisibleItems().index(item);
 
         if ((e.altKey || e.ctrlKey || e.metaKey) || (e.shiftKey && e.keyCode != this.keys.tab)) {
@@ -483,16 +483,20 @@ define(['jquery'], function($) {
      * Handle a click (select).
      *
      * @method handleClick
      * Handle a click (select).
      *
      * @method handleClick
-     * @param {Object} item The jquery id of the parent item of the group.
      * @param {Event} e The event.
      */
      * @param {Event} e The event.
      */
-    Tree.prototype.handleClick = function(item, e) {
-
+    Tree.prototype.handleClick = function(e) {
         if (e.altKey || e.ctrlKey || e.shiftKey || e.metaKey) {
             // Do nothing.
             return;
         }
 
         if (e.altKey || e.ctrlKey || e.shiftKey || e.metaKey) {
             // Do nothing.
             return;
         }
 
+        var item = $(e.target);
+
+        if (e.target !== e.currentTarget) {
+            return;
+        }
+
         // Update the active item.
         item.focus();
 
         // Update the active item.
         item.focus();
 
@@ -506,12 +510,10 @@ define(['jquery'], function($) {
      * Handle a focus event.
      *
      * @method handleFocus
      * Handle a focus event.
      *
      * @method handleFocus
-     * @param {Object} item The jquery id of the parent item of the group.
      * @param {Event} e The event.
      */
      * @param {Event} e The event.
      */
-    Tree.prototype.handleFocus = function(item) {
-
-        this.setActiveItem(item);
+    Tree.prototype.handleFocus = function(e) {
+        this.setActiveItem($(e.target));
     };
 
     /**
     };
 
     /**
@@ -520,20 +522,12 @@ define(['jquery'], function($) {
      * @method bindEventHandlers
      */
     Tree.prototype.bindEventHandlers = function() {
      * @method bindEventHandlers
      */
     Tree.prototype.bindEventHandlers = function() {
-        var thisObj = this;
-
         // Bind event handlers to the tree items. Use event delegates to allow
         // for dynamically loaded parts of the tree.
         this.treeRoot.on({
         // Bind event handlers to the tree items. Use event delegates to allow
         // for dynamically loaded parts of the tree.
         this.treeRoot.on({
-            click: function(e) {
-              return thisObj.handleClick($(this), e);
-            },
-            keydown: function(e) {
-              return thisObj.handleKeyDown($(this), e);
-            },
-            focus: function() {
-              return thisObj.handleFocus($(this));
-            },
+            click: this.handleClick.bind(this),
+            keydown: this.handleKeyDown.bind(this),
+            focus: this.handleFocus.bind(this),
         }, SELECTORS.ITEM);
     };
 
         }, SELECTORS.ITEM);
     };