Heavily improved page reload

This commit is contained in:
Eduard Urbach 2017-07-19 09:09:55 +02:00
parent 80264f91b8
commit cd6641cc06
3 changed files with 14 additions and 5 deletions

View File

@ -36,6 +36,9 @@ export class AnimeNotifier {
Diff.persistentClasses.add("mounted") Diff.persistentClasses.add("mounted")
Diff.persistentClasses.add("image-found") Diff.persistentClasses.add("image-found")
// Never remove src property on diffs
Diff.persistentAttributes.add("src")
if("IntersectionObserver" in window) { if("IntersectionObserver" in window) {
// Enable lazy load // Enable lazy load
this.visibilityObserver = new IntersectionObserver( this.visibilityObserver = new IntersectionObserver(
@ -374,10 +377,10 @@ export class AnimeNotifier {
loading(isLoading: boolean) { loading(isLoading: boolean) {
if(isLoading) { if(isLoading) {
document.body.style.cursor = "progress" document.documentElement.style.cursor = "progress"
this.app.loading.classList.remove(this.app.fadeOutClass) this.app.loading.classList.remove(this.app.fadeOutClass)
} else { } else {
document.body.style.cursor = "auto" document.documentElement.style.cursor = "auto"
this.app.loading.classList.add(this.app.fadeOutClass) this.app.loading.classList.add(this.app.fadeOutClass)
} }
} }

View File

@ -1,5 +1,6 @@
export class Diff { export class Diff {
static persistentClasses = new Set<string>() static persistentClasses = new Set<string>()
static persistentAttributes = new Set<string>()
// Reuse container for diffs to avoid memory allocation // Reuse container for diffs to avoid memory allocation
static container: HTMLElement static container: HTMLElement
@ -22,7 +23,9 @@ export class Diff {
} }
Diff.rootContainer.innerHTML = html.replace("<!DOCTYPE html>", "") Diff.rootContainer.innerHTML = html.replace("<!DOCTYPE html>", "")
Diff.childNodes(aRoot, Diff.rootContainer) console.log(aRoot.getElementsByTagName("body")[0])
console.log(Diff.rootContainer.getElementsByTagName("body")[0])
Diff.childNodes(aRoot.getElementsByTagName("body")[0], Diff.rootContainer.getElementsByTagName("body")[0])
} }
// childNodes diffs the child nodes of 2 given elements and applies DOM mutations. // childNodes diffs the child nodes of 2 given elements and applies DOM mutations.
@ -80,7 +83,7 @@ export class Diff {
let attrib = elemA.attributes[x] let attrib = elemA.attributes[x]
if(attrib.specified) { if(attrib.specified) {
if(!elemB.hasAttribute(attrib.name)) { if(!elemB.hasAttribute(attrib.name) && !Diff.persistentAttributes.has(attrib.name)) {
removeAttributes.push(attrib) removeAttributes.push(attrib)
} }
} }

View File

@ -4,4 +4,7 @@ import { AnimeNotifier } from "./AnimeNotifier"
let app = new Application() let app = new Application()
let arn = new AnimeNotifier(app) let arn = new AnimeNotifier(app)
arn.init() arn.init()
// For debugging purposes
window["arn"] = arn