From af5c623671162ce11fc9b8a8672ab48a5f1346a9 Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 21 Jan 2020 22:08:41 +0100 Subject: [PATCH] simplification of triggering events from links --- .../services/frontend_script_api.js | 2 +- src/public/javascripts/services/tree.js | 2 -- .../javascripts/widgets/basic_widget.js | 6 ++++ .../javascripts/widgets/global_buttons.js | 33 +++++++++---------- .../javascripts/widgets/note_actions.js | 31 ++++------------- src/public/javascripts/widgets/note_info.js | 13 +++++++- src/public/javascripts/widgets/note_tree.js | 5 ++- src/public/stylesheets/desktop.css | 4 +-- 8 files changed, 45 insertions(+), 51 deletions(-) diff --git a/src/public/javascripts/services/frontend_script_api.js b/src/public/javascripts/services/frontend_script_api.js index c7aa12839..97d8d328a 100644 --- a/src/public/javascripts/services/frontend_script_api.js +++ b/src/public/javascripts/services/frontend_script_api.js @@ -50,7 +50,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte */ this.activateNote = async (notePath, noteLoadedListener) => { await treeService.activateNote(notePath, async () => { - await appContext.getMainNoteTree().scrollToActiveNote(); + await appContext.getMainNoteTree().scrollToActiveNoteListener(); if (noteLoadedListener) { noteLoadedListener(); diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.js index 931a38892..22f430623 100644 --- a/src/public/javascripts/services/tree.js +++ b/src/public/javascripts/services/tree.js @@ -556,8 +556,6 @@ keyboardActionService.setGlobalActionHandler('CutIntoNote', () => createNoteInto keyboardActionService.setGlobalActionHandler('CreateNoteInto', createNoteInto); -keyboardActionService.setGlobalActionHandler('ScrollToActiveNote', () => appContext.getMainNoteTree().scrollToActiveNote()); - $(window).bind('hashchange', async function() { if (isNotePathInAddress()) { const [notePath, tabId] = getHashValueFromAddress(); diff --git a/src/public/javascripts/widgets/basic_widget.js b/src/public/javascripts/widgets/basic_widget.js index 2105aac8d..c60fac88b 100644 --- a/src/public/javascripts/widgets/basic_widget.js +++ b/src/public/javascripts/widgets/basic_widget.js @@ -7,6 +7,12 @@ class BasicWidget extends Component { keyboardActionsService.updateDisplayedShortcuts($widget); + $widget.find("[data-trigger-event]").on('click', e => { + const eventName = $(e.target).attr('data-trigger-event'); + + this.appContext.trigger(eventName); + }); + return $widget; } diff --git a/src/public/javascripts/widgets/global_buttons.js b/src/public/javascripts/widgets/global_buttons.js index a9f8fc475..c10d6bf39 100644 --- a/src/public/javascripts/widgets/global_buttons.js +++ b/src/public/javascripts/widgets/global_buttons.js @@ -14,31 +14,30 @@ const WIDGET_TPL = `
- + - + - + - +
`; class GlobalButtonsWidget extends BasicWidget { doRender($widget) { - $widget = $(WIDGET_TPL); - - const $createTopLevelNoteButton = $widget.find(".create-top-level-note-button"); - const $collapseTreeButton = $widget.find(".collapse-tree-button"); - const $scrollToActiveNoteButton = $widget.find(".scroll-to-active-note-button"); - const $toggleSearchButton = $widget.find(".toggle-search-button"); - - $createTopLevelNoteButton.on('click', () => this.trigger('createTopLevelNote')); - $collapseTreeButton.on('click', () => this.trigger('collapseTree')); - $scrollToActiveNoteButton.on('click', () => appContext.getMainNoteTree().scrollToActiveNote()); - $toggleSearchButton.on('click', () => this.trigger('toggleSearch')); - - return $widget; + return $(WIDGET_TPL); } } diff --git a/src/public/javascripts/widgets/note_actions.js b/src/public/javascripts/widgets/note_actions.js index 4676da2a7..ff053b9d3 100644 --- a/src/public/javascripts/widgets/note_actions.js +++ b/src/public/javascripts/widgets/note_actions.js @@ -1,7 +1,4 @@ import TabAwareWidget from "./tab_aware_widget.js"; -import appContext from "../services/app_context.js"; -import libraryLoader from "../services/library_loader.js"; -import keyboardActionService from "../services/keyboard_actions.js"; const TPL = ` `; @@ -25,23 +22,7 @@ export default class NoteActionsWidget extends TabAwareWidget { doRender() { this.$widget = $(TPL); - this.$showRevisionsButton = this.$widget.find('.show-note-revisions-button'); - this.$showRevisionsButton.on('click', e => this.triggerEvent(e, 'showNoteRevisions')); - - this.$showAttributesButton = this.$widget.find('.show-attributes-button'); - this.$showAttributesButton.on('click', e => this.triggerEvent(e, 'showAttributes')); - - this.$showLinkMapButton = this.$widget.find('.show-link-map-button'); - this.$showLinkMapButton.on('click', e => this.triggerEvent(e, 'showLinkMap')); - this.$showSourceButton = this.$widget.find('.show-source-button'); - this.$showSourceButton.on('click', e => this.triggerEvent(e, 'showNoteSource')); - - this.$showNoteInfoButton = this.$widget.find('.show-note-info-button'); - this.$showNoteInfoButton.on('click', e => this.triggerEvent(e, 'showNoteInfo')); - - this.$printNoteButton = this.$widget.find('.print-note-button'); - this.$printNoteButton.on('click', e => this.triggerEvent(e, 'printActiveNote')); this.$exportNoteButton = this.$widget.find('.export-note-button'); this.$exportNoteButton.on("click", () => { diff --git a/src/public/javascripts/widgets/note_info.js b/src/public/javascripts/widgets/note_info.js index 3f1fc5339..d898065f3 100644 --- a/src/public/javascripts/widgets/note_info.js +++ b/src/public/javascripts/widgets/note_info.js @@ -1,7 +1,18 @@ import StandardWidget from "./standard_widget.js"; const TPL = ` - +
+ + diff --git a/src/public/javascripts/widgets/note_tree.js b/src/public/javascripts/widgets/note_tree.js index 5740cd804..383d39ce0 100644 --- a/src/public/javascripts/widgets/note_tree.js +++ b/src/public/javascripts/widgets/note_tree.js @@ -251,7 +251,7 @@ export default class NoteTreeWidget extends TabAwareWidget { if (!node) { const hoistedNoteId = await hoistedNoteService.getHoistedNoteId(); - node = getNodesByNoteId(hoistedNoteId)[0]; + node = this.getNodesByNoteId(hoistedNoteId)[0]; } node.setExpanded(false); @@ -281,8 +281,7 @@ export default class NoteTreeWidget extends TabAwareWidget { } } - // FIXME since this operates on note details tab context it seems it does not really belong here - async scrollToActiveNote() { + async scrollToActiveNoteListener() { const activeContext = appContext.getActiveTabContext(); if (activeContext && activeContext.notePath) { diff --git a/src/public/stylesheets/desktop.css b/src/public/stylesheets/desktop.css index f2fc34cd5..a3102b7aa 100644 --- a/src/public/stylesheets/desktop.css +++ b/src/public/stylesheets/desktop.css @@ -124,8 +124,8 @@ body { background-color: inherit; } -.widget .note-info-table td, .widget .note-info-table th { - padding: 5px; +#note-info-table td, #note-info-table th { + padding: 15px; } [data-toggle="tooltip"] span {
Note ID: