From eedbfd42af2bfe6682b5bb749dc961edfd06980d Mon Sep 17 00:00:00 2001 From: MickaelK Date: Thu, 6 Feb 2025 14:41:14 +1100 Subject: [PATCH] fix (download): download in new page whenever clicking on the download link, there were issue with target=_blank + the download attribute. Effectively the download attribute remove the effect of target blank, hence this workaround to make sure the files that are downloaded are correctly named + open up in a new tab. The issue without target blank is if the user starts the download, he doesn't see a direct feedback telling him that something is working under the hood, hence the target blank --- public/assets/lib/rx.js | 3 ++- public/assets/pages/filespage/ctrl_submenu.js | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/public/assets/lib/rx.js b/public/assets/lib/rx.js index 81c433fb..7bf27eb0 100644 --- a/public/assets/lib/rx.js +++ b/public/assets/lib/rx.js @@ -39,10 +39,11 @@ export function preventDefault() { return rxjs.tap((e) => e.preventDefault()); } -export function onClick($node) { +export function onClick($node, opts = { preventDefault: false }) { const sideE = ($node) => { assert.type($node, HTMLElement); return rxjs.fromEvent($node, "click").pipe( + rxjs.tap((e) => (opts.preventDefault === true) && e.preventDefault()), rxjs.map(() => $node) ); }; diff --git a/public/assets/pages/filespage/ctrl_submenu.js b/public/assets/pages/filespage/ctrl_submenu.js index 2f97c823..5231697b 100644 --- a/public/assets/pages/filespage/ctrl_submenu.js +++ b/public/assets/pages/filespage/ctrl_submenu.js @@ -122,9 +122,11 @@ function componentLeft(render, { $scroll }) { `))), rxjs.tap(($buttons) => animate($buttons, { time: 100, keyframes: slideYIn(5) })), rxjs.switchMap(($page) => rxjs.merge( - onClick(qs($page, `[data-action="download"]`)).pipe( - rxjs.mergeMap(() => rxjs.EMPTY), - ), + onClick(qs($page, `[data-action="download"]`), { preventDefault: true }).pipe(rxjs.tap(($button) => { + let url = $button.parentElement.getAttribute("href"); + url += "&name=" + $button.parentElement.getAttribute("download"); + window.open(url); + })), onClick(qs($page, `[data-action="share"]`)).pipe(rxjs.tap(() => { componentShare(createModal({ withButtonsRight: null, @@ -178,6 +180,9 @@ function componentLeft(render, { $scroll }) { `))), rxjs.mergeMap(($page) => rxjs.merge( + onClick(qs($page, `[data-action="download"]`), { preventDefault: true }).pipe(rxjs.tap(($button) => { + window.open($button.parentElement.getAttribute("href")); + })), onClick(qs($page, `[data-action="delete"]`)).pipe(rxjs.mergeMap(() => { const paths = expandSelection().map(({ path }) => path); return rxjs.from(componentDelete(