diff options
Diffstat (limited to 'scripts/src/notebook-edit.js')
-rw-r--r-- | scripts/src/notebook-edit.js | 34 |
1 files changed, 21 insertions, 13 deletions
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')); + } +}); |