From: Mischa POSLAWSKY Date: Mon, 7 Dec 2020 14:25:29 +0000 (+0100) Subject: edit/page: common retrieval of contents element X-Git-Tag: v5.0~33 X-Git-Url: http://git.shiar.nl/minimedit.git/commitdiff_plain/9c6f7860bd137aff83ad9038839089c150974ea3 edit/page: common retrieval of contents element --- diff --git a/edit/page.js b/edit/page.js index 0566bcf..35497c1 100644 --- a/edit/page.js +++ b/edit/page.js @@ -1,5 +1,9 @@ var pagebody; +function editorcontents() { + return document.getElementsByClassName('static')[0]; +} + function editorsetup() { CKEDITOR.disableAutoInline = true; @@ -167,8 +171,7 @@ if (pagebody) { editlink.style.fontWeight = 'bold'; editlink.href = ''; editlink.onclick = undefined; - var dynpage = document.getElementsByClassName('static')[0]; - document.body.replaceChild(pagebody, dynpage); + document.body.replaceChild(pagebody, editorcontents()); pagebody.setAttribute('contenteditable', true); pagebody.querySelectorAll('[data-dyn]').forEach(function (el) { let blockname = el.getAttribute('data-dyn'); @@ -190,7 +193,7 @@ if (pagebody) { } document.addEventListener('DOMContentLoaded', function (e) { - pagebody = document.getElementsByClassName('static')[0].cloneNode(true); + pagebody = editorcontents().cloneNode(true); var editorinc = document.createElement('script'); editorinc.addEventListener('load', editorsetup); editorinc.src = ckesrc;