-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathBootstrapFrontend.ts
More file actions
171 lines (153 loc) · 5.37 KB
/
BootstrapFrontend.ts
File metadata and controls
171 lines (153 loc) · 5.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/**
* Bootstraps WCF's JavaScript with additions for the frontend usage.
*
* @author Alexander Ebert
* @copyright 2001-2019 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*/
import * as BackgroundQueue from "./BackgroundQueue";
import * as Bootstrap from "./Bootstrap";
import * as UiUserIgnore from "./Ui/User/Ignore";
import * as UiPageHeaderMenu from "./Ui/Page/Header/Menu";
import * as UiMessageUserConsent from "./Ui/Message/UserConsent";
import * as UiMessageShareDialog from "./Ui/Message/Share/Dialog";
import { addShareProviders, ShareProvider } from "./Ui/Message/Share/Providers";
import * as UiFeedDialog from "./Ui/Feed/Dialog";
import User from "./User";
import UiPageMenuMainFrontend from "./Ui/Page/Menu/Main/Frontend";
import { whenFirstSeen } from "./LazyLoader";
import { prepareRequest } from "./Ajax/Backend";
import { setup as serviceWorkerSetup } from "./Notification/ServiceWorker";
import { getArticlePopover } from "./Api/Articles/GetArticlePopover";
import { getUserPopover } from "./Api/Users/GetUserPopover";
interface BootstrapOptions {
backgroundQueue: {
url: string;
force: boolean;
};
serviceWorker?: {
publicKey: string;
serviceWorkerJsUrl: string;
registerUrl: string;
notificationLastReadTime: number;
};
dynamicColorScheme: boolean;
executeCronjobs: string | undefined;
shareButtonProviders?: ShareProvider[];
styleChanger: boolean;
removeQuotes?: string[];
usedQuotes?: Map<string, string[]>;
reportEndpoint: string;
}
/**
* Initializes user profile popover.
*/
function setupUserPopover(): void {
whenFirstSeen(".userLink", () => {
void import("./Component/Popover").then(({ setupFor }) => {
setupFor({
endpoint: (objectId) => getUserPopover(objectId).then((response) => response.template),
identifier: "com.woltlab.wcf.user",
selector: ".userLink",
});
});
});
}
function setupArticlePopover(): void {
whenFirstSeen(".articleLink", () => {
void import("WoltLabSuite/Core/Component/Popover").then(({ setupFor }) => {
setupFor({
endpoint: (objectId) => getArticlePopover(objectId).then((response) => response.template),
identifier: "com.woltlab.wcf.article",
selector: ".articleLink",
});
});
});
}
declare const COMPILER_TARGET_DEFAULT: boolean;
/**
* Bootstraps general modules and frontend exclusive ones.
*/
export function setup(options: BootstrapOptions): void {
// Modify the URL of the background queue URL to always target the current domain to avoid CORS.
options.backgroundQueue.url = window.WSC_API_URL + options.backgroundQueue.url.substr(window.WCF_PATH.length);
Bootstrap.setup({
dynamicColorScheme: options.dynamicColorScheme,
enableMobileMenu: true,
pageMenuMainProvider: new UiPageMenuMainFrontend(),
});
if (options.removeQuotes?.length) {
void import("./Component/Quote/Storage").then(({ removeQuotes }) => removeQuotes(options.removeQuotes!));
}
if (options.usedQuotes?.size) {
void import("./Component/Quote/Storage").then(({ markQuoteAsUsed }) => {
options.usedQuotes!.forEach((uuids, editorId) => {
for (const uuid of uuids) {
markQuoteAsUsed(editorId, uuid);
}
});
});
}
UiPageHeaderMenu.init();
if (options.styleChanger) {
void import("./Controller/Style/Changer").then((ControllerStyleChanger) => {
ControllerStyleChanger.setup();
});
}
setupUserPopover();
setupArticlePopover();
if (options.executeCronjobs !== undefined) {
void prepareRequest(options.executeCronjobs)
.get()
.disableLoadingIndicator()
.fetchAsResponse()
.catch(() => {
/* Ignore errors. */
});
}
BackgroundQueue.setUrl(options.backgroundQueue.url);
if (Math.random() < 0.1 || options.backgroundQueue.force) {
// invoke the queue roughly every 10th request or on demand
BackgroundQueue.invoke();
}
if (COMPILER_TARGET_DEFAULT) {
UiUserIgnore.init();
}
UiMessageUserConsent.init();
if (options.shareButtonProviders) {
addShareProviders(options.shareButtonProviders);
}
UiMessageShareDialog.setup();
if (User.userId) {
UiFeedDialog.setup();
if (options.serviceWorker) {
serviceWorkerSetup(
options.serviceWorker.publicKey,
options.serviceWorker.serviceWorkerJsUrl,
options.serviceWorker.registerUrl,
options.serviceWorker.notificationLastReadTime,
);
}
}
whenFirstSeen("woltlab-core-reaction-summary", () => {
void import("./Ui/Reaction/SummaryDetails").then(({ setup }) => setup());
});
whenFirstSeen("woltlab-core-comment", () => {
void import("./Component/Comment/woltlab-core-comment");
});
whenFirstSeen("woltlab-core-comment-response", () => {
void import("./Component/Comment/Response/woltlab-core-comment-response");
});
whenFirstSeen("[data-follow-user]", () => {
void import("./Component/User/Follow").then(({ setup }) => setup());
});
whenFirstSeen("[data-ignore-user]", () => {
void import("./Component/User/Ignore").then(({ setup }) => setup());
});
whenFirstSeen("[data-report-content]", () => {
void import("./Ui/Moderation/Report").then(({ setup }) => setup(options.reportEndpoint));
});
whenFirstSeen("[data-reaction-object-type]", () => {
void import("./Component/Reaction/Button").then(({ setup }) => setup());
});
}