From 2b2b2aaec5a13e2ab5037018d9ce1c93c6edd6b2 Mon Sep 17 00:00:00 2001 From: Ryan Prather Date: Sat, 13 Jun 2026 12:14:23 -0400 Subject: [PATCH] upd: home.js migrate from old to new --- assets/js/home.js | 116 ++++++++++++---------------------------------- 1 file changed, 30 insertions(+), 86 deletions(-) diff --git a/assets/js/home.js b/assets/js/home.js index b30d71b..8eff68b 100644 --- a/assets/js/home.js +++ b/assets/js/home.js @@ -111,7 +111,7 @@ export function previewNote() { export function setEventListeners() { document.addEventListener('keyup', function (event) { if (event.key == "F3") { - openRef(false); + openRef(); } }); @@ -119,9 +119,14 @@ export function setEventListeners() { let key = event.keyCode; if (key == 8 || key >= 48 && key <= 90 || key >= 96 && key <= 111 || key >= 186 && key <= 222) { + state.saved = false state.textDirty = true; document.querySelector('.mobile-note-header h2').classList.add('dirty'); document.querySelector('.note-header h2').classList.add('dirty'); + + if(state.failureCount > 0 && !state.to) { + state.to = setTimeout(note.saveNote, state.saveTimeout); + } } }); @@ -133,10 +138,16 @@ export function setEventListeners() { document.getElementById('increaseFont').addEventListener('click', increaseFont); document.getElementById('decreaseFont').addEventListener('click', decreaseFont); - document.getElementById('open-ref').addEventListener('click', openRef, {closeSidebar: false}); - document.getElementById('mobile-open-ref').addEventListener('click', openRef, {closeSidebar: false}); - document.getElementById('previewBtn').addEventListener('click', previewNote); + const openRefBtn = document.getElementById('open-ref'); + openRefBtn.addEventListener('click', openRef); + openRefBtn.closeSidebar = true; + const mobileOpenRefBtn = document.getElementById('mobile-open-ref'); + mobileOpenRefBtn.addEventListener('click', openRef); + mobileOpenRefBtn.closeSidebar = true; + + document.getElementById('previewBtn').addEventListener('click', previewNote); + //document.getElementById('shareBtn').addEventListener('click', note.openShareNote); document.getElementById('searchBtn').addEventListener('click', ref.queryRef); document.getElementById('closeSearch').addEventListener('click', closeRef); } @@ -145,28 +156,10 @@ export function initHome() { setBooks(); setEventListeners(); - $('sidebar-link').on('click', function(event) { - event.preventDefault(); - event.stopPropagation(); - - $('#sidebar').toggleClass('inactive'); - }); - - $('sidebar').on('click', 'a', function(event) { - var $a = $(this), href = $a.attr('href'), target = $a.attr('target'); - - event.preventDefault(); - event.stopPropagation(); - - $('sidebar').addClass('inactive'); - - setTimeout(function() { - if (target == '_blank') - window.open(href); - else - window.location.href = href; - }, 500); - }); + // expand the sidebar by default if we are on a large screen + if(document.body.clientWidth >= 1501) { + document.querySelector('.container').classList.remove('sidebar-collapsed'); + } $('#note-table').DataTable({ paging: false, @@ -184,6 +177,7 @@ export function initHome() { }, ] }); + $('#note-table').css('width', '100%'); $('#shareBtn').on('click', note.openShareNote); $('#modal-backdrop').on('click', note.closeShareNote); @@ -234,22 +228,26 @@ export function setBooks() { /** * Opens the reference with the option to close the sidebar. - * - * @param {boolean} closeSidebar - Indicates whether to close the sidebar when opening the reference. */ -export function openRef(e, closeSidebar = true) { +export function openRef(e) { document.querySelector('#open-ref').classList.add('active'); document.querySelector('#mobile-open-ref').classList.add('active'); let refQuery = document.querySelector('#refQuery'); refQuery.style.display = 'block'; + let closeSidebar = false; + if(typeof e.currentTarget.closeSidebar !== 'undefined') { + closeSidebar = e.currentTarget.closeSidebar; + } + + if (closeSidebar && !document.querySelector('.container').classList.contains('sidebar-collapsed')) { + document.querySelector('.toggle').click(); + } + let ref = document.querySelector('#ref-text'); refQuery.style.left = ref.offsetLeft + 'px'; refQuery.style.top = ref.offsetTop + 'px'; - if (closeSidebar) { - document.querySelector('.toggle').click(); - } } /** @@ -271,60 +269,6 @@ export function closeRef() { document.querySelector('#mobile-open-ref').classList.remove('active'); } -/** - * Retrieves a note from the server based on the provided ID. - * - * @param {string} id - The ID of the note to retrieve. - * @param {boolean} [runOpen=true] - Whether to open the note sidebar after retrieving the note. - * @return {Promise} A promise that resolves when the note is successfully retrieved and the UI is updated. - */ -export function retrieveNote(id, runOpen = true) { - fetch('/get-note', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - 'id': id - }) - }) - .then(response => response.json()) - .then(result => { - var dt = new Date(result.date.date); - - document.querySelector('#notes').value = result.text; - document.querySelector('#passage').value = result.passage; - document.querySelector('#series').value = result.series.id; - document.querySelector('#speaker').value = result.speaker.id; - document.querySelector('#noteTitle').value = result.title; - document.querySelector('#noteDate').value = ''; - document.querySelector('#noteDate').value = - (dt.getMonth() < 9 ? '0' + (dt.getMonth() + 1) : (dt.getMonth() + 1)) + '/' + - (dt.getDate() < 10 ? '0' + dt.getDate() : dt.getDate()) + '/' + - dt.getFullYear(); - document.querySelector('#noteId').value = result.id; - - if (result.refs) { - references = result.refs; - } - - const list = document.querySelector('#ref-list'); - list.innerHTML = ''; - var newList = null; - for (var x in references) { - var newList = document.createElement('li'); - newList.className = 'tab'; - var button = makeButton(x); - newList.appendChild(button); - list.appendChild(newList); - } - - if (runOpen) { - note.openNote(false); - } - }); -} - /** * A function to create a button element with the specified title and event listeners for click and double click actions. *