MDL-65539 course: Keyboad drag and drop should not break page

Before this change keyboard drag and drop of sections would alter
the structure of the page.

This occured because in this case the dragnode was the original node
This commit is contained in:
Neill Magill
2020-04-03 08:39:30 +01:00
parent 1c45c9200a
commit ffe5f336d3
5 changed files with 50 additions and 11 deletions
@@ -147,6 +147,14 @@ Y.extend(DRAGSECTION, M.core.dragdrop, {
drag_start: function(e) {
// Get our drag object
var drag = e.target;
// This is the node that the user started to drag.
var node = drag.get('node');
// This is the container node that will follow the mouse around,
// or during a keyboard drag and drop the original node.
var dragnode = drag.get('dragNode');
if (node === dragnode) {
return;
}
// Creat a dummy structure of the outer elemnents for clean styles application
var containernode = Y.Node.create('<' + M.course.format.get_containernode() +
'></' + M.course.format.get_containernode() + '>');
@@ -155,10 +163,10 @@ Y.extend(DRAGSECTION, M.core.dragdrop, {
'></' + M.course.format.get_sectionwrappernode() + '>');
sectionnode.addClass(M.course.format.get_sectionwrapperclass());
sectionnode.setStyle('margin', 0);
sectionnode.setContent(drag.get('node').get('innerHTML'));
sectionnode.setContent(node.get('innerHTML'));
containernode.appendChild(sectionnode);
drag.get('dragNode').setContent(containernode);
drag.get('dragNode').addClass(CSS.COURSECONTENT);
dragnode.setContent(containernode);
dragnode.addClass(CSS.COURSECONTENT);
},
drag_dropmiss: function(e) {
@@ -431,6 +439,11 @@ Y.extend(DRAGRESOURCE, M.core.dragdrop, {
drag_start: function(e) {
// Get our drag object
var drag = e.target;
if (drag.get('dragNode') === drag.get('node')) {
// We do not want to modify the contents of the real node.
// They will be the same during a keyboard drag and drop.
return;
}
drag.get('dragNode').setContent(drag.get('node').get('innerHTML'));
drag.get('dragNode').all('img.iconsmall').setStyle('vertical-align', 'baseline');
},
File diff suppressed because one or more lines are too long
@@ -147,6 +147,14 @@ Y.extend(DRAGSECTION, M.core.dragdrop, {
drag_start: function(e) {
// Get our drag object
var drag = e.target;
// This is the node that the user started to drag.
var node = drag.get('node');
// This is the container node that will follow the mouse around,
// or during a keyboard drag and drop the original node.
var dragnode = drag.get('dragNode');
if (node === dragnode) {
return;
}
// Creat a dummy structure of the outer elemnents for clean styles application
var containernode = Y.Node.create('<' + M.course.format.get_containernode() +
'></' + M.course.format.get_containernode() + '>');
@@ -155,10 +163,10 @@ Y.extend(DRAGSECTION, M.core.dragdrop, {
'></' + M.course.format.get_sectionwrappernode() + '>');
sectionnode.addClass(M.course.format.get_sectionwrapperclass());
sectionnode.setStyle('margin', 0);
sectionnode.setContent(drag.get('node').get('innerHTML'));
sectionnode.setContent(node.get('innerHTML'));
containernode.appendChild(sectionnode);
drag.get('dragNode').setContent(containernode);
drag.get('dragNode').addClass(CSS.COURSECONTENT);
dragnode.setContent(containernode);
dragnode.addClass(CSS.COURSECONTENT);
},
drag_dropmiss: function(e) {
@@ -427,6 +435,11 @@ Y.extend(DRAGRESOURCE, M.core.dragdrop, {
drag_start: function(e) {
// Get our drag object
var drag = e.target;
if (drag.get('dragNode') === drag.get('node')) {
// We do not want to modify the contents of the real node.
// They will be the same during a keyboard drag and drop.
return;
}
drag.get('dragNode').setContent(drag.get('node').get('innerHTML'));
drag.get('dragNode').all('img.iconsmall').setStyle('vertical-align', 'baseline');
},
+5
View File
@@ -116,6 +116,11 @@ Y.extend(DRAGRESOURCE, M.core.dragdrop, {
drag_start: function(e) {
// Get our drag object
var drag = e.target;
if (drag.get('dragNode') === drag.get('node')) {
// We do not want to modify the contents of the real node.
// They will be the same during a keyboard drag and drop.
return;
}
drag.get('dragNode').setContent(drag.get('node').get('innerHTML'));
drag.get('dragNode').all('img.iconsmall').setStyle('vertical-align', 'baseline');
},
+11 -3
View File
@@ -115,6 +115,14 @@ Y.extend(DRAGSECTION, M.core.dragdrop, {
drag_start: function(e) {
// Get our drag object
var drag = e.target;
// This is the node that the user started to drag.
var node = drag.get('node');
// This is the container node that will follow the mouse around,
// or during a keyboard drag and drop the original node.
var dragnode = drag.get('dragNode');
if (node === dragnode) {
return;
}
// Creat a dummy structure of the outer elemnents for clean styles application
var containernode = Y.Node.create('<' + M.course.format.get_containernode() +
'></' + M.course.format.get_containernode() + '>');
@@ -123,10 +131,10 @@ Y.extend(DRAGSECTION, M.core.dragdrop, {
'></' + M.course.format.get_sectionwrappernode() + '>');
sectionnode.addClass(M.course.format.get_sectionwrapperclass());
sectionnode.setStyle('margin', 0);
sectionnode.setContent(drag.get('node').get('innerHTML'));
sectionnode.setContent(node.get('innerHTML'));
containernode.appendChild(sectionnode);
drag.get('dragNode').setContent(containernode);
drag.get('dragNode').addClass(CSS.COURSECONTENT);
dragnode.setContent(containernode);
dragnode.addClass(CSS.COURSECONTENT);
},
drag_dropmiss: function(e) {