aboutsummaryrefslogtreecommitdiff
path: root/scripts/src/notebook-edit.js
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2019-01-13 11:42:01 -0600
committerluxagraf <sng@luxagraf.net>2019-01-13 11:42:01 -0600
commit5b9343d77d8321e44d1ffc60769c651771dc38dd (patch)
tree8bbce1b415fbf2fd4c4ee1a7913ca41d362216ec /scripts/src/notebook-edit.js
parent261f9df4911f861a71e11eb3f0bfbe1a5a5d12b9 (diff)
Refactored Javascript, started on forums
Diffstat (limited to 'scripts/src/notebook-edit.js')
-rw-r--r--scripts/src/notebook-edit.js34
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'));
+ }
+});