Removed ajax class requirement

This commit is contained in:
Eduard Urbach 2018-03-23 21:29:28 +01:00
parent b3f18437db
commit 5e4afa9748
4 changed files with 27 additions and 12 deletions

View File

@ -84,7 +84,7 @@ component SidebarButton(name string, target string, icon string)
span.sidebar-text= name
component SidebarButtonNoAJAX(name string, target string, icon string)
a.sidebar-link(href=target, aria-label=name, data-bubble="true")
a.sidebar-link(href=target, aria-label=name, data-bubble="true", data-ajax="false")
.sidebar-button
Icon(icon)
span.sidebar-text= name

View File

@ -1,9 +1,9 @@
component Login(target string)
.login-buttons.mountable
a.login-button.login-button-google(href="/auth/google", target=target)
a.login-button.login-button-google(href="/auth/google", target=target, data-ajax="false")
Icon("google")
span Sign in via Google
a.login-button.login-button-facebook(href="/auth/facebook", target=target)
a.login-button.login-button-facebook(href="/auth/facebook", target=target, data-ajax="false")
Icon("facebook")
span Sign in via Facebook

View File

@ -246,7 +246,7 @@ component SettingsAccounts(user *arn.User)
.widget-section.social-account
label(for="google") Google:
a#google.button.social-account-button(href="/auth/google")
a#google.button.social-account-button(href="/auth/google", data-ajax="false")
if user.Accounts.Google.ID != ""
Icon("check")
span Connected
@ -257,7 +257,7 @@ component SettingsAccounts(user *arn.User)
.widget-section.social-account
label(for="facebook") Facebook:
a#facebook.button.social-account-button(href="/auth/facebook")
a#facebook.button.social-account-button(href="/auth/facebook", data-ajax="false")
if user.Accounts.Facebook.ID != ""
Icon("check")
span Connected

View File

@ -6,7 +6,6 @@ class LoadOptions {
}
export class Application {
ajaxClass: string
fadeOutClass: string
activeLinkClass: string
content: HTMLElement
@ -18,7 +17,6 @@ export class Application {
constructor() {
this.currentPath = window.location.pathname
this.originalPath = window.location.pathname
this.ajaxClass = "ajax"
this.activeLinkClass = "active"
this.fadeOutClass = "fade-out"
}
@ -150,10 +148,25 @@ export class Application {
element = document.body
}
let links = element.querySelectorAll("." + this.ajaxClass)
let links = element.getElementsByTagName("a")
for(let i = 0; i < links.length; i++) {
let link = links[i] as HTMLElement
let link = links[i] as HTMLAnchorElement
// Don't ajaxify links to a different host
if(link.hostname !== window.location.hostname) {
if(!link.target) {
link.target = "_blank"
}
continue
}
// Don't ajaxify links with a target or links that disable ajax specifically
if(link.target.length > 0 || link.dataset.ajax === "false") {
continue
}
let self = this
link.onclick = function(e) {
@ -179,9 +192,11 @@ export class Application {
scrollToTop() {
let parent : HTMLElement | null = this.content
Diff.mutations.queue(() => {
while(parent = parent.parentElement) {
parent.scrollTop = 0
}
})
}
emit(eventName: string) {