Improved profile

This commit is contained in:
2017-07-03 17:21:00 +02:00
parent e6d18f2e1d
commit dd974ed99a
14 changed files with 180 additions and 92 deletions

View File

@ -76,7 +76,41 @@ export function load(arn: AnimeNotifier, element: HTMLElement) {
// Diff
export function diff(arn: AnimeNotifier, element: HTMLElement) {
let url = element.dataset.url || (element as HTMLAnchorElement).getAttribute("href")
arn.diff(url)
arn.diff(url).then(() => {
arn.requestIdleCallback(() => {
const duration = 300.0
const steps = 60
const interval = duration / steps
const fullSin = Math.PI / 2
const contentPadding = 25
let target = element
let scrollHandle: number
let oldScroll = arn.app.content.parentElement.scrollTop
let newScroll = Math.max(target.offsetTop - contentPadding, 0)
let scrollDistance = newScroll - oldScroll
let timeStart = performance.now()
let timeEnd = timeStart + duration
let scroll = () => {
let time = performance.now()
let progress = (time - timeStart) / duration
if(progress > 1.0) {
progress = 1.0
}
arn.app.content.parentElement.scrollTop = oldScroll + scrollDistance * Math.sin(progress * fullSin)
if(time >= timeEnd || arn.app.content.parentElement.scrollTop == newScroll) {
clearInterval(scrollHandle)
}
}
scrollHandle = setInterval(scroll, interval)
})
})
}
// Forum reply

View File

@ -44,10 +44,14 @@ export class AnimeNotifier {
document.addEventListener("keydown", this.onKeyDown.bind(this), false)
window.addEventListener("popstate", this.onPopState.bind(this))
this.requestIdleCallback(this.onIdle.bind(this))
}
requestIdleCallback(func: Function) {
if("requestIdleCallback" in window) {
window["requestIdleCallback"](this.onIdle.bind(this))
window["requestIdleCallback"](func)
} else {
this.onIdle()
func()
}
}
@ -194,6 +198,10 @@ export class AnimeNotifier {
unmountMountables() {
for(let element of findAll("mountable")) {
if(element.classList.contains("never-unmount")) {
continue
}
element.classList.remove("mounted")
}
}
@ -228,6 +236,10 @@ export class AnimeNotifier {
}
diff(url: string) {
if(url == this.app.currentPath) {
return
}
let request = fetch("/_" + url, {
credentials: "same-origin"
})