diff --git a/svelte/src/file_viewer/Downloader.svelte b/svelte/src/file_viewer/Downloader.svelte index 6c4c7ab..070cccc 100644 --- a/svelte/src/file_viewer/Downloader.svelte +++ b/svelte/src/file_viewer/Downloader.svelte @@ -101,8 +101,10 @@ const download = (href, file_name) => { let a = document.createElement("a") a.href = href a.download = file_name - a.click() - a.remove() + + // You can't call .click() on an element that is not in the DOM. But + // emitting a click event works + a.dispatchEvent(new MouseEvent("click")) } diff --git a/svelte/src/filesystem/DetailsWindow.svelte b/svelte/src/filesystem/DetailsWindow.svelte index 7568915..86797a2 100644 --- a/svelte/src/filesystem/DetailsWindow.svelte +++ b/svelte/src/filesystem/DetailsWindow.svelte @@ -2,7 +2,7 @@ import Chart from "util/Chart.svelte"; import { formatDataVolume, formatDate, formatThousands } from "util/Formatting"; import Modal from "util/Modal.svelte"; -import { fs_path_url, fs_share_path, fs_share_url, fs_timeseries, type FSNode } from "./FilesystemAPI"; +import { fs_path_url, fs_share_hotlink_url, fs_share_url, fs_timeseries, type FSNode } from "./FilesystemAPI"; import { color_by_name } from "util/Util.svelte"; import { tick } from "svelte"; import CopyButton from "layout/CopyButton.svelte"; @@ -21,7 +21,7 @@ const visibility_change = visible => { $: direct_url = $nav.base.path ? window.location.origin+fs_path_url($nav.base.path) : "" $: share_url = fs_share_url($nav.path) -$: direct_share_url = $nav.base.path ? window.location.origin+fs_path_url(fs_share_path($nav.path)) : "" +$: direct_share_url = fs_share_hotlink_url($nav.path) let chart let chart_timespan = 0 diff --git a/svelte/src/filesystem/FilesystemAPI.ts b/svelte/src/filesystem/FilesystemAPI.ts index a3fd1cb..be948a8 100644 --- a/svelte/src/filesystem/FilesystemAPI.ts +++ b/svelte/src/filesystem/FilesystemAPI.ts @@ -339,6 +339,15 @@ export const fs_share_url = (path: FSNode[]): string => { return share_path } + +export const fs_share_hotlink_url = (path: FSNode[]): string => { + let share_path = fs_share_path(path) + if (share_path !== "") { + share_path = window.location.protocol + "//" + window.location.host + fs_path_url(share_path) + } + return share_path +} + export const fs_share_path = (path: FSNode[]): string => { let share_url = "" let bucket_idx = -1 @@ -373,6 +382,7 @@ export const fs_download = (node: FSNode) => { a.download = node.name + ".zip" } - a.click() - a.remove() + // You can't call .click() on an element that is not in the DOM. But + // emitting a click event works + a.dispatchEvent(new MouseEvent("click")) } diff --git a/svelte/src/filesystem/Menu.svelte b/svelte/src/filesystem/Menu.svelte index 48586a0..2d884e3 100644 --- a/svelte/src/filesystem/Menu.svelte +++ b/svelte/src/filesystem/Menu.svelte @@ -4,9 +4,10 @@ import Button from "layout/Button.svelte"; import Euro from "util/Euro.svelte"; import { formatDataVolume } from "util/Formatting"; import { user } from "lib/UserStore"; +import Dialog from "layout/Dialog.svelte"; let button: HTMLButtonElement -let dialog: HTMLDialogElement +let dialog: Dialog export let no_login_label = "Pixeldrain" @@ -17,35 +18,7 @@ export let style = "" export let embedded = false $: target = embedded ? "_blank" : "_self" -const open = () => { - // Show the window so we can get the location - dialog.showModal() - - const edge_offset = 5 - - // Get the egdes of the screen, so the window does not spawn off-screen - const window_rect = dialog.getBoundingClientRect() - const max_left = window.innerWidth - window_rect.width - edge_offset - const max_top = window.innerHeight - window_rect.height - edge_offset - - // Get the location of the button - const button_rect = button.getBoundingClientRect() - - // Prevent the window from being glued to the edges - const min_left = Math.max(button_rect.left, edge_offset) - const min_top = Math.max(button_rect.bottom, edge_offset) - - // Place the window - dialog.style.left = Math.round(Math.min(min_left, max_left)) + "px" - dialog.style.top = Math.round(Math.min(min_top, max_top)) + "px" -} - -// Close the dialog when the user clicks the background -const click = (e: MouseEvent) => { - if (e.target === dialog) { - dialog.close() - } -} +const open = () => dialog.open(button.getBoundingClientRect())