From 5b9343d77d8321e44d1ffc60769c651771dc38dd Mon Sep 17 00:00:00 2001 From: luxagraf Date: Sun, 13 Jan 2019 11:42:01 -0600 Subject: Refactored Javascript, started on forums --- scripts/src/notebook-edit.js | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'scripts/src/notebook-edit.js') diff --git a/scripts/src/notebook-edit.js b/scripts/src/notebook-edit.js index 7d0aa8f..a6ba689 100644 --- a/scripts/src/notebook-edit.js +++ b/scripts/src/notebook-edit.js @@ -17,8 +17,12 @@ function initNotebookEditor() { document.getElementById('btn-js-hide').classList.add('hide'); btn.classList.remove('hide'); + btn.isHidden = true; btn.addEventListener('click', function(e){ e.preventDefault(); + e.target.textContent = e.target.isHidden ? 'Save' : 'Edit'; + e.target.isHidden = !e.target.isHidden; + e.target.classList.toggle('save'); edit_notebook(title, form, picker, fname, window.url); }, false); } @@ -68,6 +72,7 @@ function initMultiNotebookEditor(notebooks){ btn.isHidden = true; function clickHandler(e) { e.preventDefault(); + console.log(e.target.textContent); e.target.textContent = e.target.isHidden ? 'Save' : 'Edit'; e.target.isHidden = !e.target.isHidden; e.target.classList.toggle('save'); @@ -131,16 +136,19 @@ function notebookCallback(title, request) { console.log('server error'); } } -if (typeof(document.getElementById('nb-edit-form')) != 'undefined' && document.getElementById('nb-edit-form') != null) { - initNotebookEditor(); -} -if (typeof(document.getElementById('nb-create-form')) != 'undefined' && document.getElementById('nb-create-form') != null && document.getElementById('nb-list-home') !== null) { - var newnotebook = document.getElementById('notebook-wrapper'); - newnotebook.classList.add('hide'); - var notebookAddForm = document.getElementById('nb-create-form'); - var btn = document.getElementById('add_id_notebook'); - addNotebookModal(notebookAddForm, btn); - var create_form = document.getElementById('nb-create-form'); - activatePicker(create_form, create_form.getElementsByTagName('fieldset')['color-picker']); - initMultiNotebookEditor(document.getElementsByClassName('nb-list-item')); -} + +document.addEventListener("DOMContentLoaded", function () { + if (typeof(document.getElementById('nb-edit-form')) != 'undefined' && document.getElementById('nb-edit-form') != null) { + initNotebookEditor(); + } + if (typeof(document.getElementById('nb-create-form')) != 'undefined' && document.getElementById('nb-create-form') != null && document.getElementById('nb-list-home') !== null) { + var newnotebook = document.getElementById('notebook-wrapper'); + newnotebook.classList.add('hide'); + var notebookAddForm = document.getElementById('nb-create-form'); + var btn = document.getElementById('add_id_notebook'); + addNotebookModal(notebookAddForm, btn); + var create_form = document.getElementById('nb-create-form'); + activatePicker(create_form, create_form.getElementsByTagName('fieldset')['color-picker']); + initMultiNotebookEditor(document.getElementsByClassName('nb-list-item')); + } +}); -- cgit v1.2.3-70-g09d2