function buildComponent(tag, id, html){ var el = document.createElement(tag.toLowerCase()); if(id) el.id = id; if(typeof html === 'string') el.innerHTML = html; if(typeof html === 'object') el.appendChild(html); return el; }; function getJSONFromDjango(method, url, callback, data) { var data = data || null var request = new XMLHttpRequest(); var csrftoken = getCookie('csrftoken'); request.addEventListener('load', callback.bind(null, request)); request.open(method, url, true); request.setRequestHeader('X-CSRFToken', csrftoken); request.onerror = function() { console.log('error on request'); }; //create a modal to let the user know we're saving var saveModal = document.createElement('div'); var loader = document.createElement('div'); loader.classList.add('loader'); saveModal.appendChild(loader); saveModal.close = false; //no close button saveModal.modalHed = "Saving changes"; //modal text content saveModal.wrapperClass = 'loading'; //add a wrapper class to the modal for styling var modal = modalBox(saveModal); request.send(data); } // hijack a form and submit with ajax function ajaxHijack(form, func) { form.onsubmit = function(e) { e.preventDefault(); func(e.target); return false; } } //global init for Color Picker function initColorPicker(form){ var notebook_form_inputs = form.getElementsByTagName('input'); var p = form.getElementsByTagName('fieldset')['color-picker']; //document.getElementById('js-novi-backdrop').removeEventListener("click", handleMouseDown, true); p.classList.add('top'); p.popup = p.popup || new Picker({ parent: p, 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; }, }); } function get_login_form() { getJSON('GET', '/login/', function(e){ console.log(e); }); } //first define your getCookie function function getCookie(cname) { var name = cname + "="; var decodedCookie = decodeURIComponent(document.cookie); var ca = decodedCookie.split(';'); for(var i = 0; i (
|||\s+|\r)<\/p>$/gm; return re.test(commentText); }; function addNotebookModal(notebookAddForm, btn) { initColorPicker(notebookAddForm); ajaxHijack(notebookAddForm, notebookCreate) btn.content = notebookAddForm.parentNode; addHandler(btn); function addHandler(el){ el.addEventListener('click', function(e){ e.preventDefault(); var modalContent = e.target.content; modalContent.wrapperClass = 'overlay'; //add a wrapper class to the modal for styling var modal = modalBox(modalContent, el); }); } }