diff options
Diffstat (limited to 'scripts/src/notebook-edit.js')
-rw-r--r-- | scripts/src/notebook-edit.js | 74 |
1 files changed, 61 insertions, 13 deletions
diff --git a/scripts/src/notebook-edit.js b/scripts/src/notebook-edit.js index 00e9708..c1aa278 100644 --- a/scripts/src/notebook-edit.js +++ b/scripts/src/notebook-edit.js @@ -1,29 +1,73 @@ - -const picker = document.getElementById('color-picker'); function disablePicker(e) { console.log(e.target.popup); } function initNotebookEditor() { var btn = document.getElementById('edit-toggle-btn'), title = document.getElementById('nb-title'), - form = document.getElementById('nb-edit-form'); + form = document.getElementById('nb-edit-form'), + picker = form.getElementsByTagName('fieldset')['color-picker'], + fname = form.getElementsByTagName('input')['id_name']; window.bookediting = false; form.getElementsByTagName('input')['color_rgb'].disabled = true; form.addEventListener('input', function () { window.formchange = true; - console.log("adding change"); + console.log('adding change'); }); document.getElementById('btn-js-hide').classList.add('hide'); btn.classList.remove('hide'); btn.addEventListener('click', function(e){ e.preventDefault(); - edit_notebook(this, title, form, window.url); + edit_notebook(this, title, form, picker, fname, window.url); }, false); } -function edit_notebook(btn, title, form, url){ +function initNotebookCreator(btn, title, url) { + var notebook_form = document.querySelector('#nb-create-form'); + var notebook_form_inputs = notebook_form.getElementsByTagName('input'); + var picker = notebook_form.getElementsByTagName('fieldset')['color-picker']; + picker.popup = new Picker({ + parent: picker, + color: 'blue', + alpha: false, + //editor: false, + editorFormat: 'hex', + onDone: function(color) { + this.settings['parent'].style.backgroundColor = color.rgbString; + notebook_form_inputs['color_rgb'].value = color.rgbString; + }, + }); + var forms = []; + var btns = []; + var notebooks = document.getElementsByClassName('nb-list-item'); + window.bookediting = false; + for (var i = 0; i < notebooks.length; i++) { + var fname = notebooks[i].getElementsByTagName('input')['id_form-'+i+'-name']; + fname.parentNode.classList.add('hide'); + notebooks[i].getElementsByTagName('input')['i-'+i].classList.add('hide'); + forms[i] = notebooks[i].getElementsByTagName('form')[0]; + forms[i].getElementsByTagName('input')['color_rgb'].disabled = true; + forms[i].addEventListener('input', function () { + window.formchange = true; + console.log('adding change'); + }); + btns[i] = notebooks[i].getElementsByTagName('a')['edit-toggle-btn-'+i]; + btns[i].addEventListener('click', myFunc, false); + btns[i].t = notebooks[i].getElementsByTagName('h2')[0]; + btns[i].picker = notebooks[i].getElementsByTagName('fieldset')['color-picker-'+i]; + btns[i].fname = fname; + btns[i].form = forms[i]; + btns[i].url = forms[i]['action']; + function myFunc(e) { + e.preventDefault(); + edit_notebook(e.target, e.target.t, e.target.form, e.target.picker, e.target.fname, e.target.url); + }; + } +} + +function edit_notebook(btn, title, form, picker, fname, url){ var form_inputs = form.getElementsByTagName('input'); + console.log(picker); if (window.bookediting === false) { picker.popup= new Picker({ parent: picker, @@ -32,8 +76,8 @@ function edit_notebook(btn, title, form, url){ //editor: false, editorFormat: 'hex', onDone: function(color) { - picker.style.backgroundColor = color.rgbString; - document.getElementById('id_color_rgb').value = color.rgbString; + this.settings['parent'].style.backgroundColor = color.rgbString; + form_inputs['color_rgb'].value = color.rgbString; }, }); title.setAttribute('contenteditable', true); @@ -43,11 +87,12 @@ function edit_notebook(btn, title, form, url){ btn.classList.add('save'); window.bookediting = true; window.titlecontents = title.innerHTML; - window.colorcontent = document.getElementById('id_color_rgb').value + window.colorcontent = form_inputs['color_rgb'].value; } else { - if (window.titlecontents !== title.innerHTML || window.colorcontent !== document.getElementById('id_color_rgb').value || window.formchange) { - console.log("changed"); - form_inputs['name'].value = title.innerHTML; + if (window.titlecontents !== title.innerHTML || window.colorcontent !== form_inputs['color_rgb'].value || window.formchange) { + console.log('changed'); + console.log(form_inputs); + fname.value = title.innerHTML; //const data = formToJSON(form.elements); //console.log(JSON.stringify(data, null, ' ')); var request = new XMLHttpRequest(); @@ -78,6 +123,9 @@ function edit_notebook(btn, title, form, url){ } return false; } -if (typeof(document.getElementById('nb-edit-form')) != "undefined" && document.getElementById('nb-edit-form') != null) { +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('note-edit-form') === null) { + initNotebookCreator(); +} |