From 906082a6b291a0f58823693e34f7b99e1b3bcf94 Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 14 Jul 2023 21:59:43 +0200 Subject: [PATCH] add help button to attachment list --- src/public/app/services/utils.js | 15 +++++++---- src/public/app/widgets/shared_switch.js | 2 +- src/public/app/widgets/switch.js | 1 - .../widgets/type_widgets/attachment_list.js | 25 ++++++++++++++++--- src/services/window.js | 8 +++--- 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/public/app/services/utils.js b/src/public/app/services/utils.js index 1fdd54bb6..e17606c1e 100644 --- a/src/public/app/services/utils.js +++ b/src/public/app/services/utils.js @@ -332,17 +332,22 @@ function initHelpDropdown($el) { const wikiBaseUrl = "https://github.com/zadam/trilium/wiki/"; -function openHelp(e) { - window.open(wikiBaseUrl + $(e.target).attr("data-help-page"), '_blank'); +function openHelp($button) { + const helpPage = $button.attr("data-help-page"); + + if (helpPage) { + const url = wikiBaseUrl + helpPage; + + window.open(url, '_blank'); + } } function initHelpButtons($el) { // for some reason, the .on(event, listener, handler) does not work here (e.g. Options -> Sync -> Help button) // so we do it manually $el.on("click", e => { - if ($(e.target).attr("data-help-page")) { - openHelp(e); - } + const $helpButton = $(e.target).closest("[data-help-page]"); + openHelp($helpButton); }); } diff --git a/src/public/app/widgets/shared_switch.js b/src/public/app/widgets/shared_switch.js index c779db22c..c219bac3e 100644 --- a/src/public/app/widgets/shared_switch.js +++ b/src/public/app/widgets/shared_switch.js @@ -21,7 +21,7 @@ export default class SharedSwitchWidget extends SwitchWidget { this.$switchOffButton.attr("title", "Unshare the note"); this.$helpButton.attr("data-help-page", "Sharing").show(); - this.$helpButton.on('click', e => utils.openHelp(e)); + this.$helpButton.on('click', e => utils.openHelp($(e.target))); } async switchOn() { diff --git a/src/public/app/widgets/switch.js b/src/public/app/widgets/switch.js index 3fab865bc..e70fb5612 100644 --- a/src/public/app/widgets/switch.js +++ b/src/public/app/widgets/switch.js @@ -110,7 +110,6 @@ export default class SwitchWidget extends NoteContextAwareWidget { this.$switchOffButton.on('click', () => this.toggle(false)); this.$helpButton = this.$widget.find(".switch-help-button"); - } toggle(state) { diff --git a/src/public/app/widgets/type_widgets/attachment_list.js b/src/public/app/widgets/type_widgets/attachment_list.js index 3220518f2..fca0334f1 100644 --- a/src/public/app/widgets/type_widgets/attachment_list.js +++ b/src/public/app/widgets/type_widgets/attachment_list.js @@ -1,6 +1,7 @@ import TypeWidget from "./type_widget.js"; import AttachmentDetailWidget from "../attachment_detail.js"; import linkService from "../../services/link.js"; +import utils from "../../services/utils.js"; const TPL = `
@@ -14,6 +15,18 @@ const TPL = ` margin-bottom: 15px; display: flex; justify-content: space-between; + align-items: baseline; + } + + .attachment-help-button { + font-size: xx-large; + border: 0; + background: none; + cursor: pointer; + color: var(--main-text-color); + margin-left: 20px; + position: relative; + top: 8px; } @@ -36,14 +49,20 @@ export default class AttachmentListTypeWidget extends TypeWidget { } async doRefresh(note) { + const $helpButton = $(''); + utils.initHelpButtons($helpButton); + this.$linksWrapper.empty().append( $('
').append( "Owning note: ", await linkService.createLink(this.noteId), ), - $('