Don't allow items to be dragged out of the viewport

This commit is contained in:
Nariman Jelveh
2025-09-04 19:36:03 -07:00
parent 55c173c0b7
commit a68f0edc41
3 changed files with 26 additions and 3 deletions
+4
View File
@@ -1655,6 +1655,10 @@ async function UIDesktop(options) {
if(window.desktop_selectable_is_active)
return;
// if an item is being dragged, don't show the toolbar
if(window.an_item_is_being_dragged)
return;
if(window.is_fullpage_mode)
$('.window-app-iframe').css('pointer-events', 'none');
+20 -2
View File
@@ -279,8 +279,20 @@ function UIItem(options){
// reset longer hover timeout and last window dragged over
longer_hover_timeout = null;
last_window_dragged_over = null;
window.an_item_is_being_dragged = true;
$('.toolbar').css('pointer-events', 'none');
},
drag: function(event, ui) {
// Constrain item within desktop bounds
const minLeft = -50;
const maxLeft = window.desktop_width - 50;
const minTop = window.toolbar_height;
const maxTop = window.desktop_height + window.toolbar_height - 50;
// Apply constraints to ui.position
ui.position.top = Math.max(minTop, Math.min(maxTop, ui.position.top));
// Only show drag helpers if the item has been moved more than 5px
if( Math.abs(ui.originalPosition.top - ui.offset.top) > 5
||
@@ -301,9 +313,13 @@ function UIItem(options){
// Move other selected items
for(let i=0; i < item_count - 1; i++){
// Apply same constraints to cloned items with their offset
const cloneLeft = Math.max(minLeft, Math.min(maxLeft, ui.position.left + 3 * (i+1)));
const cloneTop = Math.max(minTop, Math.min(maxTop, ui.position.top + 3 * (i+1)));
$(other_selected_items[i]).css({
'left': ui.position.left + 3 * (i+1),
'top': ui.position.top + 3 * (i+1),
'left': cloneLeft,
'top': cloneTop,
'z-index': 999 - (i),
'opacity': 0.5 - i*0.1,
})
@@ -373,6 +389,8 @@ function UIItem(options){
// reset longer hover timeout and last window dragged over
clearTimeout(longer_hover_timeout);
last_window_dragged_over = null;
window.an_item_is_being_dragged = false;
$('.toolbar').css('pointer-events', 'auto');
}
});
+2 -1
View File
@@ -1754,6 +1754,7 @@ async function UIWindow(options) {
$(el_window).draggable({
start: function(e, ui){
window.a_window_is_being_dragged = true;
$('.toolbar').css('pointer-events', 'none');
// if window is snapped, unsnap it and reset its position to where it was before snapping
if(options.is_resizable && window_is_snapped){
window_is_snapped = false;
@@ -1930,7 +1931,7 @@ async function UIWindow(options) {
$(el_window_app_iframe).css('pointer-events', 'all');
$('.window').css('pointer-events', 'initial');
$('.toolbar').css('pointer-events', 'auto');
// jqueryui changes the z-index automatically, if the stay_on_top flag is set
// make sure window stays on top with the initial zindex though
$(`.window[data-stay_on_top="true"]`).each(function(){