refactored note creation methods into a separate service

This commit is contained in:
zadam
2020-02-03 20:07:34 +01:00
parent 822a8509b3
commit 66204811cf
9 changed files with 138 additions and 110 deletions

View File

@@ -495,4 +495,26 @@ $(window).on('beforeunload', () => {
appContext.trigger('beforeUnload');
});
function isNotePathInAddress() {
const [notePath, tabId] = getHashValueFromAddress();
return notePath.startsWith("root")
// empty string is for empty/uninitialized tab
|| (notePath === '' && !!tabId);
}
function getHashValueFromAddress() {
const str = document.location.hash ? document.location.hash.substr(1) : ""; // strip initial #
return str.split("-");
}
$(window).on('hashchange', function() {
if (isNotePathInAddress()) {
const [notePath, tabId] = getHashValueFromAddress();
appContext.switchToTab(tabId, notePath);
}
});
export default appContext;