Add content selection before removing content
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / js / WoltLabSuite / Core / BootstrapFrontend.js
CommitLineData
5d5ef727
AE
1/**
2 * Bootstraps WCF's JavaScript with additions for the frontend usage.
3 *
4 * @author Alexander Ebert
c839bd49 5 * @copyright 2001-2018 WoltLab GmbH
5d5ef727 6 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
58d7e8f8 7 * @module WoltLabSuite/Core/BootstrapFrontend
5d5ef727 8 */
5a961a44
AE
9define(
10 [
5c319dfd 11 'WoltLabSuite/Core/BackgroundQueue', 'WoltLabSuite/Core/Bootstrap', 'WoltLabSuite/Core/Controller/Style/Changer',
a8d2da1d 12 'WoltLabSuite/Core/Controller/Popover', 'WoltLabSuite/Core/Ui/User/Ignore', 'WoltLabSuite/Core/Ui/Page/Header/Menu'
5a961a44
AE
13 ],
14 function(
5c319dfd
AE
15 BackgroundQueue, Bootstrap, ControllerStyleChanger,
16 ControllerPopover, UiUserIgnore, UiPageHeaderMenu
5a961a44
AE
17 )
18{
5d5ef727
AE
19 "use strict";
20
21 /**
58d7e8f8 22 * @exports WoltLabSuite/Core/BootstrapFrontend
5d5ef727 23 */
58ec7cbd 24 return {
5d5ef727
AE
25 /**
26 * Bootstraps general modules and frontend exclusive ones.
38fc3e39
AE
27 *
28 * @param {object<string, *>} options bootstrap options
5d5ef727 29 */
38fc3e39 30 setup: function(options) {
2f1b422d
AE
31 // fix the background queue URL to always run against the current domain (avoiding CORS)
32 options.backgroundQueue.url = WSC_API_URL + options.backgroundQueue.url.substr(WCF_PATH.length);
33
5d5ef727 34 Bootstrap.setup();
38fc3e39 35
a8d2da1d
AE
36 UiPageHeaderMenu.init();
37
38fc3e39 38 if (options.styleChanger) {
9ba60a8e 39 ControllerStyleChanger.setup();
38fc3e39 40 }
5b66af14 41
bfb66525
AE
42 if (options.enableUserPopover) {
43 this._initUserPopover();
44 }
45
5c319dfd
AE
46 BackgroundQueue.setUrl(options.backgroundQueue.url);
47 if (Math.random() < 0.1 || options.backgroundQueue.force) {
48 // invoke the queue roughly every 10th request or on demand
49 BackgroundQueue.invoke();
50 }
3a8d4181 51
d5bbc780
AE
52 if (COMPILER_TARGET_DEFAULT) {
53 UiUserIgnore.init();
54 }
5b66af14
AE
55 },
56
57 /**
58 * Initializes user profile popover.
59 */
60 _initUserPopover: function() {
61 ControllerPopover.init({
62 attributeName: 'data-user-id',
63 className: 'userLink',
64 identifier: 'com.woltlab.wcf.user',
65 loadCallback: function(objectId, popover) {
b5a32d79
AE
66 var callback = function(data) {
67 popover.setContent('com.woltlab.wcf.user', objectId, data.returnValues.template);
68 };
69
70 popover.ajaxApi({
71 actionName: 'getUserProfile',
72 className: 'wcf\\data\\user\\UserProfileAction',
73 objectIDs: [ objectId ]
74 }, callback, callback);
5b66af14
AE
75 }
76 });
5d5ef727
AE
77 }
78 };
38fc3e39 79});