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