Permalink
Browse files

MDL-32752: Drag-drop: Follow the ghost note if the drop target is mis…

…sed.

Simulate drop_hit and substitute target of where ghost node was dropped last
time.
  • Loading branch information...
1 parent 4f7f2a8 commit 243e9bf9847f830826dd07cdaa9a0968b892fa8b Ruslan Kabalin committed May 14, 2012
Showing with 40 additions and 0 deletions.
  1. +14 −0 course/yui/dragdrop/dragdrop.js
  2. +7 −0 lib/yui/blocks/blocks.js
  3. +19 −0 lib/yui/dragdrop/dragdrop.js
@@ -120,6 +120,13 @@ YUI.add('moodle-course-dragdrop', function(Y) {
drag.get('dragNode').addClass(CSS.COURSECONTENT);
},
+ drag_dropmiss : function(e) {
+ // Missed the target, but we assume the user intended to drop it
+ // on the last last ghost node location, e.drag and e.drop should be
+ // prepared by global_drag_dropmiss parent so simulate drop_hit(e).
+ this.drop_hit(e);
+ },
+
drop_hit : function(e) {
var drag = e.drag;
// Get a reference to our drag node
@@ -311,6 +318,13 @@ YUI.add('moodle-course-dragdrop', function(Y) {
drag.get('dragNode').all('img.iconsmall').setStyle('vertical-align', 'baseline');
},
+ drag_dropmiss : function(e) {
+ // Missed the target, but we assume the user intended to drop it
+ // on the last last ghost node location, e.drag and e.drop should be
+ // prepared by global_drag_dropmiss parent so simulate drop_hit(e).
+ this.drop_hit(e);
+ },
+
drop_hit : function(e) {
var drag = e.drag;
// Get a reference to our drag node
View
@@ -167,6 +167,13 @@ YUI.add('moodle-core-blocks', function(Y) {
this.dragsourceregion = null;
},
+ drag_dropmiss : function(e) {
+ // Missed the target, but we assume the user intended to drop it
+ // on the last last ghost node location, e.drag and e.drop should be
+ // prepared by global_drag_dropmiss parent so simulate drop_hit(e).
+ this.drop_hit(e);
+ },
+
drop_hit : function(e) {
var drag = e.drag;
// Get a reference to our drag node
@@ -15,6 +15,7 @@ YUI.add('moodle-core-dragdrop', function(Y) {
samenodeclass : null,
parentnodeclass : null,
groups : [],
+ lastdroptarget : null,
initializer : function(params) {
// Listen for all drag:start events
Y.DD.DDM.on('drag:start', this.global_drag_start, this);
@@ -26,6 +27,8 @@ YUI.add('moodle-core-dragdrop', function(Y) {
Y.DD.DDM.on('drop:over', this.global_drop_over, this);
// Listen for all drop:hit events
Y.DD.DDM.on('drop:hit', this.global_drop_hit, this);
+ // Listen for all drop:miss events
+ Y.DD.DDM.on('drag:dropmiss', this.global_drag_dropmiss, this);
},
get_drag_handle: function(title, classname, iconclass) {
@@ -130,6 +133,8 @@ YUI.add('moodle-core-dragdrop', function(Y) {
//Get a reference to our drag and drop nodes
var drag = e.drag.get('node');
var drop = e.drop.get('node');
+ // Save last drop target for the case of missed target processing
+ this.lastdroptarget = e.drop;
//Are we dropping on the same node?
if (drop.hasClass(this.samenodeclass)) {
//Are we not going up?
@@ -149,6 +154,19 @@ YUI.add('moodle-core-dragdrop', function(Y) {
this.drop_over(e);
},
+ global_drag_dropmiss : function(e) {
+ // drag:dropmiss does not have e.drag and e.drop properties
+ // we substitute them for the ease of use. For e.drop we use,
+ // this.lastdroptarget (ghost node we use for indicating where to drop)
+ e.drag = e.target;
+ // Check that drop object belong to correct group
+ if (!e.drag.target.inGroup(this.groups)) {
+ return;
+ }
+ e.drop = this.lastdroptarget;
+ this.drag_dropmiss(e);
+ },
+
global_drop_hit : function(e) {
// Check that drop object belong to correct group
if (!e.drop.inGroup(this.groups)) {
@@ -163,6 +181,7 @@ YUI.add('moodle-core-dragdrop', function(Y) {
drag_start : function(e) {},
drag_end : function(e) {},
drag_drag : function(e) {},
+ drag_dropmiss : function(e) {},
drop_over : function(e) {},
drop_hit : function(e) {}
}, {

0 comments on commit 243e9bf

Please sign in to comment.