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.
This commit is contained in:
Ruslan Kabalin 2012-05-14 15:51:59 +01:00
parent 4f7f2a8828
commit 243e9bf984
3 changed files with 40 additions and 0 deletions

View File

@ -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 File

@ -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

View File

@ -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) {}
}, {