From 07b89560739b0aff147576b7abc66816b874599c Mon Sep 17 00:00:00 2001 From: fabioswartz Date: Fri, 30 Dec 2016 11:36:28 +0000 Subject: [PATCH] Cleaning editor.js --- _embed/public/js/editor.js | 41 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/_embed/public/js/editor.js b/_embed/public/js/editor.js index f4b52df5..2c3b509d 100644 --- a/_embed/public/js/editor.js +++ b/_embed/public/js/editor.js @@ -41,18 +41,17 @@ function addFrontMatterItem(event) { let fieldID = id + "[]", input = fieldID, count = block.querySelectorAll('.group > div').length; - + input = input.replace(/\[/, '\\['); input = input.replace(/\]/, '\\]'); let fieldsets = block.getElementsByTagName("fieldset"); if (fieldsets.length > 0) { - let newtype = fieldsets[0].dataset.type; - let bid = id + "[" + fieldsets.length + "]"; - let name = fieldsets.length; - - let template = `
+ let newtype = fieldsets[0].dataset.type, + bid = id + "[" + fieldsets.length + "]", + name = fieldsets.length, + template = `

${name}

add @@ -94,8 +93,8 @@ function addFrontMatterItem(event) { block.querySelector('.delete').insertAdjacentHTML('afterend', template); } - let temp = document.getElementById(tempID); - let input = temp.querySelector('input'); + let temp = document.getElementById(tempID), + input = temp.querySelector('input'); input.focus(); input.addEventListener('keydown', (event) => { if (event.keyCode == 27) { @@ -112,8 +111,8 @@ function addFrontMatterItem(event) { return true; } - let name = value.substring(0, value.lastIndexOf(':')); - let newtype = value.substring(value.lastIndexOf(':') + 1, value.length); + let name = value.substring(0, value.lastIndexOf(':')), + newtype = value.substring(value.lastIndexOf(':') + 1, value.length); if (newtype !== "" && newtype !== "array" && newtype !== "object") { name = value; } @@ -180,15 +179,15 @@ function addFrontMatterItem(event) { document.addEventListener("DOMContentLoaded", (event) => { textareaAutoGrow(); - let container = document.getElementById('editor'); - let button = document.querySelector('#submit span:first-child'); - let kind = container.dataset.kind; + let container = document.getElementById('editor'), + button = document.querySelector('#submit span:first-child'), + kind = container.dataset.kind; if (kind != 'frontmatter-only') { - let editor = document.getElementById('editor-source'); - let mode = editor.dataset.mode; - let textarea = document.querySelector('textarea[name="content"]'); - let aceEditor = ace.edit('editor-source'); + let editor = document.getElementById('editor-source'), + mode = editor.dataset.mode, + textarea = document.querySelector('textarea[name="content"]'), + aceEditor = ace.edit('editor-source'); aceEditor.getSession().setMode("ace/mode/" + mode); aceEditor.getSession().setValue(textarea.value); aceEditor.getSession().on('change', function() { @@ -225,11 +224,11 @@ document.addEventListener("DOMContentLoaded", (event) => { data.content = data.content.toString(); } - let html = button.changeToLoading(); - let request = new XMLHttpRequest(); + let html = button.changeToLoading(), + request = new XMLHttpRequest(); + request.open("PUT", toWebDavURL(window.location.pathname)); request.setRequestHeader('Kind', kind); - request.send(JSON.stringify(data)); request.onreadystatechange = function() { if (request.readyState == 4) { @@ -255,4 +254,4 @@ document.addEventListener("DOMContentLoaded", (event) => { }); return false; -}); \ No newline at end of file +});