mirror of
https://github.com/kiwix/kiwix-js.git
synced 2025-09-22 12:01:15 -04:00
parent
85a9d82cbb
commit
9e25c7551d
@ -64,6 +64,10 @@
|
|||||||
padding-left: 1px !important;
|
padding-left: 1px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.dragging-over * {
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
.form-control {
|
.form-control {
|
||||||
margin-top: 2px;
|
margin-top: 2px;
|
||||||
}
|
}
|
||||||
|
@ -1521,17 +1521,11 @@ function displayFileSelect () {
|
|||||||
|
|
||||||
// Set the main drop zone
|
// Set the main drop zone
|
||||||
if (!params.disableDragAndDrop) {
|
if (!params.disableDragAndDrop) {
|
||||||
configDropZone.addEventListener('dragover', handleGlobalDragover);
|
// Set a global drop zone, so that whole page is enabled for drag and drop
|
||||||
configDropZone.addEventListener('dragleave', function () {
|
globalDropZone.addEventListener('dragover', handleGlobalDragover);
|
||||||
configDropZone.style.border = '';
|
globalDropZone.addEventListener('dragleave', handleGlobalDragleave);
|
||||||
});
|
|
||||||
// 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';
|
|
||||||
});
|
|
||||||
globalDropZone.addEventListener('drop', handleFileDrop);
|
globalDropZone.addEventListener('drop', handleFileDrop);
|
||||||
|
globalDropZone.addEventListener('dragenter', handleGlobalDragenter);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFireFoxOsNativeFileApiAvailable) {
|
if (isFireFoxOsNativeFileApiAvailable) {
|
||||||
@ -1635,27 +1629,92 @@ 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
|
||||||
|
var enteredElement;
|
||||||
|
|
||||||
|
function handleGlobalDragenter (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
// Disable pointer-events on children so they don't interfere with dragleave events
|
||||||
|
globalDropZone.classList.add('dragging-over');
|
||||||
|
enteredElement = e.target;
|
||||||
|
}
|
||||||
|
|
||||||
function handleGlobalDragover (e) {
|
function handleGlobalDragover (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
if (hasType(e.dataTransfer.types, 'Files') && !hasInvalidType(e.dataTransfer.types)) {
|
||||||
e.dataTransfer.dropEffect = 'link';
|
e.dataTransfer.dropEffect = 'link';
|
||||||
configDropZone.style.border = '3px dotted red';
|
globalDropZone.classList.add('dragging-over');
|
||||||
|
globalDropZone.style.border = '3px dashed red';
|
||||||
|
document.getElementById('btnConfigure').click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleGlobalDragleave (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
globalDropZone.style.border = '';
|
||||||
|
if (enteredElement === e.target) {
|
||||||
|
globalDropZone.classList.remove('dragging-over');
|
||||||
|
// Only return to page if a ZIM is actually loaded
|
||||||
|
if (selectedArchive.isReady()) {
|
||||||
|
returnToCurrentPage();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleIframeDragover (e) {
|
function handleIframeDragover (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
if (hasType(e.dataTransfer.types, 'Files') && !hasInvalidType(e.dataTransfer.types)) {
|
||||||
|
globalDropZone.classList.add('dragging-over');
|
||||||
e.dataTransfer.dropEffect = 'link';
|
e.dataTransfer.dropEffect = 'link';
|
||||||
document.getElementById('btnConfigure').click();
|
document.getElementById('btnConfigure').click();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleIframeDrop (e) {
|
function handleIframeDrop (e) {
|
||||||
e.stopPropagation();
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add type check for chromium browsers, since they count images on the same page as files
|
||||||
|
function hasInvalidType (typesList) {
|
||||||
|
for (var i = 0; i < typesList.length; i++) {
|
||||||
|
// Use indexOf() instead of startsWith() for IE11 support. Also, IE11 uses Text instead of text (and so does Opera).
|
||||||
|
// This is not comprehensive, but should cover most cases.
|
||||||
|
if (typesList[i].indexOf('image') === 0 || typesList[i].indexOf('text') === 0 || typesList[i].indexOf('Text') === 0|| typesList[i].indexOf('video') === 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// IE11 doesn't support .includes(), so custom function to check for presence of types
|
||||||
|
function hasType (typesList, type) {
|
||||||
|
for (var i = 0; i < typesList.length; i++) {
|
||||||
|
if (typesList[i] === type) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to switch back to currently loaded page from config page after dragleave event
|
||||||
|
function returnToCurrentPage () {
|
||||||
|
document.getElementById('liConfigureNav').classList.remove('active');
|
||||||
|
document.getElementById('liHomeNav').classList.add('active');
|
||||||
|
uiUtil.tabTransitionToSection('home', params.showUIAnimations);
|
||||||
|
const welcomeText = document.getElementById('welcomeText');
|
||||||
|
welcomeText.style.display = 'none';
|
||||||
|
viewArticle.style.display = 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleFileDrop (packet) {
|
async function handleFileDrop (packet) {
|
||||||
packet.stopPropagation();
|
packet.stopPropagation();
|
||||||
packet.preventDefault();
|
packet.preventDefault();
|
||||||
configDropZone.style.border = '';
|
globalDropZone.style.border = '';
|
||||||
|
globalDropZone.classList.remove('dragging-over');
|
||||||
var files = packet.dataTransfer.files;
|
var files = packet.dataTransfer.files;
|
||||||
document.getElementById('selectInstructions').style.display = 'none';
|
document.getElementById('selectInstructions').style.display = 'none';
|
||||||
document.getElementById('fileSelectionButtonContainer').style.display = 'none';
|
document.getElementById('fileSelectionButtonContainer').style.display = 'none';
|
||||||
@ -1663,11 +1722,11 @@ async function handleFileDrop (packet) {
|
|||||||
document.getElementById('selectorsDisplay').style.display = 'inline';
|
document.getElementById('selectorsDisplay').style.display = 'inline';
|
||||||
archiveFiles.value = null;
|
archiveFiles.value = null;
|
||||||
|
|
||||||
// value will be set to true if a folder is dropped then there will be no need to
|
// Value will be set to true if a folder is dropped then there will be no need to
|
||||||
// call the `setLocalArchiveFromFileList`
|
// call the `setLocalArchiveFromFileList`
|
||||||
let loadZim = true;
|
let loadZim = true;
|
||||||
|
|
||||||
// no previous file will be loaded in case of FileSystemApi
|
// No previous file will be loaded in case of FileSystemApi
|
||||||
if (params.isFileSystemApiSupported) loadZim = await abstractFilesystemAccess.handleFolderOrFileDropViaFileSystemAPI(packet);
|
if (params.isFileSystemApiSupported) loadZim = await abstractFilesystemAccess.handleFolderOrFileDropViaFileSystemAPI(packet);
|
||||||
else if (params.isWebkitDirApiSupported) {
|
else if (params.isWebkitDirApiSupported) {
|
||||||
const ret = await abstractFilesystemAccess.handleFolderOrFileDropViaWebkit(packet);
|
const ret = await abstractFilesystemAccess.handleFolderOrFileDropViaWebkit(packet);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user