From 313e58519cba5485dd8f3f3f6ccc41fcb366a172 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Fri, 2 Aug 2013 16:34:24 +0800 Subject: [PATCH] MDL-36002 dragdrop: focus fix and exception catching This sets the focus correctly after a cancel or drop event. It also catches exceptions from the lock/unlock functions. --- lib/yui/dragdrop/dragdrop.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/yui/dragdrop/dragdrop.js b/lib/yui/dragdrop/dragdrop.js index 4e9e7d18fd9..3fdec8e20cf 100644 --- a/lib/yui/dragdrop/dragdrop.js +++ b/lib/yui/dragdrop/dragdrop.js @@ -66,12 +66,20 @@ YUI.add('moodle-core-dragdrop', function(Y) { lock_drag_handle: function(drag, classname) { // Disable dragging - drag.removeHandle('.'+classname); + try { + drag.removeHandle('.'+classname); + } catch (e) { + // Throws exceptions if the drag is not started with the mouse. + } }, unlock_drag_handle: function(drag, classname) { // Enable dragging - drag.addHandle('.'+classname); + try { + drag.addHandle('.'+classname); + } catch (e) { + // Throws exceptions if the drag is not started with the mouse. + } }, ajax_failure: function(response) { @@ -234,9 +242,11 @@ YUI.add('moodle-core-dragdrop', function(Y) { * @method global_start_keyboard_drag * @param {Event} e The keydown / click event on the grab handle. * @param {Node} dragcontainer The resolved draggable node (an ancestor of the drag handle). + * @param {Node} draghandle The node that triggered this action. */ - global_start_keyboard_drag : function(e, dragcontainer) { + global_start_keyboard_drag : function(e, draghandle, dragcontainer) { M.core.dragdrop.keydragcontainer = dragcontainer; + M.core.dragdrop.keydraghandle = draghandle; // Indicate to a screenreader the node that is selected for drag and drop. dragcontainer.setAttribute('aria-grabbed', 'true'); @@ -341,7 +351,8 @@ YUI.add('moodle-core-dragdrop', function(Y) { }); this.global_drop_over(e); - dragcontainer.focus(); + this.global_drop_hit(e); + M.core.dragdrop.keydraghandle.focus(); }, /** @@ -352,7 +363,7 @@ YUI.add('moodle-core-dragdrop', function(Y) { global_cancel_keyboard_drag : function() { if (M.core.dragdrop.keydragcontainer) { M.core.dragdrop.keydragcontainer.setAttribute('aria-grabbed', 'false'); - M.core.dragdrop.keydragcontainer.focus(); + M.core.dragdrop.keydraghandle.focus(); M.core.dragdrop.keydragcontainer = null; } }, @@ -403,7 +414,7 @@ YUI.add('moodle-core-dragdrop', function(Y) { // Valid event - start the keyboard drag. dragcontainer = draghandle.ancestor('.yui3-dd-drop'); - this.global_start_keyboard_drag(e, dragcontainer); + this.global_start_keyboard_drag(e, draghandle, dragcontainer); e.preventDefault(); }, -- 2.43.0