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.
This commit is contained in:
Damyon Wiese
2013-08-02 16:34:24 +08:00
parent 7c271b918e
commit 313e58519c

View File

@@ -66,12 +66,20 @@ YUI.add('moodle-core-dragdrop', function(Y) {
lock_drag_handle: function(drag, classname) { lock_drag_handle: function(drag, classname) {
// Disable dragging // 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) { unlock_drag_handle: function(drag, classname) {
// Enable dragging // 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) { ajax_failure: function(response) {
@@ -234,9 +242,11 @@ YUI.add('moodle-core-dragdrop', function(Y) {
* @method global_start_keyboard_drag * @method global_start_keyboard_drag
* @param {Event} e The keydown / click event on the grab handle. * @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} 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.keydragcontainer = dragcontainer;
M.core.dragdrop.keydraghandle = draghandle;
// Indicate to a screenreader the node that is selected for drag and drop. // Indicate to a screenreader the node that is selected for drag and drop.
dragcontainer.setAttribute('aria-grabbed', 'true'); dragcontainer.setAttribute('aria-grabbed', 'true');
@@ -341,7 +351,8 @@ YUI.add('moodle-core-dragdrop', function(Y) {
}); });
this.global_drop_over(e); 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() { global_cancel_keyboard_drag : function() {
if (M.core.dragdrop.keydragcontainer) { if (M.core.dragdrop.keydragcontainer) {
M.core.dragdrop.keydragcontainer.setAttribute('aria-grabbed', 'false'); M.core.dragdrop.keydragcontainer.setAttribute('aria-grabbed', 'false');
M.core.dragdrop.keydragcontainer.focus(); M.core.dragdrop.keydraghandle.focus();
M.core.dragdrop.keydragcontainer = null; M.core.dragdrop.keydragcontainer = null;
} }
}, },
@@ -403,7 +414,7 @@ YUI.add('moodle-core-dragdrop', function(Y) {
// Valid event - start the keyboard drag. // Valid event - start the keyboard drag.
dragcontainer = draghandle.ancestor('.yui3-dd-drop'); dragcontainer = draghandle.ancestor('.yui3-dd-drop');
this.global_start_keyboard_drag(e, dragcontainer); this.global_start_keyboard_drag(e, draghandle, dragcontainer);
e.preventDefault(); e.preventDefault();
}, },