Skip to content

Commit

Permalink
Merge branch 'MDL-74447' of https://github.com/Chocolate-lightning/mo…
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjona committed Apr 14, 2022
2 parents 5c3563e + e9335eb commit d54fa7a
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 33 deletions.
47 changes: 40 additions & 7 deletions lib/yui/build/moodle-core-blocks/moodle-core-blocks-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,13 @@ MANAGER.prototype = {
*/
initializer: function() {
Y.log('Initialising drag and drop for blocks.', 'info');
var regionnames = this.get('regions'),
i = 0,
region,
regionname,
dragdelegation;
var regionnames = this.get('regions');
var i = 0;
var dragContainer;
var dragdelegation;
var region;
var regionContainer;
var regionname;

// Evil required by M.core.dragdrop.
this.groups = ['block'];
Expand All @@ -471,10 +473,11 @@ MANAGER.prototype = {

for (i in regionnames) {
regionname = regionnames[i];
regionContainer = Y.one('#block-region-' + regionname);
region = new BLOCKREGION({
manager: this,
region: regionname,
node: Y.one('#block-region-' + regionname)
node: regionContainer,
});
this.regionobjects[regionname] = region;

Expand All @@ -496,11 +499,24 @@ MANAGER.prototype = {
invalid: '.block-hider-hide, .block-hider-show, .moveto, .block_fake',
dragConfig: {groups: this.groups}
});

dragdelegation.dd.plug(Y.Plugin.DDProxy, {
// Don't move the node at the end of the drag
moveOnEnd: false
});
dragdelegation.dd.plug(Y.Plugin.DDWinScroll);

if (regionContainer === null) {
dragdelegation.dd.plug(Y.Plugin.DDWinScroll);
} else {
dragContainer = regionContainer.ancestor('.drag-container', true);
if (dragContainer) {
dragdelegation.dd.plug(Y.Plugin.DDNodeScroll, {
node: dragContainer,
});
} else {
dragdelegation.dd.plug(Y.Plugin.DDWinScroll);
}
}

// On the DD Manager start operation, we enable all block regions so that they can be drop targets. This
// must be done *before* drag:start but after dragging has been initialised.
Expand Down Expand Up @@ -600,6 +616,23 @@ MANAGER.prototype = {
}
},

dragOver: function(e) {
var nearestRegion = e.drop.get('node').ancestor('.drag-container', true);
if (nearestRegion) {
if (e.drag[Y.Plugin.DDNodeScroll]) {
if (e.drag[Y.Plugin.DDNodeScroll].get('node') === nearestRegion) {
// Do not bother resetting the region - it has not changed.
return;
} else {
e.drag.unplug(Y.Plugin.DDNodeScroll);
}
}
e.drag.plug(Y.Plugin.DDNodeScroll, {
node: nearestRegion,
});
}
},

/**
* Called by M.core.dragdrop.global_drop_over when something is dragged over a drop target.
* @method drop_over
Expand Down
4 changes: 2 additions & 2 deletions lib/yui/build/moodle-core-blocks/moodle-core-blocks-min.js

Large diffs are not rendered by default.

47 changes: 40 additions & 7 deletions lib/yui/build/moodle-core-blocks/moodle-core-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,13 @@ MANAGER.prototype = {
* @method initializer
*/
initializer: function() {
var regionnames = this.get('regions'),
i = 0,
region,
regionname,
dragdelegation;
var regionnames = this.get('regions');
var i = 0;
var dragContainer;
var dragdelegation;
var region;
var regionContainer;
var regionname;

// Evil required by M.core.dragdrop.
this.groups = ['block'];
Expand All @@ -467,10 +469,11 @@ MANAGER.prototype = {

for (i in regionnames) {
regionname = regionnames[i];
regionContainer = Y.one('#block-region-' + regionname);
region = new BLOCKREGION({
manager: this,
region: regionname,
node: Y.one('#block-region-' + regionname)
node: regionContainer,
});
this.regionobjects[regionname] = region;

Expand All @@ -492,11 +495,24 @@ MANAGER.prototype = {
invalid: '.block-hider-hide, .block-hider-show, .moveto, .block_fake',
dragConfig: {groups: this.groups}
});

dragdelegation.dd.plug(Y.Plugin.DDProxy, {
// Don't move the node at the end of the drag
moveOnEnd: false
});
dragdelegation.dd.plug(Y.Plugin.DDWinScroll);

if (regionContainer === null) {
dragdelegation.dd.plug(Y.Plugin.DDWinScroll);
} else {
dragContainer = regionContainer.ancestor('.drag-container', true);
if (dragContainer) {
dragdelegation.dd.plug(Y.Plugin.DDNodeScroll, {
node: dragContainer,
});
} else {
dragdelegation.dd.plug(Y.Plugin.DDWinScroll);
}
}

// On the DD Manager start operation, we enable all block regions so that they can be drop targets. This
// must be done *before* drag:start but after dragging has been initialised.
Expand Down Expand Up @@ -595,6 +611,23 @@ MANAGER.prototype = {
}
},

dragOver: function(e) {
var nearestRegion = e.drop.get('node').ancestor('.drag-container', true);
if (nearestRegion) {
if (e.drag[Y.Plugin.DDNodeScroll]) {
if (e.drag[Y.Plugin.DDNodeScroll].get('node') === nearestRegion) {
// Do not bother resetting the region - it has not changed.
return;
} else {
e.drag.unplug(Y.Plugin.DDNodeScroll);
}
}
e.drag.plug(Y.Plugin.DDNodeScroll, {
node: nearestRegion,
});
}
},

/**
* Called by M.core.dragdrop.global_drop_over when something is dragged over a drop target.
* @method drop_over
Expand Down
24 changes: 22 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 @@ -131,6 +131,9 @@ Y.extend(DRAGDROP, Y.Base, {
// Listen for all drag:start events.
this.listeners.push(Y.DD.DDM.on('drag:start', this.global_drag_start, this));

// Listen for all drag:over events.
this.listeners.push(Y.DD.DDM.on('drag:over', this.globalDragOver, this));

// Listen for all drag:end events.
this.listeners.push(Y.DD.DDM.on('drag:end', this.global_drag_end, this));

Expand Down Expand Up @@ -226,8 +229,8 @@ Y.extend(DRAGDROP, Y.Base, {
return ret;
},
/*
* Drag-dropping related functions
*/
* Drag-dropping related functions
*/
global_drag_start: function(e) {
// Get our drag object
var drag = e.target;
Expand All @@ -248,6 +251,15 @@ Y.extend(DRAGDROP, Y.Base, {
this.drag_start(e);
},

/**
* Drag-dropping related functions
*
* @param {EventFacade} e
*/
globalDragOver: function(e) {
this.dragOver(e);
},

global_drag_end: function(e) {
var drag = e.target;
// Check that drag object belongs to correct group
Expand Down Expand Up @@ -689,6 +701,14 @@ Y.extend(DRAGDROP, Y.Base, {
*/
drag_start: function() {},

/**
* Callback to use for the drag:over event.
*
* @method dragOver
* @param {EventFacade} e
*/
dragOver: function() {},

/**
* Callback to use when dragging ends.
*
Expand Down
Loading

0 comments on commit d54fa7a

Please sign in to comment.