Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-file Dragging Bug Fix #1245

Merged
merged 9 commits into from
May 4, 2024
4 changes: 4 additions & 0 deletions www/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
padding-left: 1px !important;
}

.dragging-over * {
pointer-events: none !important;
D3V-D marked this conversation as resolved.
Show resolved Hide resolved
}

.form-control {
margin-top: 2px;
}
Expand Down
70 changes: 54 additions & 16 deletions www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1521,17 +1521,11 @@ function displayFileSelect () {

// Set the main drop zone
if (!params.disableDragAndDrop) {
configDropZone.addEventListener('dragover', handleGlobalDragover);
configDropZone.addEventListener('dragleave', function () {
configDropZone.style.border = '';
});
// Also set a global drop zone (allows us to ensure Config is always displayed for the file drop)
globalDropZone.addEventListener('dragover', function (e) {
e.preventDefault();
if (configDropZone.style.display === 'none') document.getElementById('btnConfigure').click();
e.dataTransfer.dropEffect = 'link';
});
// do globally, since the whole page functions as a drop zone, so indicate properly
D3V-D marked this conversation as resolved.
Show resolved Hide resolved
globalDropZone.addEventListener('dragover', handleGlobalDragover);
globalDropZone.addEventListener('dragleave', handleGlobalDragleave);
globalDropZone.addEventListener('drop', handleFileDrop);
globalDropZone.addEventListener('dragenter', handleGlobalDragenter);
}

if (isFireFoxOsNativeFileApiAvailable) {
Expand Down Expand Up @@ -1635,27 +1629,71 @@ document.getElementById('archiveFilesLbl').addEventListener('keydown', function
}
});

/** Drag and Drop handling for ZIM files */

// keep track of entrance event so we only fire the correct leave event
D3V-D marked this conversation as resolved.
Show resolved Hide resolved
var enteredelement;
D3V-D marked this conversation as resolved.
Show resolved Hide resolved

function handleGlobalDragenter (e) {
e.preventDefault();
// disable pointer-events on children
// so they don't interfere with dragleave events
D3V-D marked this conversation as resolved.
Show resolved Hide resolved
globalDropZone.classList.add('dragging-over');
enteredelement = e.target;
}

function handleGlobalDragover (e) {
e.preventDefault();
e.dataTransfer.dropEffect = 'link';
configDropZone.style.border = '3px dotted red';

if (e.dataTransfer.types.includes('Files') && !hasInvalidType(e.dataTransfer.types)) {
e.dataTransfer.dropEffect = 'link';
globalDropZone.classList.add('dragging-over');
globalDropZone.style.border = '3px dashed red';
document.getElementById('btnConfigure').click();
}
}

function handleGlobalDragleave (e) {
e.preventDefault();
globalDropZone.style.border = '';
if (e.dataTransfer.types.includes('Files') && !hasInvalidType(e.dataTransfer.types)) {
/** can we somehow check if a page has been loaded? no need to go home if no page loaded yet. just keep on config */
D3V-D marked this conversation as resolved.
Show resolved Hide resolved
if (enteredelement === e.target) {
globalDropZone.classList.remove('dragging-over');
document.getElementById('btnHome').click();
}
}
}

function handleIframeDragover (e) {
e.preventDefault();
e.dataTransfer.dropEffect = 'link';
document.getElementById('btnConfigure').click();
if (e.dataTransfer.types.includes('Files') && !hasInvalidType(e.dataTransfer.types)) {
globalDropZone.classList.add('dragging-over');
e.dataTransfer.dropEffect = 'link';
document.getElementById('btnConfigure').click();
}
}

function handleIframeDrop (e) {
e.stopPropagation();
e.preventDefault();
e.stopPropagation();
}

// add type check for chromium browsers, since they count images on the same page as files
D3V-D marked this conversation as resolved.
Show resolved Hide resolved
function hasInvalidType (typesList) {
for (var i = 0; i < typesList.length; i++) {
if (typesList[i].startsWith('image') || typesList[i].startsWith('text') || typesList[i].startsWith('video')) {
return true;
}
}
return false;
}

async function handleFileDrop (packet) {
packet.stopPropagation();
packet.preventDefault();
configDropZone.style.border = '';
globalDropZone.style.border = '';
globalDropZone.classList.remove('dragging-over');
var files = packet.dataTransfer.files;
document.getElementById('selectInstructions').style.display = 'none';
document.getElementById('fileSelectionButtonContainer').style.display = 'none';
Expand Down
Loading