-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin-editor.php
More file actions
67 lines (54 loc) · 1.99 KB
/
admin-editor.php
File metadata and controls
67 lines (54 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Editor</title>
</head>
<body>
<div class="content-block" id="editor-title">
<h1>Editor</h1>
</div>
<div class="content-block" id="editor-nav">
</div>
<div class="content-block" id="editor-content" style="padding: 0;">
<h1>Content</h>
</div>
<script>
loadEditorPage();
function loadEditorPage() {
pageName = localStorage.getItem('editor-pane-name');
const content = document.getElementById('editor-content');
// Tell browser this is the current page
history.pushState({ path: pageName }, "", "frame.html");
fetch(pageName)
.then(res => {
if (!res.ok) throw new Error(`Failed to load ${pageName}`);
return res.text();
})
.then(html => {
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
// Set container content WITHOUT script tags
// We remove scripts first so they don't get ignored inside innerHTML
const scripts = doc.querySelectorAll('script');
scripts.forEach(s => s.remove());
content.innerHTML = doc.body.innerHTML;
// Now add and execute scripts manually
scripts.forEach(oldScript => {
const newScript = document.createElement('script');
if (oldScript.src) {
newScript.src = oldScript.src;
newScript.async = false; // to preserve execution order
} else {
newScript.textContent = oldScript.textContent;
}
content.appendChild(newScript); // append inside content container
});
})
.catch(err => {
content.innerHTML = `<p style="color:red;">${err.message}</p>`;
});
}
</script>
</body>
</html>