Convert `Clipboard` to TypeScript
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / js / WoltLabSuite / Core / Bootstrap.js
1 /**
2 * Bootstraps WCF's JavaScript.
3 * It defines globals needed for backwards compatibility
4 * and runs modules that are needed on page load.
5 *
6 * @author Tim Duesterhus
7 * @copyright 2001-2019 WoltLab GmbH
8 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
9 * @module WoltLabSuite/Core/Bootstrap
10 */
11 define(
12 [
13 'favico', 'enquire', 'perfect-scrollbar', 'WoltLabSuite/Core/Date/Time/Relative',
14 'Ui/SimpleDropdown', 'WoltLabSuite/Core/Ui/Mobile', 'WoltLabSuite/Core/Ui/TabMenu', 'WoltLabSuite/Core/Ui/FlexibleMenu',
15 'Ui/Dialog', 'WoltLabSuite/Core/Ui/Tooltip', 'WoltLabSuite/Core/Language', 'WoltLabSuite/Core/Environment',
16 'WoltLabSuite/Core/Date/Picker', 'EventHandler', 'Core', 'WoltLabSuite/Core/Ui/Page/Action',
17 'Devtools', 'Dom/ChangeListener'
18 ],
19 function(
20 favico, enquire, perfectScrollbar, DateTimeRelative,
21 UiSimpleDropdown, UiMobile, UiTabMenu, UiFlexibleMenu,
22 UiDialog, UiTooltip, Language, Environment,
23 DatePicker, EventHandler, Core, UiPageAction,
24 Devtools, DomChangeListener
25 )
26 {
27 "use strict";
28
29 // perfectScrollbar does not need to be bound anywhere, it just has to be loaded for WCF.js
30 window.Favico = favico;
31 window.enquire = enquire;
32 // non strict equals by intent
33 if (window.WCF == null) window.WCF = { };
34 if (window.WCF.Language == null) window.WCF.Language = { };
35 window.WCF.Language.get = Language.get;
36 window.WCF.Language.add = Language.add;
37 window.WCF.Language.addObject = Language.addObject;
38
39 // WCF.System.Event compatibility
40 window.__wcf_bc_eventHandler = EventHandler;
41
42 /**
43 * @exports WoltLabSuite/Core/Bootstrap
44 */
45 return {
46 /**
47 * Initializes the core UI modifications and unblocks jQuery's ready event.
48 *
49 * @param {Object=} options initialization options
50 */
51 setup: function(options) {
52 options = Core.extend({
53 enableMobileMenu: true
54 }, options);
55
56 //noinspection JSUnresolvedVariable
57 if (window.ENABLE_DEVELOPER_TOOLS) Devtools._internal_.enable();
58
59 Environment.setup();
60
61 DateTimeRelative.setup();
62 DatePicker.init();
63
64 UiSimpleDropdown.setup();
65 UiMobile.setup({
66 enableMobileMenu: options.enableMobileMenu
67 });
68 UiTabMenu.setup();
69 //UiFlexibleMenu.setup();
70 UiDialog.setup();
71 UiTooltip.setup();
72
73 // convert method=get into method=post
74 var forms = elBySelAll('form[method=get]');
75 for (var i = 0, length = forms.length; i < length; i++) {
76 forms[i].setAttribute('method', 'post');
77 }
78
79 if (Environment.browser() === 'microsoft') {
80 window.onbeforeunload = function() {
81 /* Prevent "Back navigation caching" (http://msdn.microsoft.com/en-us/library/ie/dn265017%28v=vs.85%29.aspx) */
82 };
83 }
84
85 var interval = 0;
86 interval = window.setInterval(function() {
87 if (typeof window.jQuery === 'function') {
88 window.clearInterval(interval);
89
90 // the 'jump to top' button triggers style recalculation/layout,
91 // putting it at the end of the jQuery queue avoids trashing the
92 // layout too early and thus delaying the page initialization
93 window.jQuery(function() {
94 UiPageAction.setup();
95 });
96
97 window.jQuery.holdReady(false);
98 }
99 }, 20);
100
101 this._initA11y();
102 DomChangeListener.add('WoltLabSuite/Core/Bootstrap', this._initA11y.bind(this));
103 },
104
105 _initA11y: function() {
106 elBySelAll('nav:not([aria-label]):not([aria-labelledby]):not([role])', undefined, function(element) {
107 elAttr(element, 'role', 'presentation');
108 });
109
110 elBySelAll('article:not([aria-label]):not([aria-labelledby]):not([role])', undefined, function(element) {
111 elAttr(element, 'role', 'presentation');
112 });
113 }
114 };
115 });