Skip to content

Commit 89bfd77

Browse files
committed
Skin down LokiHtmlReplacer a bit
1 parent c37f543 commit 89bfd77

2 files changed

Lines changed: 16 additions & 31 deletions

File tree

view/base/templates/script/ajax-queue.phtml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ if ($interval < 10) {
152152

153153
this.getTargets(requests).forEach(target => {
154154
const targetElement = document.getElementById(target);
155+
console.log('updating', target, targetElement);
156+
155157
const newTargetElement = ajaxDocument.getElementById(target);
156158

157159
if (!targetElement || !newTargetElement) {

view/base/templates/script/html-updater.phtml

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
11
<script>
22
const LokiHtmlReplacer = {
33
replace(root, incomingHTML) {
4-
if (!(root instanceof Element)) {
5-
throw new TypeError('`root` must be an Element');
4+
if (root.hasAttribute('x-ignore')) {
5+
return;
66
}
7-
if (root.hasAttribute('x-ignore')) return;
8-
9-
const incomingFrag = this._parseHTML(incomingHTML);
107

8+
const incomingFrag = this.parseHTML(incomingHTML);
119
const existingSkips = root.querySelectorAll('[x-ignore]');
10+
1211
existingSkips.forEach(oldEl => {
1312
const ancestor = oldEl.parentElement?.closest('[x-ignore]');
14-
if (ancestor && ancestor !== oldEl) return;
15-
16-
const key = oldEl.getAttribute('x-ignore');
17-
let counterpart = null;
13+
if (ancestor && ancestor !== oldEl) {
14+
return;
15+
}
1816

19-
if (key && key.length > 0) {
20-
counterpart = incomingFrag.querySelector(`[x-ignore="${this._cssEscape(key)}"]`);
21-
} else {
22-
const path = this._pathFromRoot(root, oldEl);
23-
counterpart = this._nodeByPath(incomingFrag, path);
24-
if (counterpart && !(counterpart instanceof Element && counterpart.hasAttribute('x-ignore'))) {
25-
counterpart = null;
26-
}
17+
const path = this.pathFromRoot(root, oldEl);
18+
let counterpart = this.nodeByPath(incomingFrag, path);
19+
if (counterpart && !(counterpart instanceof Element && counterpart.hasAttribute('x-ignore'))) {
20+
counterpart = null;
2721
}
2822

2923
if (counterpart) {
@@ -34,24 +28,13 @@
3428
root.replaceChildren(...incomingFrag.childNodes);
3529
},
3630

37-
_parseHTML(html) {
31+
parseHTML(html) {
3832
const tpl = document.createElement('template');
3933
tpl.innerHTML = String(html ?? '').trim();
4034
return tpl.content;
4135
},
4236

43-
_cssEscape(ident) {
44-
if (window.CSS && typeof window.CSS.escape === 'function') {
45-
return window.CSS.escape(ident);
46-
}
47-
return String(ident)
48-
.replace(/[\0-\x1F\x7F]/g, '\uFFFD')
49-
.replace(/(^-?\d)|[^a-zA-Z0-9_\u00A0-\uFFFF-]/g, (ch, d) =>
50-
d ? `\\3${d} ` : `\\${ch}`
51-
);
52-
},
53-
54-
_pathFromRoot(rootEl, el) {
37+
pathFromRoot(rootEl, el) {
5538
const path = [];
5639
let cur = el;
5740
while (cur && cur !== rootEl) {
@@ -69,7 +52,7 @@
6952
return path;
7053
},
7154

72-
_nodeByPath(rootLike, path) {
55+
nodeByPath(rootLike, path) {
7356
let node = rootLike;
7457
for (const idx of path) {
7558
const children = (node instanceof DocumentFragment)

0 commit comments

Comments
 (0)