From 243e9bf9847f830826dd07cdaa9a0968b892fa8b Mon Sep 17 00:00:00 2001 From: Ruslan Kabalin Date: Mon, 14 May 2012 15:51:59 +0100 Subject: [PATCH] MDL-32752: Drag-drop: Follow the ghost note if the drop target is missed. Simulate drop_hit and substitute target of where ghost node was dropped last time. --- course/yui/dragdrop/dragdrop.js | 14 ++++++++++++++ lib/yui/blocks/blocks.js | 7 +++++++ lib/yui/dragdrop/dragdrop.js | 19 +++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/course/yui/dragdrop/dragdrop.js b/course/yui/dragdrop/dragdrop.js index c3ed979443b..2e604932bf4 100644 --- a/course/yui/dragdrop/dragdrop.js +++ b/course/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 diff --git a/lib/yui/blocks/blocks.js b/lib/yui/blocks/blocks.js index 35fc12e2cc0..8555f327f14 100644 --- a/lib/yui/blocks/blocks.js +++ b/lib/yui/blocks/blocks.js @@ -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 diff --git a/lib/yui/dragdrop/dragdrop.js b/lib/yui/dragdrop/dragdrop.js index 930f60042f3..49b1fcca9f3 100644 --- a/lib/yui/dragdrop/dragdrop.js +++ b/lib/yui/dragdrop/dragdrop.js @@ -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) {} }, {