From 17fe9a6a1b03e28fc30b6a30d6076b77742577b8 Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 6 Oct 2021 18:31:19 +0200 Subject: [PATCH] added help button to JS code notes to navigate to API docs --- src/public/app/widgets/tab_row.js | 1 + .../app/widgets/type_widgets/editable_code.js | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/public/app/widgets/tab_row.js b/src/public/app/widgets/tab_row.js index 3ff68605a..4434b0d20 100644 --- a/src/public/app/widgets/tab_row.js +++ b/src/public/app/widgets/tab_row.js @@ -186,6 +186,7 @@ const TAB_ROW_TPL = ` font-size: 24px; position: relative; top: -6px; + cursor: pointer; } .tab-row-widget .note-tab .note-tab-close:hover { diff --git a/src/public/app/widgets/type_widgets/editable_code.js b/src/public/app/widgets/type_widgets/editable_code.js index 88682a365..3bdc734f0 100644 --- a/src/public/app/widgets/type_widgets/editable_code.js +++ b/src/public/app/widgets/type_widgets/editable_code.js @@ -10,10 +10,24 @@ import treeService from "../../services/tree.js"; const TPL = `
+ +
@@ -36,6 +50,16 @@ export default class EditableCodeTypeWidget extends TypeWidget { doRender() { this.$widget = $(TPL); + this.$openTriliumApiDocsButton = this.$widget.find(".trilium-api-docs-button"); + this.$openTriliumApiDocsButton.on("click", () => { + if (this.note.mime.endsWith("frontend")) { + window.open("https://zadam.github.io/trilium/frontend_api/FrontendScriptApi.html", "_blank"); + } + else { + window.open("https://zadam.github.io/trilium/backend_api/BackendScriptApi.html", "_blank"); + } + }); + this.$editor = this.$widget.find('.note-detail-code-editor'); this.$executeButton = this.$widget.find('.execute-button'); this.$saveToNoteButton = this.$widget.find('.save-to-note-button'); @@ -99,6 +123,8 @@ export default class EditableCodeTypeWidget extends TypeWidget { && !note.getAllNotePaths().find(notePathArr => !notePathArr.includes("hidden")) ); + this.$openTriliumApiDocsButton.toggle(note.mime.startsWith('application/javascript;env=')); + const noteComplement = await this.noteContext.getNoteComplement(); await this.spacedUpdate.allowUpdateWithoutChange(() => {