From 37ae2f46572329ebabad5bde147abc2e16b0ee72 Mon Sep 17 00:00:00 2001 From: Wei Ouyang Date: Sun, 25 Feb 2024 22:56:06 +0100 Subject: [PATCH] Fix buttons --- index.html | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/index.html b/index.html index 5cb1b0bb9..e83e4f90e 100644 --- a/index.html +++ b/index.html @@ -152,41 +152,32 @@ function getSelections(config) { return new Promise((resolve) => { const buttonStyle = "font-size: 0.65rem; background: #448aff;color: white;margin-right: 10px;margin-top: -4px;margin-left: -8px;width: 40px;" - const button_set = $('
') - const ok_button = $(``) + // Check if buttons already exist + let ok_button = $('#ok-button'); + let cancel_button = $('#cancel-button'); + + if (!ok_button.length || !cancel_button.length) { + ok_button = $(``) + cancel_button = $(``) + const button_set = $('
') + button_set.append(ok_button).append(cancel_button) + button_set.insertAfter(fm.getUI('statusbar').children('.elfinder-stat-size')); + } ok_button.on('click', () => { const selected = fm.selectedFiles() - api.close() + if(config === undefined || !config.close_on_select) api.close() resolve(selected); - }) ok_button.hide() fm.select(() => { ok_button.show() }) - const _exec = fm.exec - fm.exec = (function (cmd, files, opts, dstHash) { - // intercept the open action - if (cmd === "open") { - const selected = fm.selectedFiles() - api.close() - resolve(selected); - } - else { - _exec.apply(fm, [cmd, files, opts, dstHash]); - } - }).bind(fm); - - const cancel_button = $(``) cancel_button.on('click', () => { - api.close() + if(config === undefined || !config.close_on_select) api.close() resolve([]) }) - button_set.append(ok_button).append(cancel_button) - button_set.insertAfter(fm.getUI('statusbar').children('.elfinder-stat-size')); // adjust the window size window.dispatchEvent(new Event('resize')) - api.on("close", () => { resolve([]) }) @@ -259,4 +250,4 @@ - \ No newline at end of file +