Fixed diffs

This commit is contained in:
Eduard Urbach 2017-07-19 04:04:19 +02:00
parent 6e46c8950a
commit 1d3d069766

View File

@ -21,6 +21,7 @@ export class Diff {
for(let i = 0; i < numNodes; i++) { for(let i = 0; i < numNodes; i++) {
let a = aChild[i] let a = aChild[i]
// Remove nodes at the end of a that do not exist in b
if(i >= bChild.length) { if(i >= bChild.length) {
aRoot.removeChild(a) aRoot.removeChild(a)
continue continue
@ -28,34 +29,31 @@ export class Diff {
let b = bChild[i] let b = bChild[i]
// If a doesn't have that many nodes, simply append at the end of a
if(i >= aChild.length) { if(i >= aChild.length) {
aRoot.appendChild(b) aRoot.appendChild(b)
continue continue
} }
// If it's a completely different HTML tag or node type, replace it
if(a.nodeName !== b.nodeName || a.nodeType !== b.nodeType) { if(a.nodeName !== b.nodeName || a.nodeType !== b.nodeType) {
aRoot.replaceChild(b, a) aRoot.replaceChild(b, a)
continue continue
} }
// Text node:
// We don't need to check for b to be a text node as well because
// we eliminated different node types in the previous condition.
if(a.nodeType === Node.TEXT_NODE) { if(a.nodeType === Node.TEXT_NODE) {
a.textContent = b.textContent a.textContent = b.textContent
continue continue
} }
// HTML element:
if(a.nodeType === Node.ELEMENT_NODE) { if(a.nodeType === Node.ELEMENT_NODE) {
let elemA = a as HTMLElement let elemA = a as HTMLElement
let elemB = b as HTMLElement let elemB = b as HTMLElement
// Ignore lazy images if they have the same source
if(elemA.classList.contains("lazy") && elemB.classList.contains("lazy")) {
if(elemA.dataset.src !== elemB.dataset.src) {
elemA.dataset.src = elemB.dataset.src
elemA.title = elemB.title
}
continue
}
// Skip iframes // Skip iframes
// This part needs to be executed AFTER lazy images check // This part needs to be executed AFTER lazy images check
// to allow lazily loaded iframes to update their data src. // to allow lazily loaded iframes to update their data src.
@ -84,7 +82,7 @@ export class Diff {
if(attrib.specified) { if(attrib.specified) {
// Skip mountables // Skip mountables
if(attrib.name == "class" && elemA.classList.contains("mounted")) { if(attrib.name == "class" && (elemA.classList.contains("mounted") || elemA.classList.contains("image-found"))) {
continue continue
} }