MDL-40975 JavaScript: Make drag/drop respond to a single click as well as a drag

This commit is contained in:
Andrew Nicols
2013-11-06 11:40:51 +08:00
parent 81dc079654
commit a4400cefdb
+15 -7
View File
@@ -21,7 +21,7 @@ YUI.add('moodle-core-dragdrop', function(Y) {
parentnodeclass : null,
groups : [],
lastdroptarget : null,
initializer : function(params) {
initializer : function() {
// Listen for all drag:start events
Y.DD.DDM.on('drag:start', this.global_drag_start, this);
// Listen for all drag:end events
@@ -35,7 +35,8 @@ YUI.add('moodle-core-dragdrop', function(Y) {
// Listen for all drop:miss events
Y.DD.DDM.on('drag:dropmiss', this.global_drag_dropmiss, this);
Y.on('key', this.global_keydown, window, 'down:32,enter,esc', this);
Y.one(Y.config.doc.body).delegate('key', this.global_keydown, 'down:32, enter, esc', '.' + MOVEICON.cssclass, this);
Y.one(Y.config.doc.body).delegate('click', this.global_keydown, '.' + MOVEICON.cssclass , this);
},
get_drag_handle: function(title, classname, iconclass, large) {
@@ -437,11 +438,16 @@ YUI.add('moodle-core-dragdrop', function(Y) {
* @param {Event} e The keydown / click event on the drag handle.
*/
global_keydown : function(e) {
var draghandle = e.target,
var draghandle = e.target.ancestor('.' + MOVEICON.cssclass, true),
dragcontainer,
draggroups;
if (e.keyCode == 27 ) {
if (draghandle === null) {
// The element clicked did not have a a draghandle in it's lineage.
return;
}
if (e.keyCode === 27 ) {
// Escape to cancel from anywhere.
this.global_cancel_keyboard_drag();
e.preventDefault();
@@ -452,17 +458,19 @@ YUI.add('moodle-core-dragdrop', function(Y) {
if (!draghandle.hasClass(MOVEICON.cssclass)) {
return;
}
// Do nothing if not space or enter.
if (e.keyCode != 13 && e.keyCode != 32) {
if (e.keyCode !== 13 && e.keyCode !== 32 && e.type !== 'click') {
return;
}
// Check the drag groups to see if we are the handler for this node.
draggroups = e.target.getAttribute('data-draggroups').split(' ');
draggroups = draghandle.getAttribute('data-draggroups').split(' ');
var i, j, validgroup = false;
for (i = 0; i < draggroups.length; i++) {
for (j = 0; j < this.groups.length; j++) {
if (draggroups[i] == this.groups[j]) {
if (draggroups[i] === this.groups[j]) {
validgroup = true;
break;
}