mirror of
https://github.com/moodle/moodle.git
synced 2025-07-23 15:22:05 +02:00
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:
23
lib/yui/dragdrop/dragdrop.js
vendored
23
lib/yui/dragdrop/dragdrop.js
vendored
@@ -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();
|
||||
},
|
||||
|
Reference in New Issue
Block a user