Commit | Line | Data |
---|---|---|
a3a09eff TD |
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 | |
c839bd49 | 7 | * @copyright 2001-2018 WoltLab GmbH |
a3a09eff | 8 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
58d7e8f8 | 9 | * @module WoltLabSuite/Core/Bootstrap |
a3a09eff TD |
10 | */ |
11 | define( | |
0127caf7 | 12 | [ |
58d7e8f8 MS |
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', | |
32669648 | 16 | 'WoltLabSuite/Core/Date/Picker', 'EventHandler', 'Core', 'WoltLabSuite/Core/Ui/Page/JumpToTop', |
7ecb5d1c | 17 | 'Devtools', 'Dom/ChangeListener' |
0127caf7 AE |
18 | ], |
19 | function( | |
f317bc66 | 20 | favico, enquire, perfectScrollbar, DateTimeRelative, |
9a421cc7 AE |
21 | UiSimpleDropdown, UiMobile, UiTabMenu, UiFlexibleMenu, |
22 | UiDialog, UiTooltip, Language, Environment, | |
32669648 | 23 | DatePicker, EventHandler, Core, UiPageJumpToTop, |
7ecb5d1c | 24 | Devtools, DomChangeListener |
0127caf7 | 25 | ) |
a3a09eff | 26 | { |
c318ad3b AE |
27 | "use strict"; |
28 | ||
b7f79b30 | 29 | // perfectScrollbar does not need to be bound anywhere, it just has to be loaded for WCF.js |
17e6272b TD |
30 | window.Favico = favico; |
31 | window.enquire = enquire; | |
46badb6a TD |
32 | // non strict equals by intent |
33 | if (window.WCF == null) window.WCF = { }; | |
34 | if (window.WCF.Language == null) window.WCF.Language = { }; | |
3f043599 TD |
35 | window.WCF.Language.get = Language.get; |
36 | window.WCF.Language.add = Language.add; | |
37 | window.WCF.Language.addObject = Language.addObject; | |
17e6272b | 38 | |
126b3f33 AE |
39 | // WCF.System.Event compatibility |
40 | window.__wcf_bc_eventHandler = EventHandler; | |
41 | ||
a3a09eff | 42 | /** |
58d7e8f8 | 43 | * @exports WoltLabSuite/Core/Bootstrap |
a3a09eff | 44 | */ |
cbbb348c | 45 | return { |
a3a09eff TD |
46 | /** |
47 | * Initializes the core UI modifications and unblocks jQuery's ready event. | |
cbbb348c AE |
48 | * |
49 | * @param {Object=} options initialization options | |
a3a09eff | 50 | */ |
cbbb348c AE |
51 | setup: function(options) { |
52 | options = Core.extend({ | |
53 | enableMobileMenu: true | |
54 | }, options); | |
55 | ||
32669648 AE |
56 | //noinspection JSUnresolvedVariable |
57 | if (window.ENABLE_DEVELOPER_TOOLS) Devtools._internal_.enable(); | |
58 | ||
bd969ed4 AE |
59 | Environment.setup(); |
60 | ||
61 | DateTimeRelative.setup(); | |
f317bc66 | 62 | DatePicker.init(); |
bd969ed4 | 63 | |
9a421cc7 | 64 | UiSimpleDropdown.setup(); |
cbbb348c AE |
65 | UiMobile.setup({ |
66 | enableMobileMenu: options.enableMobileMenu | |
67 | }); | |
9a421cc7 | 68 | UiTabMenu.setup(); |
b8eab696 | 69 | //UiFlexibleMenu.setup(); |
9a421cc7 AE |
70 | UiDialog.setup(); |
71 | UiTooltip.setup(); | |
a3a09eff | 72 | |
d63c6f77 | 73 | // convert method=get into method=post |
d0023381 | 74 | var forms = elBySelAll('form[method=get]'); |
d63c6f77 AE |
75 | for (var i = 0, length = forms.length; i < length; i++) { |
76 | forms[i].setAttribute('method', 'post'); | |
77 | } | |
78 | ||
bd969ed4 | 79 | if (Environment.browser() === 'microsoft') { |
d63c6f77 AE |
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 | ||
bd969ed4 AE |
85 | var interval = 0; |
86 | interval = window.setInterval(function() { | |
87 | if (typeof window.jQuery === 'function') { | |
88 | window.clearInterval(interval); | |
89 | ||
e8eb94de AE |
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 | new UiPageJumpToTop(); | |
95 | }); | |
96 | ||
bd969ed4 AE |
97 | window.jQuery.holdReady(false); |
98 | } | |
99 | }, 20); | |
7ecb5d1c MW |
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([role])', undefined, function(element) { | |
107 | elAttr(element, 'role', 'presentation'); | |
108 | }); | |
109 | ||
110 | elBySelAll('article:not([aria-label]):not([role])', undefined, function(element) { | |
111 | elAttr(element, 'role', 'presentation'); | |
112 | }); | |
a3a09eff | 113 | } |
c318ad3b | 114 | }; |
a3a09eff | 115 | }); |