From 647aed0e76f6246740279887d0e1339ae0abd7c0 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Wed, 19 Jul 2017 04:47:32 +0200 Subject: [PATCH] Improved diff --- pages/animelist/animelist.pixy | 4 ++-- scripts/Application.ts | 2 +- scripts/Diff.ts | 42 +++++++++++++++++++--------------- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/pages/animelist/animelist.pixy b/pages/animelist/animelist.pixy index 95ccb1c3..4b26c19e 100644 --- a/pages/animelist/animelist.pixy +++ b/pages/animelist/animelist.pixy @@ -43,8 +43,8 @@ component AnimeList(animeList *arn.AnimeList, viewUser *arn.User, user *arn.User td.anime-list-item-name a.ajax(href=item.Link(animeList.User().Nick))= item.Anime().Title.Canonical - if user != nil && item.Status == arn.AnimeListStatusWatching && item.Anime().EpisodeByNumber(item.Episodes + 1) != nil - td.anime-list-item-actions + td.anime-list-item-actions + if user != nil && item.Status == arn.AnimeListStatusWatching && item.Anime().EpisodeByNumber(item.Episodes + 1) != nil for _, link := range item.Anime().EpisodeByNumber(item.Episodes + 1).Links a(href=link, title="Watch episode " + toString(item.Episodes + 1) + " on twist.moe", target="_blank", rel="noopener") RawIcon("eye") diff --git a/scripts/Application.ts b/scripts/Application.ts index d1d30bd5..3e041285 100644 --- a/scripts/Application.ts +++ b/scripts/Application.ts @@ -152,7 +152,7 @@ export class Application { for(let i = 0; i < links.length; i++) { let link = links[i] as HTMLElement - link.classList.remove(this.ajaxClass) + // link.classList.remove(this.ajaxClass) let self = this link.onclick = function(e) { diff --git a/scripts/Diff.ts b/scripts/Diff.ts index 974a0450..6fa223c0 100644 --- a/scripts/Diff.ts +++ b/scripts/Diff.ts @@ -82,29 +82,35 @@ export class Diff { for(let x = 0; x < elemB.attributes.length; x++) { let attrib = elemB.attributes[x] - if(attrib.specified) { - // Skip mountables - if(attrib.name == "class") { - let classesA = elemA.classList - let classesB = elemB.classList - - for(let className of classesA) { - if(!classesB.contains(className) && !Diff.persistentClasses.has(className)) { - classesA.remove(className) - } - } - - for(let className of classesB) { - if(!classesA.contains(className)) { - classesA.add(className) - } - } + if(!attrib.specified) { + continue + } + if(attrib.name === "class") { + // If the class is exactly the same, skip this attribute. + if(elemA.getAttribute("class") === attrib.value) { continue } - elemA.setAttribute(attrib.name, elemB.getAttribute(attrib.name)) + let classesA = elemA.classList + let classesB = elemB.classList + + for(let className of classesA) { + if(!classesB.contains(className) && !Diff.persistentClasses.has(className)) { + classesA.remove(className) + } + } + + for(let className of classesB) { + if(!classesA.contains(className)) { + classesA.add(className) + } + } + + continue } + + elemA.setAttribute(attrib.name, elemB.getAttribute(attrib.name)) } // Special case: Apply state of input elements