2018-11-15 22:53:52 +00:00
|
|
|
/// <reference path="User.ts" />
|
2018-11-07 21:00:16 +00:00
|
|
|
/// <reference path="Colour.ts" />
|
|
|
|
/// <reference path="Support.ts" />
|
2018-11-15 22:53:52 +00:00
|
|
|
/// <reference path="Permissions.ts" />
|
|
|
|
/// <reference path="Comments.ts" />
|
2018-12-09 03:42:38 +00:00
|
|
|
/// <reference path="Common.ts" />
|
2018-12-10 23:43:50 +00:00
|
|
|
/// <reference path="FormUtilities.ts" />
|
2018-12-30 22:07:32 +00:00
|
|
|
/// <reference path="UserRelations.ts" />
|
|
|
|
|
2018-11-06 22:55:05 +00:00
|
|
|
declare const timeago: any;
|
|
|
|
declare const hljs: any;
|
|
|
|
|
2018-11-07 21:00:16 +00:00
|
|
|
let loginFormAvatarTimeout: number = 0;
|
|
|
|
|
2018-11-06 22:55:05 +00:00
|
|
|
// Initialisation process.
|
|
|
|
window.addEventListener('load', () => {
|
|
|
|
timeago().render(document.querySelectorAll('time'));
|
|
|
|
hljs.initHighlighting();
|
|
|
|
|
2018-12-10 23:43:50 +00:00
|
|
|
initCSRF();
|
2018-11-15 22:53:52 +00:00
|
|
|
userInit();
|
2018-12-30 22:07:32 +00:00
|
|
|
userRelationsInit();
|
2018-11-07 21:00:16 +00:00
|
|
|
|
|
|
|
const changelogChangeAction: HTMLDivElement = document.querySelector('.changelog__change__action') as HTMLDivElement;
|
|
|
|
|
|
|
|
if (changelogChangeAction && !Support.sidewaysText) {
|
|
|
|
changelogChangeAction.title = "This is supposed to be sideways, but your browser doesn't support that.";
|
|
|
|
}
|
2018-11-06 22:55:05 +00:00
|
|
|
|
2018-11-15 22:02:57 +00:00
|
|
|
const loginForms: HTMLCollectionOf<HTMLFormElement> = document.getElementsByClassName('js-login-form') as HTMLCollectionOf<HTMLFormElement>;
|
2018-11-06 22:55:05 +00:00
|
|
|
|
2018-11-15 22:02:57 +00:00
|
|
|
if (loginForms.length > 0) {
|
|
|
|
for (let i = 0; i < loginForms.length; i++) {
|
|
|
|
const loginForm: HTMLFormElement = loginForms[i],
|
|
|
|
loginAvatar: HTMLElement = loginForm.getElementsByClassName('js-login-avatar')[0] as HTMLElement,
|
|
|
|
loginUsername: HTMLInputElement = loginForm.getElementsByClassName('js-login-username')[0] as HTMLInputElement;
|
2018-11-07 21:00:16 +00:00
|
|
|
|
2018-11-15 22:02:57 +00:00
|
|
|
// Initial bump, in case anything is prefilled.
|
|
|
|
loginFormUpdateAvatar(loginAvatar, loginUsername, true);
|
2018-11-07 21:00:16 +00:00
|
|
|
|
2018-11-15 22:02:57 +00:00
|
|
|
loginUsername.addEventListener('keyup', () => loginFormUpdateAvatar(loginAvatar, loginUsername));
|
|
|
|
}
|
2018-11-07 21:00:16 +00:00
|
|
|
}
|
2018-11-15 22:53:52 +00:00
|
|
|
|
|
|
|
commentsInit();
|
2018-11-06 22:55:05 +00:00
|
|
|
});
|
2018-11-07 21:00:16 +00:00
|
|
|
|
|
|
|
function loginFormUpdateAvatar(avatarElement: HTMLElement, usernameElement: HTMLInputElement, force: boolean = false): void {
|
|
|
|
if (!force) {
|
|
|
|
if (loginFormAvatarTimeout)
|
|
|
|
return;
|
|
|
|
|
|
|
|
loginFormAvatarTimeout = setTimeout(() => {
|
|
|
|
loginFormUpdateAvatar(avatarElement, usernameElement, true);
|
|
|
|
clearTimeout(loginFormAvatarTimeout);
|
|
|
|
loginFormAvatarTimeout = 0;
|
|
|
|
}, 750);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const xhr: XMLHttpRequest = new XMLHttpRequest;
|
|
|
|
xhr.addEventListener('readystatechange', () => {
|
|
|
|
if (xhr.readyState !== 4)
|
|
|
|
return;
|
|
|
|
|
|
|
|
avatarElement.style.backgroundImage = `url('/profile.php?m=avatar&u=${xhr.responseText}')`;
|
|
|
|
});
|
|
|
|
xhr.open('GET', `/auth.php?m=get_user&u=${encodeURI(usernameElement.value)}`);
|
|
|
|
xhr.send();
|
|
|
|
}
|
2019-01-22 16:38:20 +00:00
|
|
|
|
|
|
|
interface MessageBoxButton {
|
|
|
|
text: string;
|
|
|
|
callback: Function;
|
|
|
|
}
|
|
|
|
|
|
|
|
function messageBox(text: string, title: string = null, buttons: MessageBoxButton[] = []): boolean
|
|
|
|
{
|
|
|
|
if (document.querySelector('.messagebox')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const element = document.createElement('div');
|
|
|
|
element.className = 'messagebox';
|
|
|
|
|
|
|
|
const container = element.appendChild(document.createElement('div'));
|
|
|
|
container.className = 'container messagebox__container';
|
|
|
|
|
|
|
|
const titleElement = container.appendChild(document.createElement('div')),
|
|
|
|
titleBackground = titleElement.appendChild(document.createElement('div')),
|
|
|
|
titleText = titleElement.appendChild(document.createElement('div'));
|
|
|
|
|
|
|
|
titleElement.className = 'container__title';
|
|
|
|
titleBackground.className = 'container__title__background';
|
|
|
|
titleText.className = 'container__title__text';
|
|
|
|
titleText.textContent = title || 'Information';
|
|
|
|
|
|
|
|
const textElement = container.appendChild(document.createElement('div'));
|
|
|
|
textElement.className = 'container__content';
|
|
|
|
textElement.textContent = text;
|
|
|
|
|
|
|
|
const buttonsContainer = container.appendChild(document.createElement('div'));
|
|
|
|
buttonsContainer.className = 'messagebox__buttons';
|
|
|
|
|
|
|
|
if (buttons.length < 1) {
|
|
|
|
const okButton = buttonsContainer.appendChild(document.createElement('button'));
|
|
|
|
okButton.className = 'input__button';
|
|
|
|
okButton.textContent = 'OK';
|
|
|
|
okButton.addEventListener('click', () => element.remove());
|
|
|
|
} else {
|
|
|
|
for (let i = 0; i < buttons.length; i++) {
|
|
|
|
let button = buttonsContainer.appendChild(document.createElement('button'));
|
|
|
|
button.className = 'input__button';
|
|
|
|
button.textContent = buttons[i].text;
|
|
|
|
button.addEventListener('click', () => {
|
|
|
|
element.remove();
|
|
|
|
buttons[i].callback();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
document.body.appendChild(element);
|
|
|
|
return true;
|
|
|
|
}
|