Skip to content

Commit

Permalink
MDL-43267 Javascript: Improve focus before and after drag/drop
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Feb 7, 2014
1 parent 02839a3 commit 8659df9
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
17 changes: 15 additions & 2 deletions lib/yui/build/moodle-core-dragdrop/moodle-core-dragdrop-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ Y.extend(DRAGDROP, Y.Base, {

unlock_drag_handle: function(drag, classname) {
drag.addHandle('.'+classname);
drag.get('activeHandle').focus();
},

ajax_failure: function(response) {
Expand Down Expand Up @@ -442,9 +443,18 @@ Y.extend(DRAGDROP, Y.Base, {
bodyContent: droplist,
draggable: true,
visible: true,
centered: true
center: true,
modal: true
});

M.core.dragdrop.dropui.after('visibleChange', function(e) {
// After the dialogue has been closed, we call the cancel function. This will
// ensure that tidying up happens (e.g. focusing on the start Node).
if (e.prevVal && !e.newVal) {
this.global_cancel_keyboard_drag();
}
}, this);

// Focus the first drop target.
if (droplist.one('a')) {
droplist.one('a').focus();
Expand Down Expand Up @@ -484,6 +494,9 @@ Y.extend(DRAGDROP, Y.Base, {
if (param === 'node' || param === 'dragNode' || param === 'dropNode') {
return this.node;
}
if (param === 'activeHandle') {
return this.node.one('.editing_move');
}
return null;
};

Expand Down Expand Up @@ -526,7 +539,6 @@ Y.extend(DRAGDROP, Y.Base, {
this.drag_start(dragevent);
this.global_drop_over(dropevent);
this.global_drop_hit(dropevent);
M.core.dragdrop.keydraghandle.focus();
},

/**
Expand All @@ -536,6 +548,7 @@ Y.extend(DRAGDROP, Y.Base, {
*/
global_cancel_keyboard_drag: function() {
if (M.core.dragdrop.keydragcontainer) {
// Focus on the node which was being dragged.
M.core.dragdrop.keydraghandle.focus();
M.core.dragdrop.keydragcontainer = null;
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions lib/yui/build/moodle-core-dragdrop/moodle-core-dragdrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ Y.extend(DRAGDROP, Y.Base, {

unlock_drag_handle: function(drag, classname) {
drag.addHandle('.'+classname);
drag.get('activeHandle').focus();
},

ajax_failure: function(response) {
Expand Down Expand Up @@ -442,9 +443,18 @@ Y.extend(DRAGDROP, Y.Base, {
bodyContent: droplist,
draggable: true,
visible: true,
centered: true
center: true,
modal: true
});

M.core.dragdrop.dropui.after('visibleChange', function(e) {
// After the dialogue has been closed, we call the cancel function. This will
// ensure that tidying up happens (e.g. focusing on the start Node).
if (e.prevVal && !e.newVal) {
this.global_cancel_keyboard_drag();
}
}, this);

// Focus the first drop target.
if (droplist.one('a')) {
droplist.one('a').focus();
Expand Down Expand Up @@ -484,6 +494,9 @@ Y.extend(DRAGDROP, Y.Base, {
if (param === 'node' || param === 'dragNode' || param === 'dropNode') {
return this.node;
}
if (param === 'activeHandle') {
return this.node.one('.editing_move');
}
return null;
};

Expand Down Expand Up @@ -526,7 +539,6 @@ Y.extend(DRAGDROP, Y.Base, {
this.drag_start(dragevent);
this.global_drop_over(dropevent);
this.global_drop_hit(dropevent);
M.core.dragdrop.keydraghandle.focus();
},

/**
Expand All @@ -536,6 +548,7 @@ Y.extend(DRAGDROP, Y.Base, {
*/
global_cancel_keyboard_drag: function() {
if (M.core.dragdrop.keydragcontainer) {
// Focus on the node which was being dragged.
M.core.dragdrop.keydraghandle.focus();
M.core.dragdrop.keydragcontainer = null;
}
Expand Down
17 changes: 15 additions & 2 deletions lib/yui/src/dragdrop/js/dragdrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ Y.extend(DRAGDROP, Y.Base, {

unlock_drag_handle: function(drag, classname) {
drag.addHandle('.'+classname);
drag.get('activeHandle').focus();
},

ajax_failure: function(response) {
Expand Down Expand Up @@ -440,9 +441,18 @@ Y.extend(DRAGDROP, Y.Base, {
bodyContent: droplist,
draggable: true,
visible: true,
centered: true
center: true,
modal: true
});

M.core.dragdrop.dropui.after('visibleChange', function(e) {
// After the dialogue has been closed, we call the cancel function. This will
// ensure that tidying up happens (e.g. focusing on the start Node).
if (e.prevVal && !e.newVal) {
this.global_cancel_keyboard_drag();
}
}, this);

// Focus the first drop target.
if (droplist.one('a')) {
droplist.one('a').focus();
Expand Down Expand Up @@ -482,6 +492,9 @@ Y.extend(DRAGDROP, Y.Base, {
if (param === 'node' || param === 'dragNode' || param === 'dropNode') {
return this.node;
}
if (param === 'activeHandle') {
return this.node.one('.editing_move');
}
return null;
};

Expand Down Expand Up @@ -524,7 +537,6 @@ Y.extend(DRAGDROP, Y.Base, {
this.drag_start(dragevent);
this.global_drop_over(dropevent);
this.global_drop_hit(dropevent);
M.core.dragdrop.keydraghandle.focus();
},

/**
Expand All @@ -534,6 +546,7 @@ Y.extend(DRAGDROP, Y.Base, {
*/
global_cancel_keyboard_drag: function() {
if (M.core.dragdrop.keydragcontainer) {
// Focus on the node which was being dragged.
M.core.dragdrop.keydraghandle.focus();
M.core.dragdrop.keydragcontainer = null;
}
Expand Down

0 comments on commit 8659df9

Please sign in to comment.