handle url hash changes
This commit is contained in:
parent
b725012631
commit
a7b0df7254
3 changed files with 20 additions and 16 deletions
|
@ -61,8 +61,8 @@ namespace NP
|
|||
}
|
||||
|
||||
// Shorthand for the first element of getElementsByClassName
|
||||
public static Class(className: string): NodeListOf<HTMLElement> {
|
||||
return <NodeListOf<HTMLElement>>document.getElementsByClassName(className);
|
||||
public static Class(className: string): NodeListOf<Element> {
|
||||
return <NodeListOf<Element>>document.getElementsByClassName(className);
|
||||
}
|
||||
|
||||
// Shorthand for prepending
|
||||
|
|
|
@ -1,13 +1,4 @@
|
|||
window.addEventListener("load", () => {
|
||||
var user: string = location.hash.substring(2);
|
||||
|
||||
NP.UI.RegisterHooks();
|
||||
|
||||
if (user.length < 1) {
|
||||
NP.UI.Mode(NP.Mode.INDEX);
|
||||
NP.UI.Background(NP.Background.COLOURFADE);
|
||||
} else {
|
||||
NP.UI.Mode(NP.Mode.USER);
|
||||
NP.Watcher.Start(user);
|
||||
}
|
||||
NP.UI.Update();
|
||||
});
|
||||
|
|
|
@ -87,19 +87,32 @@ namespace NP
|
|||
}
|
||||
}
|
||||
|
||||
public static RegisterHooks(): void {
|
||||
UI.InfoBack.addEventListener('click', () => {
|
||||
public static Update(): void {
|
||||
var user: string = location.hash.substring(2);
|
||||
|
||||
if (user.length > 0) {
|
||||
Watcher.Start(user);
|
||||
UI.Mode(Mode.USER);
|
||||
} else {
|
||||
Watcher.Stop();
|
||||
UI.Mode(Mode.INDEX);
|
||||
NP.UI.Background(NP.Background.COLOURFADE);
|
||||
UI.Background(Background.COLOURFADE);
|
||||
}
|
||||
}
|
||||
|
||||
public static RegisterHooks(): void {
|
||||
UI.InfoBack.addEventListener('click', () => {
|
||||
location.hash = '';
|
||||
});
|
||||
|
||||
var enter: Function = () => {
|
||||
location.hash = '#/' + UI.FormUsername.value;
|
||||
Watcher.Start(UI.FormUsername.value);
|
||||
};
|
||||
|
||||
window.addEventListener('hashchange', () => {
|
||||
UI.Update();
|
||||
});
|
||||
|
||||
UI.FormSubmit.addEventListener('click', () => {
|
||||
enter.call(this);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue