mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-74447 core: Restrict block drag/drop to container
This commit is contained in:
parent
5423e5f443
commit
e9335eb448
@ -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'];
|
||||
@ -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;
|
||||
|
||||
@ -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.
|
||||
@ -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
|
||||
|
File diff suppressed because one or more lines are too long
@ -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'];
|
||||
@ -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;
|
||||
|
||||
@ -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.
|
||||
@ -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
|
||||
|
@ -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));
|
||||
|
||||
@ -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;
|
||||
@ -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
|
||||
@ -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.
|
||||
*
|
||||
|
File diff suppressed because one or more lines are too long
@ -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));
|
||||
|
||||
@ -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;
|
||||
@ -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
|
||||
@ -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.
|
||||
*
|
||||
|
47
lib/yui/src/blocks/js/manager.js
vendored
47
lib/yui/src/blocks/js/manager.js
vendored
@ -54,11 +54,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'];
|
||||
@ -78,10 +80,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;
|
||||
|
||||
@ -103,11 +106,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.
|
||||
@ -207,6 +223,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
|
||||
|
24
lib/yui/src/dragdrop/js/dragdrop.js
vendored
24
lib/yui/src/dragdrop/js/dragdrop.js
vendored
@ -129,6 +129,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));
|
||||
|
||||
@ -224,8 +227,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;
|
||||
@ -246,6 +249,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
|
||||
@ -687,6 +699,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.
|
||||
*
|
||||
|
@ -48,7 +48,7 @@
|
||||
{{#pix}} e/cancel, core {{/pix}}
|
||||
</button>
|
||||
</div>
|
||||
<div class="drawercontent" data-usertour="scroller">
|
||||
<div class="drawercontent drag-container" data-usertour="scroller">
|
||||
{{$drawercontent}}{{/drawercontent}}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -89,7 +89,7 @@
|
||||
{{$closebuttontext}}{{#str}}closeblockdrawer, core{{/str}}{{/closebuttontext}}
|
||||
{{/ theme_boost/drawer}}
|
||||
{{/hasblocks}}
|
||||
<div id="page" data-region="mainpage" data-usertour="scroller" class="drawers {{#courseindexopen}}show-drawer-left{{/courseindexopen}} {{#blockdraweropen}}show-drawer-right{{/blockdraweropen}}">
|
||||
<div id="page" data-region="mainpage" data-usertour="scroller" class="drawers {{#courseindexopen}}show-drawer-left{{/courseindexopen}} {{#blockdraweropen}}show-drawer-right{{/blockdraweropen}} drag-container">
|
||||
<div id="topofscroll" class="main-inner">
|
||||
<div class="drawer-toggles d-flex">
|
||||
{{#courseindex}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user