X-Git-Url: http://git.shiar.net/minimedit.git/blobdiff_plain/8da4e3db153de18c026cc8dda79bdc0947663c8a..2573a637bff34caeb3de0f3489c0c6dfbf6d2a1d:/edit/page.js diff --git a/edit/page.js b/edit/page.js index d1f16bf..35497c1 100644 --- a/edit/page.js +++ b/edit/page.js @@ -1,3 +1,13 @@ +var pagebody; + +function editorcontents() { + return document.getElementsByClassName('static')[0]; +} + +function editorsetup() { + +CKEDITOR.disableAutoInline = true; + CKEDITOR.plugins.add('inlinesave', { init: function(editor) { editor.addCommand( 'inlinesave', { @@ -153,17 +163,15 @@ CKEDITOR.on('instanceCreated', function (event) { }; }); - CKEDITOR.disableAutoInline = true; - -// add edit link to menu -var pagebody = document.getElementsByClassName('static')[0]; if (pagebody) { + // add edit link to menu var editlink = document.querySelector('a[href="#edit"]'); if (editlink) editlink.onclick = function (e) { editlink.style.fontWeight = 'bold'; editlink.href = ''; editlink.onclick = undefined; + document.body.replaceChild(pagebody, editorcontents()); pagebody.setAttribute('contenteditable', true); pagebody.querySelectorAll('[data-dyn]').forEach(function (el) { let blockname = el.getAttribute('data-dyn'); @@ -182,3 +190,12 @@ if (pagebody) { } } +} + +document.addEventListener('DOMContentLoaded', function (e) { + pagebody = editorcontents().cloneNode(true); + var editorinc = document.createElement('script'); + editorinc.addEventListener('load', editorsetup); + editorinc.src = ckesrc; + document.getElementsByTagName('head')[0].appendChild(editorinc); +});