Add content selection before removing content
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / js / WoltLabSuite / Core / BootstrapFrontend.js
1 /**
2 * Bootstraps WCF's JavaScript with additions for the frontend usage.
3 *
4 * @author Alexander Ebert
5 * @copyright 2001-2018 WoltLab GmbH
6 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
7 * @module WoltLabSuite/Core/BootstrapFrontend
8 */
9 define(
10 [
11 'WoltLabSuite/Core/BackgroundQueue', 'WoltLabSuite/Core/Bootstrap', 'WoltLabSuite/Core/Controller/Style/Changer',
12 'WoltLabSuite/Core/Controller/Popover', 'WoltLabSuite/Core/Ui/User/Ignore', 'WoltLabSuite/Core/Ui/Page/Header/Menu'
13 ],
14 function(
15 BackgroundQueue, Bootstrap, ControllerStyleChanger,
16 ControllerPopover, UiUserIgnore, UiPageHeaderMenu
17 )
18 {
19 "use strict";
20
21 /**
22 * @exports WoltLabSuite/Core/BootstrapFrontend
23 */
24 return {
25 /**
26 * Bootstraps general modules and frontend exclusive ones.
27 *
28 * @param {object<string, *>} options bootstrap options
29 */
30 setup: function(options) {
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
34 Bootstrap.setup();
35
36 UiPageHeaderMenu.init();
37
38 if (options.styleChanger) {
39 ControllerStyleChanger.setup();
40 }
41
42 if (options.enableUserPopover) {
43 this._initUserPopover();
44 }
45
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 }
51
52 if (COMPILER_TARGET_DEFAULT) {
53 UiUserIgnore.init();
54 }
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) {
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);
75 }
76 });
77 }
78 };
79 });