@qhealth-design-system/core 1.22.2 → 1.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.storybook/assets/image-position-demo-portrait.svg +54 -0
- package/.storybook/assets/image-position-demo.svg +55 -0
- package/.storybook/globals.js +9 -0
- package/.storybook/preview.js +8 -1
- package/CHANGELOG.md +2 -0
- package/README.md +0 -6
- package/package.json +13 -33
- package/src/assets/img/svg-icons.svg +154 -154
- package/src/component-loader.js +11 -2
- package/src/components/_global/css/admin/component.scss +1 -0
- package/src/components/_global/css/btn/component.scss +9 -0
- package/src/components/_global/css/img/image-position-utility-classes.scss +30 -0
- package/src/components/_global/css/img/image-ratio-utility-classes.scss +41 -0
- package/src/components/_global/css/img/images.scss +74 -5
- package/src/components/_global/css/modal/component.scss +1 -0
- package/src/components/_global/js/animate/global.js +272 -294
- package/src/components/_global/js/collapsible.js +3 -3
- package/src/components/_global/js/global.js +304 -316
- package/src/components/_global/js/legacyGlobal.js +63 -0
- package/src/components/_global/js/modal/global.js +218 -223
- package/src/components/_global/js/popover/controller.js +4 -4
- package/src/components/_global/js/tabs/global.js +264 -276
- package/src/components/a-z_listing/js/global.js +106 -92
- package/src/components/accordion/css/component.scss +24 -41
- package/src/components/accordion/html/component.hbs +23 -5
- package/src/components/accordion/js/global.js +5 -10
- package/src/components/basic_search/js/global.js +0 -7
- package/src/components/code/js/global.js +6 -12
- package/src/components/file_upload/js/global.js +1 -5
- package/src/components/internal_navigation/css/component.scss +2 -2
- package/src/components/internal_navigation/html/component.hbs +16 -1
- package/src/components/main_navigation/js/global.js +341 -335
- package/src/components/overflow_menu/css/component.scss +1 -0
- package/src/components/search_box/css/component.scss +0 -1
- package/src/components/tab/js/global.js +5 -10
- package/src/components/toggle_tip/js/global.js +0 -6
- package/src/components/tool_tip/js/global.js +0 -6
- package/src/components/video_player/css/component.scss +27 -9
- package/src/components/video_player/html/component.hbs +32 -6
- package/src/components/video_player/js/global.js +8 -1
- package/src/index.js +4 -0
- package/src/stories/Accordion/accordion.stories.js +1 -0
- package/src/stories/Banner/bannerContained.stories.js +123 -0
- package/src/stories/Flexbox/Flexbox.stories.js +316 -0
- package/src/stories/Image/Image.stories.js +182 -0
- package/src/stories/Templates/ContentPage.stories.js +101 -0
- package/src/stories/Templates/LandingPage.stories.js +193 -0
- package/src/stories/Templates/templateHelpers.js +102 -0
- package/src/stories/VideoPlayer/VideoPlayer.stories.js +16 -0
- package/src/styles/imports/utilities.scss +15 -25
- package/src/styles/imports/variables.scss +26 -0
- package/src/components/_global/html/head.html +0 -22
- package/src/components/_global/html/scripts.html +0 -28
- package/src/components/_global/js/_polyfills/global.js +0 -19
- package/src/components/_template/html/component-page.html +0 -75
- package/src/components/_template/js/global.js +0 -3
- package/src/components/accordion/html/accordion-group.html +0 -163
- package/src/components/accordion/html/default.html +0 -99
- package/src/components/banner_basic/js/global.js +0 -3
- package/src/components/loading_spinner/js/global.js +0 -3
- package/src/components/pagination/html/default.html +0 -39
- package/src/components/search_box/html/component.html +0 -26
- package/src/data/current.json +0 -400
- package/src/data/current_admin.json +0 -305
- package/src/data/model_component.js +0 -14
- package/src/data/site.json +0 -977
- package/src/externals/tinymce_classes.css +0 -62
- package/src/html/component-global-elements.html +0 -2857
- package/src/html/component-horizontal_rule.html +0 -647
- package/src/html/component-internal_navigation.html +0 -583
- package/src/html/component-left_hand_navigation.html +0 -57
- package/src/html/component-main_navigation.html +0 -583
- package/src/html/component-multi_column.html +0 -582
- package/src/html/components.html +0 -354
- package/src/html/home.html +0 -1898
- package/src/html/index.html +0 -129
- package/src/html/inner-with-nav.html +0 -605
- package/src/html/inner.html +0 -618
|
@@ -4,373 +4,379 @@
|
|
|
4
4
|
* @module mobileNav
|
|
5
5
|
*/
|
|
6
6
|
import { setExpanded } from "../../../helpers/global-helpers.js";
|
|
7
|
+
import * as animate from "../../_global/js/animate/global.js";
|
|
8
|
+
import utils from "../../_global/js/global.js";
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var mobileNavAnimating = false;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* IE8 compatible function for replacing classes on a DOM node
|
|
15
|
-
*
|
|
16
|
-
* @memberof module:mobileNav
|
|
17
|
-
* @instance
|
|
18
|
-
* @private
|
|
19
|
-
*
|
|
20
|
-
* @param {object} element - The DOM element we want to toggle classes on
|
|
21
|
-
* @param {object} state - The current state of the animation on the element
|
|
22
|
-
* @param {string} openingClass - The firstClass you want to toggle on the DOM node
|
|
23
|
-
* @param {string} closingClass - The secondClass you want to toggle on the DOM node
|
|
24
|
-
*/
|
|
25
|
-
function toggleClasses(element, state, openingClass, closingClass) {
|
|
26
|
-
if (state === "opening" || state === "open") {
|
|
27
|
-
var oldClass = openingClass || "qld__main-nav__content--closed";
|
|
28
|
-
var newClass = closingClass || "qld__main-nav__content--open";
|
|
29
|
-
} else {
|
|
30
|
-
var oldClass = closingClass || "qld__main-nav__content--open";
|
|
31
|
-
var newClass = openingClass || "qld__main-nav__content--closed";
|
|
32
|
-
}
|
|
10
|
+
var mobileNav = {};
|
|
11
|
+
var mobileNavEvents = {};
|
|
12
|
+
var mobileNavAnimating = false;
|
|
33
13
|
|
|
34
|
-
|
|
35
|
-
|
|
14
|
+
/**
|
|
15
|
+
* IE8 compatible function for replacing classes on a DOM node
|
|
16
|
+
*
|
|
17
|
+
* @memberof module:mobileNav
|
|
18
|
+
* @instance
|
|
19
|
+
* @private
|
|
20
|
+
*
|
|
21
|
+
* @param {object} element - The DOM element we want to toggle classes on
|
|
22
|
+
* @param {object} state - The current state of the animation on the element
|
|
23
|
+
* @param {string} openingClass - The firstClass you want to toggle on the DOM node
|
|
24
|
+
* @param {string} closingClass - The secondClass you want to toggle on the DOM node
|
|
25
|
+
*/
|
|
26
|
+
function toggleClasses(element, state, openingClass, closingClass) {
|
|
27
|
+
var oldClass;
|
|
28
|
+
var newClass;
|
|
29
|
+
if (state === "opening" || state === "open") {
|
|
30
|
+
oldClass = openingClass || "qld__main-nav__content--closed";
|
|
31
|
+
newClass = closingClass || "qld__main-nav__content--open";
|
|
32
|
+
} else {
|
|
33
|
+
oldClass = closingClass || "qld__main-nav__content--open";
|
|
34
|
+
newClass = openingClass || "qld__main-nav__content--closed";
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
* @memberof module:mobileNav
|
|
42
|
-
* @instance
|
|
43
|
-
* @private
|
|
44
|
-
*
|
|
45
|
-
* @param {object} element - The DOM element we want to manipulate
|
|
46
|
-
* @param {object} className - The name of the class to be removed
|
|
47
|
-
*/
|
|
48
|
-
function removeClass(element, className) {
|
|
49
|
-
if (element.classList) {
|
|
50
|
-
element.classList.remove(className);
|
|
51
|
-
} else {
|
|
52
|
-
element.className = element.className.replace(
|
|
53
|
-
new RegExp(
|
|
54
|
-
"(^|\\b)" + className.split(" ").join("|") + "(\\b|$)",
|
|
55
|
-
"gi",
|
|
56
|
-
),
|
|
57
|
-
" ",
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
37
|
+
removeClass(element, oldClass);
|
|
38
|
+
addClass(element, newClass);
|
|
39
|
+
}
|
|
61
40
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
41
|
+
/**
|
|
42
|
+
* IE8 compatible function for removing a class
|
|
43
|
+
*
|
|
44
|
+
* @memberof module:mobileNav
|
|
45
|
+
* @instance
|
|
46
|
+
* @private
|
|
47
|
+
*
|
|
48
|
+
* @param {object} element - The DOM element we want to manipulate
|
|
49
|
+
* @param {object} className - The name of the class to be removed
|
|
50
|
+
*/
|
|
51
|
+
function removeClass(element, className) {
|
|
52
|
+
if (element.classList) {
|
|
53
|
+
element.classList.remove(className);
|
|
54
|
+
} else {
|
|
55
|
+
element.className = element.className.replace(
|
|
56
|
+
new RegExp("(^|\\b)" + className.split(" ").join("|") + "(\\b|$)", "gi"),
|
|
57
|
+
" ",
|
|
58
|
+
);
|
|
78
59
|
}
|
|
60
|
+
}
|
|
79
61
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
var handler = rawHandler.apply(this, arguments);
|
|
98
|
-
if (handler === false) {
|
|
99
|
-
event.stopPropagation();
|
|
100
|
-
event.preventDefault();
|
|
101
|
-
}
|
|
102
|
-
return handler;
|
|
103
|
-
}
|
|
62
|
+
/**
|
|
63
|
+
* IE8 compatible function for adding a class
|
|
64
|
+
*
|
|
65
|
+
* @memberof module:mobileNav
|
|
66
|
+
* @instance
|
|
67
|
+
* @private
|
|
68
|
+
*
|
|
69
|
+
* @param {object} element - The DOM element we want to manipulate
|
|
70
|
+
* @param {object} className - The name of the class to be added
|
|
71
|
+
*/
|
|
72
|
+
function addClass(element, className) {
|
|
73
|
+
if (element.classList) {
|
|
74
|
+
element.classList.add(className);
|
|
75
|
+
} else {
|
|
76
|
+
element.className = element.className + " " + className;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
104
79
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
80
|
+
/**
|
|
81
|
+
* IE8 compatible function for adding an event
|
|
82
|
+
* https://stackoverflow.com/questions/10149963/adding-event-listener-cross-browser
|
|
83
|
+
*
|
|
84
|
+
* @memberof module:mobileNav
|
|
85
|
+
* @instance
|
|
86
|
+
* @private
|
|
87
|
+
*
|
|
88
|
+
* @param {object} element - The DOM element to add the listener
|
|
89
|
+
* @param {object} event - The event data
|
|
90
|
+
* @param {object} rawHandler - The function to run when triggered
|
|
91
|
+
*
|
|
92
|
+
* @returns {object} - The token for removal of listener
|
|
93
|
+
*/
|
|
94
|
+
function addEvent(element, event, rawHandler) {
|
|
95
|
+
// Using local functions instead of anonymous for event handler
|
|
96
|
+
function listenHandler(event) {
|
|
97
|
+
var handler = rawHandler.apply(this, arguments);
|
|
98
|
+
if (handler === false) {
|
|
99
|
+
event.stopPropagation();
|
|
100
|
+
event.preventDefault();
|
|
113
101
|
}
|
|
102
|
+
return handler;
|
|
103
|
+
}
|
|
114
104
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
event: event,
|
|
122
|
-
};
|
|
123
|
-
} else {
|
|
124
|
-
element.attachEvent("on" + event, attachHandler);
|
|
125
|
-
return {
|
|
126
|
-
element: element,
|
|
127
|
-
handler: attachHandler,
|
|
128
|
-
event: event,
|
|
129
|
-
};
|
|
105
|
+
// Make sure attachHandler is also going to work
|
|
106
|
+
function attachHandler() {
|
|
107
|
+
var handler = rawHandler.call(element, window.event);
|
|
108
|
+
if (handler === false) {
|
|
109
|
+
window.event.returnValue = false;
|
|
110
|
+
window.event.cancelBubble = true;
|
|
130
111
|
}
|
|
112
|
+
return handler;
|
|
131
113
|
}
|
|
132
114
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
115
|
+
// Return the token and add the correct listener
|
|
116
|
+
if (element.addEventListener) {
|
|
117
|
+
element.addEventListener(event, listenHandler, false);
|
|
118
|
+
return {
|
|
119
|
+
element: element,
|
|
120
|
+
handler: listenHandler,
|
|
121
|
+
event: event,
|
|
122
|
+
};
|
|
123
|
+
} else {
|
|
124
|
+
element.attachEvent("on" + event, attachHandler);
|
|
125
|
+
return {
|
|
126
|
+
element: element,
|
|
127
|
+
handler: attachHandler,
|
|
128
|
+
event: event,
|
|
129
|
+
};
|
|
148
130
|
}
|
|
131
|
+
}
|
|
149
132
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
: element.currentStyle
|
|
165
|
-
)[property]; // avoid getPropertyValue altogether
|
|
133
|
+
/**
|
|
134
|
+
* IE8 compatible function for removing an event
|
|
135
|
+
*
|
|
136
|
+
* @memberof module:mobileNav
|
|
137
|
+
* @instance
|
|
138
|
+
* @private
|
|
139
|
+
*
|
|
140
|
+
* @param {object} token - The token from the add listener function
|
|
141
|
+
*/
|
|
142
|
+
function removeEvent(token) {
|
|
143
|
+
if (token.element.removeEventListener) {
|
|
144
|
+
token.element.removeEventListener(token.event, token.handler);
|
|
145
|
+
} else {
|
|
146
|
+
token.element.detachEvent("on" + token.event, token.handler);
|
|
166
147
|
}
|
|
148
|
+
}
|
|
167
149
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
150
|
+
/**
|
|
151
|
+
* IE8 compatible function for getting elements style
|
|
152
|
+
*
|
|
153
|
+
* @memberof module:mobileNav
|
|
154
|
+
* @instance
|
|
155
|
+
* @private
|
|
156
|
+
*
|
|
157
|
+
* @param {object} element - element to check style
|
|
158
|
+
* @param {object} property - property to return value
|
|
159
|
+
*/
|
|
160
|
+
function getStyle(element, property) {
|
|
161
|
+
return (
|
|
162
|
+
typeof getComputedStyle !== "undefined"
|
|
163
|
+
? getComputedStyle(element, null)
|
|
164
|
+
: element.currentStyle
|
|
165
|
+
)[property]; // avoid getPropertyValue altogether
|
|
166
|
+
}
|
|
183
167
|
|
|
184
|
-
|
|
168
|
+
/**
|
|
169
|
+
* Toggle a mobileNav element
|
|
170
|
+
*
|
|
171
|
+
* @memberof module:mobileNav
|
|
172
|
+
*
|
|
173
|
+
* @param {string} element - The toggle for the main nav
|
|
174
|
+
* @param {integer} speed - The speed in ms for the animation
|
|
175
|
+
* @param {object} callbacks - An object of four optional callbacks: { onOpen, afterOpen, onClose, afterClose }
|
|
176
|
+
*
|
|
177
|
+
*/
|
|
178
|
+
mobileNav.Toggle = function (element, speed, callbacks) {
|
|
179
|
+
// Stop the main nav from being toggled if it is already being toggled
|
|
180
|
+
if (mobileNavAnimating) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
185
183
|
|
|
186
|
-
|
|
187
|
-
try {
|
|
188
|
-
window.event.cancelBubble = true;
|
|
189
|
-
event.stopPropagation();
|
|
190
|
-
} catch (error) {}
|
|
184
|
+
mobileNavAnimating = true;
|
|
191
185
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
186
|
+
// stop event propagation
|
|
187
|
+
try {
|
|
188
|
+
window.event.cancelBubble = true;
|
|
189
|
+
event.stopPropagation();
|
|
190
|
+
} catch {
|
|
191
|
+
// no-op: window.event / event may be unavailable in this context
|
|
192
|
+
}
|
|
196
193
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
var overlay = target.querySelector(".qld__main-nav__overlay");
|
|
202
|
-
var closeButton = target.querySelector(".qld__main-nav__toggle--close");
|
|
203
|
-
var openButton = document.querySelector(".qld__main-nav__toggle--open");
|
|
204
|
-
var focustrapTop = menu.querySelector(".qld__main-nav__focus-trap-top");
|
|
205
|
-
var focustrapBottom = menu.querySelector(
|
|
206
|
-
".qld__main-nav__focus-trap-bottom",
|
|
207
|
-
);
|
|
208
|
-
var menuHeading = document.querySelector(".qld__main-nav__menu-heading");
|
|
209
|
-
var focusContent = menu.querySelectorAll("a, .qld__main-nav__toggle");
|
|
210
|
-
var closed =
|
|
211
|
-
target.className.indexOf("qld__main-nav__content--open") === -1;
|
|
212
|
-
var header = document.querySelector(".qld__header");
|
|
213
|
-
var body = document.querySelector(".main");
|
|
214
|
-
var footer = document.querySelector(".qld__footer");
|
|
215
|
-
|
|
216
|
-
var menuWidth = menu.offsetWidth;
|
|
217
|
-
var state = closed ? "opening" : "";
|
|
218
|
-
|
|
219
|
-
overlay.style.display = "block";
|
|
220
|
-
|
|
221
|
-
(function (target, speed) {
|
|
222
|
-
QLD.animate.Toggle({
|
|
223
|
-
element: menu,
|
|
224
|
-
property: "right",
|
|
225
|
-
openSize: 0,
|
|
226
|
-
closeSize: -1 * menuWidth,
|
|
227
|
-
speed: speed || 250,
|
|
228
|
-
prefunction: function () {
|
|
229
|
-
// Set these values immediately for transitions
|
|
230
|
-
if (state === "opening") {
|
|
231
|
-
menu.style.display = "block";
|
|
232
|
-
overlay.style.right = 0;
|
|
233
|
-
overlay.style.opacity = 0.5;
|
|
234
|
-
|
|
235
|
-
// run when opening
|
|
236
|
-
if (typeof callbacks.onOpen === "function") {
|
|
237
|
-
callbacks.onOpen();
|
|
238
|
-
}
|
|
239
|
-
} else {
|
|
240
|
-
overlay.style.opacity = "0";
|
|
194
|
+
// check this once
|
|
195
|
+
if (typeof callbacks != "object") {
|
|
196
|
+
callbacks = {};
|
|
197
|
+
}
|
|
241
198
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
199
|
+
// Elements we modify
|
|
200
|
+
var targetId = element.getAttribute("aria-controls");
|
|
201
|
+
var target = document.getElementById(targetId);
|
|
202
|
+
var menu = target.querySelector(".qld__main-nav__menu");
|
|
203
|
+
var overlay = target.querySelector(".qld__main-nav__overlay");
|
|
204
|
+
var closeButton = target.querySelector(".qld__main-nav__toggle--close");
|
|
205
|
+
var openButton = document.querySelector(".qld__main-nav__toggle--open");
|
|
206
|
+
var focustrapTop = menu.querySelector(".qld__main-nav__focus-trap-top");
|
|
207
|
+
var focustrapBottom = menu.querySelector(".qld__main-nav__focus-trap-bottom");
|
|
208
|
+
var menuHeading = document.querySelector(".qld__main-nav__menu-heading");
|
|
209
|
+
var focusContent = menu.querySelectorAll("a, .qld__main-nav__toggle");
|
|
210
|
+
var closed = target.className.indexOf("qld__main-nav__content--open") === -1;
|
|
211
|
+
var header = document.querySelector(".qld__header");
|
|
212
|
+
var body = document.querySelector(".main");
|
|
213
|
+
var footer = document.querySelector(".qld__footer");
|
|
214
|
+
|
|
215
|
+
var menuWidth = menu.offsetWidth;
|
|
216
|
+
var state = closed ? "opening" : "";
|
|
217
|
+
|
|
218
|
+
overlay.style.display = "block";
|
|
219
|
+
|
|
220
|
+
(function (target, speed) {
|
|
221
|
+
animate.Toggle({
|
|
222
|
+
element: menu,
|
|
223
|
+
property: "right",
|
|
224
|
+
openSize: 0,
|
|
225
|
+
closeSize: -1 * menuWidth,
|
|
226
|
+
speed: speed || 250,
|
|
227
|
+
prefunction: function () {
|
|
228
|
+
// Set these values immediately for transitions
|
|
229
|
+
if (state === "opening") {
|
|
230
|
+
menu.style.display = "block";
|
|
231
|
+
overlay.style.right = 0;
|
|
232
|
+
overlay.style.opacity = 0.5;
|
|
233
|
+
|
|
234
|
+
// run when opening
|
|
235
|
+
if (typeof callbacks.onOpen === "function") {
|
|
236
|
+
callbacks.onOpen();
|
|
246
237
|
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
if (state === "opening") {
|
|
250
|
-
// Move the focus to the close button
|
|
251
|
-
if (menuHeading) {
|
|
252
|
-
menuHeading.focus();
|
|
253
|
-
}
|
|
254
|
-
if (openButton) setExpanded(openButton, true);
|
|
255
|
-
if (closeButton) setExpanded(closeButton, true);
|
|
256
|
-
|
|
257
|
-
if (focustrapTop) focustrapTop.setAttribute("tabindex", 0);
|
|
258
|
-
if (focustrapBottom) focustrapBottom.setAttribute("tabindex", 0);
|
|
259
|
-
|
|
260
|
-
if (body) body.setAttribute("aria-hidden", true);
|
|
261
|
-
if (footer) footer.setAttribute("aria-hidden", true);
|
|
262
|
-
// openButton.setAttribute("aria-expanded", true);
|
|
263
|
-
// closeButton.setAttribute("aria-expanded", true);
|
|
264
|
-
|
|
265
|
-
// // Focus trap enabled
|
|
266
|
-
// focustrapTop.setAttribute("tabindex", 0);
|
|
267
|
-
// focustrapBottom.setAttribute("tabindex", 0);
|
|
268
|
-
|
|
269
|
-
// // header.setAttribute('aria-hidden', true);
|
|
270
|
-
// body.setAttribute("aria-hidden", true);
|
|
271
|
-
// footer.setAttribute("aria-hidden", true);
|
|
272
|
-
|
|
273
|
-
// Add event listeners
|
|
274
|
-
mobileNavEvents.focusTop = addEvent(
|
|
275
|
-
focustrapTop,
|
|
276
|
-
"focus",
|
|
277
|
-
function () {
|
|
278
|
-
focusContent[focusContent.length - 1].focus();
|
|
279
|
-
},
|
|
280
|
-
);
|
|
281
|
-
|
|
282
|
-
mobileNavEvents.focusBottom = addEvent(
|
|
283
|
-
focustrapBottom,
|
|
284
|
-
"focus",
|
|
285
|
-
function () {
|
|
286
|
-
focusContent[0].focus();
|
|
287
|
-
},
|
|
288
|
-
);
|
|
289
|
-
|
|
290
|
-
// Add key listener
|
|
291
|
-
mobileNavEvents.escKey = addEvent(document, "keydown", function () {
|
|
292
|
-
var event = event || window.event;
|
|
293
|
-
var overlayOpen = getStyle(overlay, "display");
|
|
294
|
-
|
|
295
|
-
// Check the menu is open and visible and the escape key is pressed
|
|
296
|
-
if (event.keyCode === 27 && overlayOpen === "block") {
|
|
297
|
-
mobileNav.Toggle(element, speed, callbacks);
|
|
298
|
-
}
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
if (typeof callbacks.afterOpen === "function") {
|
|
302
|
-
callbacks.afterOpen();
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
// Adjust the size of the cta wrapper in mobile view
|
|
306
|
-
const mobileMenuWidth = document.querySelector(
|
|
307
|
-
".qld__main-nav__menu-inner",
|
|
308
|
-
).offsetWidth;
|
|
309
|
-
let ctaWrapper = document.querySelector(
|
|
310
|
-
".qld__main-nav__cta-wrapper",
|
|
311
|
-
);
|
|
312
|
-
if (mobileMenuWidth && ctaWrapper) {
|
|
313
|
-
ctaWrapper.style.width = mobileMenuWidth + "px";
|
|
314
|
-
}
|
|
315
|
-
} else {
|
|
316
|
-
// Move the focus back to the menu button
|
|
317
|
-
if (closeButton) closeButton.focus();
|
|
318
|
-
if (openButton) setExpanded(openButton, false);
|
|
319
|
-
if (closeButton) setExpanded(closeButton, false);
|
|
320
|
-
|
|
321
|
-
if (focustrapTop) focustrapTop.removeAttribute("tabindex");
|
|
322
|
-
if (focustrapBottom) focustrapBottom.removeAttribute("tabindex");
|
|
238
|
+
} else {
|
|
239
|
+
overlay.style.opacity = "0";
|
|
323
240
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
241
|
+
// run when closing
|
|
242
|
+
if (typeof callbacks.onClose === "function") {
|
|
243
|
+
callbacks.onClose();
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
postfunction: function () {
|
|
248
|
+
if (state === "opening") {
|
|
249
|
+
// Move the focus to the close button
|
|
250
|
+
if (menuHeading) {
|
|
251
|
+
menuHeading.focus();
|
|
252
|
+
}
|
|
253
|
+
if (openButton) setExpanded(openButton, true);
|
|
254
|
+
if (closeButton) setExpanded(closeButton, true);
|
|
255
|
+
|
|
256
|
+
if (focustrapTop) focustrapTop.setAttribute("tabindex", 0);
|
|
257
|
+
if (focustrapBottom) focustrapBottom.setAttribute("tabindex", 0);
|
|
258
|
+
|
|
259
|
+
if (body) body.setAttribute("aria-hidden", true);
|
|
260
|
+
if (footer) footer.setAttribute("aria-hidden", true);
|
|
261
|
+
// openButton.setAttribute("aria-expanded", true);
|
|
262
|
+
// closeButton.setAttribute("aria-expanded", true);
|
|
263
|
+
|
|
264
|
+
// // Focus trap enabled
|
|
265
|
+
// focustrapTop.setAttribute("tabindex", 0);
|
|
266
|
+
// focustrapBottom.setAttribute("tabindex", 0);
|
|
267
|
+
|
|
268
|
+
// // header.setAttribute('aria-hidden', true);
|
|
269
|
+
// body.setAttribute("aria-hidden", true);
|
|
270
|
+
// footer.setAttribute("aria-hidden", true);
|
|
271
|
+
|
|
272
|
+
// Add event listeners
|
|
273
|
+
mobileNavEvents.focusTop = addEvent(
|
|
274
|
+
focustrapTop,
|
|
275
|
+
"focus",
|
|
276
|
+
function () {
|
|
277
|
+
focusContent[focusContent.length - 1].focus();
|
|
278
|
+
},
|
|
279
|
+
);
|
|
327
280
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
281
|
+
mobileNavEvents.focusBottom = addEvent(
|
|
282
|
+
focustrapBottom,
|
|
283
|
+
"focus",
|
|
284
|
+
function () {
|
|
285
|
+
focusContent[0].focus();
|
|
286
|
+
},
|
|
287
|
+
);
|
|
331
288
|
|
|
332
|
-
|
|
333
|
-
|
|
289
|
+
// Add key listener
|
|
290
|
+
mobileNavEvents.escKey = addEvent(document, "keydown", function () {
|
|
291
|
+
var event = event || window.event;
|
|
292
|
+
var overlayOpen = getStyle(overlay, "display");
|
|
334
293
|
|
|
335
|
-
|
|
336
|
-
|
|
294
|
+
// Check the menu is open and visible and the escape key is pressed
|
|
295
|
+
if (event.keyCode === 27 && overlayOpen === "block") {
|
|
296
|
+
mobileNav.Toggle(element, speed, callbacks);
|
|
337
297
|
}
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
if (typeof callbacks.afterOpen === "function") {
|
|
301
|
+
callbacks.afterOpen();
|
|
338
302
|
}
|
|
339
303
|
|
|
340
|
-
//
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
"qld__main-
|
|
346
|
-
"qld__main-nav__scroll--locked",
|
|
304
|
+
// Adjust the size of the cta wrapper in mobile view
|
|
305
|
+
const mobileMenuWidth = document.querySelector(
|
|
306
|
+
".qld__main-nav__menu-inner",
|
|
307
|
+
).offsetWidth;
|
|
308
|
+
let ctaWrapper = document.querySelector(
|
|
309
|
+
".qld__main-nav__cta-wrapper",
|
|
347
310
|
);
|
|
311
|
+
if (mobileMenuWidth && ctaWrapper) {
|
|
312
|
+
ctaWrapper.style.width = mobileMenuWidth + "px";
|
|
313
|
+
}
|
|
314
|
+
} else {
|
|
315
|
+
// Move the focus back to the menu button
|
|
316
|
+
if (closeButton) closeButton.focus();
|
|
317
|
+
if (openButton) setExpanded(openButton, false);
|
|
318
|
+
if (closeButton) setExpanded(closeButton, false);
|
|
319
|
+
|
|
320
|
+
if (focustrapTop) focustrapTop.removeAttribute("tabindex");
|
|
321
|
+
if (focustrapBottom) focustrapBottom.removeAttribute("tabindex");
|
|
322
|
+
|
|
323
|
+
if (header) header.removeAttribute("aria-hidden");
|
|
324
|
+
if (body) body.removeAttribute("aria-hidden");
|
|
325
|
+
if (footer) footer.removeAttribute("aria-hidden");
|
|
326
|
+
|
|
327
|
+
// Remove the event listeners
|
|
328
|
+
removeEvent(mobileNavEvents.focusTop);
|
|
329
|
+
removeEvent(mobileNavEvents.focusBottom);
|
|
348
330
|
|
|
349
|
-
//
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
331
|
+
// Remove the event listener for the keypress
|
|
332
|
+
removeEvent(mobileNavEvents.escKey);
|
|
333
|
+
|
|
334
|
+
if (typeof callbacks.afterClose === "function") {
|
|
335
|
+
callbacks.afterClose();
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// Toggle classes
|
|
340
|
+
toggleClasses(target, state);
|
|
341
|
+
toggleClasses(
|
|
342
|
+
document.body,
|
|
343
|
+
state,
|
|
344
|
+
"qld__main-nav__scroll--unlocked",
|
|
345
|
+
"qld__main-nav__scroll--locked",
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
// Reset inline styles
|
|
349
|
+
menu.style.display = "";
|
|
350
|
+
menu.style.right = "";
|
|
351
|
+
overlay.style.display = "";
|
|
352
|
+
overlay.style.right = "";
|
|
353
|
+
overlay.style.opacity = "";
|
|
354
|
+
|
|
355
|
+
mobileNavAnimating = false;
|
|
356
|
+
},
|
|
369
357
|
});
|
|
358
|
+
})(target, speed);
|
|
359
|
+
};
|
|
370
360
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
361
|
+
/**
|
|
362
|
+
* Initialise the mobile nav: wire the open/close toggles and fix up the SVG
|
|
363
|
+
* icon paths for the nav/header CTAs.
|
|
364
|
+
*
|
|
365
|
+
* @param {Document|Element} root - Scope for the toggle query. Defaults to `document`.
|
|
366
|
+
*/
|
|
367
|
+
export default function initMainNav(root = document) {
|
|
368
|
+
// Add toggle event to open mobile nav
|
|
369
|
+
var navToggles = root.querySelectorAll('*[aria-controls="main-nav"]');
|
|
370
|
+
navToggles.forEach(function (button) {
|
|
371
|
+
button.addEventListener("click", function () {
|
|
372
|
+
mobileNav.Toggle(button);
|
|
373
|
+
});
|
|
375
374
|
});
|
|
376
|
-
|
|
375
|
+
|
|
376
|
+
// Finds all the menu related icons in main nav, mega nav, and header.
|
|
377
|
+
utils.updateSvgIconPath(
|
|
378
|
+
".qld__main-nav__cta-wrapper .qld__main-nav__item-link svg.qld__icon > use, .qld__header__cta-wrapper .qld__header__cta-link svg.qld__icon > use",
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export { mobileNav };
|