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 span.sidebar-text= name
component SidebarButtonNoAJAX(name string, target string, icon string) 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 .sidebar-button
Icon(icon) Icon(icon)
span.sidebar-text= name span.sidebar-text= name

View File

@ -1,9 +1,9 @@
component Login(target string) component Login(target string)
.login-buttons.mountable .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") Icon("google")
span Sign in via 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") Icon("facebook")
span Sign in via Facebook span Sign in via Facebook

View File

@ -246,7 +246,7 @@ component SettingsAccounts(user *arn.User)
.widget-section.social-account .widget-section.social-account
label(for="google") Google: 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 != "" if user.Accounts.Google.ID != ""
Icon("check") Icon("check")
span Connected span Connected
@ -257,7 +257,7 @@ component SettingsAccounts(user *arn.User)
.widget-section.social-account .widget-section.social-account
label(for="facebook") Facebook: 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 != "" if user.Accounts.Facebook.ID != ""
Icon("check") Icon("check")
span Connected span Connected

View File

@ -6,7 +6,6 @@ class LoadOptions {
} }
export class Application { export class Application {
ajaxClass: string
fadeOutClass: string fadeOutClass: string
activeLinkClass: string activeLinkClass: string
content: HTMLElement content: HTMLElement
@ -18,7 +17,6 @@ export class Application {
constructor() { constructor() {
this.currentPath = window.location.pathname this.currentPath = window.location.pathname
this.originalPath = window.location.pathname this.originalPath = window.location.pathname
this.ajaxClass = "ajax"
this.activeLinkClass = "active" this.activeLinkClass = "active"
this.fadeOutClass = "fade-out" this.fadeOutClass = "fade-out"
} }
@ -150,10 +148,25 @@ export class Application {
element = document.body element = document.body
} }
let links = element.querySelectorAll("." + this.ajaxClass) let links = element.getElementsByTagName("a")
for(let i = 0; i < links.length; i++) { 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 let self = this
link.onclick = function(e) { link.onclick = function(e) {
@ -179,9 +192,11 @@ export class Application {
scrollToTop() { scrollToTop() {
let parent : HTMLElement | null = this.content let parent : HTMLElement | null = this.content
Diff.mutations.queue(() => {
while(parent = parent.parentElement) { while(parent = parent.parentElement) {
parent.scrollTop = 0 parent.scrollTop = 0
} }
})
} }
emit(eventName: string) { emit(eventName: string) {