@internetstiftelsen/styleguide 5.0.19 → 5.1.1
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/dist/app.js +71 -0
- package/dist/assets/js/Events.js +43 -77
- package/dist/assets/js/RequestError.js +16 -31
- package/dist/assets/js/anchorScroll.js +22 -15
- package/dist/assets/js/charCounter.js +100 -142
- package/dist/assets/js/className.js +19 -20
- package/dist/assets/js/conditional.js +96 -152
- package/dist/assets/js/debounce.js +15 -22
- package/dist/assets/js/el.js +108 -159
- package/dist/assets/js/getCookieByName.js +13 -11
- package/dist/assets/js/hasCookieConsent.js +30 -40
- package/dist/assets/js/htmlTextLength.js +12 -10
- package/dist/assets/js/iconToggle.js +16 -20
- package/dist/assets/js/nodeAdded.js +40 -53
- package/dist/assets/js/objToQuery.js +25 -41
- package/dist/assets/js/offset.js +29 -25
- package/dist/assets/js/ot.js +10 -13
- package/dist/assets/js/parallax.js +23 -23
- package/dist/assets/js/queryToObj.js +16 -22
- package/dist/assets/js/readSpeakerHandling.js +26 -28
- package/dist/assets/js/request.js +43 -52
- package/dist/assets/js/responsivePosition.js +46 -74
- package/dist/assets/js/stringToNode.js +11 -10
- package/dist/assets/js/template.js +15 -21
- package/dist/assets/js/textToggle.js +19 -24
- package/dist/assets/js/track.js +14 -12
- package/dist/assets/js/uid.js +10 -6
- package/dist/assets/js/utmGenerator.js +27 -33
- package/dist/assets/js/validationMessage.js +18 -25
- package/dist/assets/js/youtube.js +134 -170
- package/dist/atoms/button/Button.js +42 -55
- package/dist/atoms/file/file.js +25 -29
- package/dist/atoms/file/filePreview.js +27 -31
- package/dist/atoms/grid-toggle/grid-toggle.js +6 -9
- package/dist/atoms/height-limiter/height-limiter.js +37 -50
- package/dist/atoms/password-toggle/password-toggle.js +9 -11
- package/dist/atoms/range/range.js +32 -39
- package/dist/atoms/textarea/rich-text.js +221 -251
- package/dist/atoms/tooltip/tooltip.js +13 -17
- package/dist/components.js +42 -77
- package/dist/focusTrap.js +66 -77
- package/dist/molecules/alert/alert.js +15 -20
- package/dist/molecules/context-menu/context-menu.js +11 -16
- package/dist/molecules/continue-video-guide/continue-video-guide.js +90 -101
- package/dist/molecules/cookie-disclaimer/cookie-disclaimer.js +24 -33
- package/dist/molecules/form/Form.js +242 -352
- package/dist/molecules/form/index.js +15 -14
- package/dist/molecules/glider/glider-course.js +62 -75
- package/dist/molecules/glider/glider-hero.js +88 -101
- package/dist/molecules/glider/glider.js +49 -45
- package/dist/molecules/modal/modal.js +256 -325
- package/dist/molecules/multi-select/multi-select.js +198 -304
- package/dist/molecules/natural-language-form/natural-language-form.js +32 -46
- package/dist/molecules/overview-navigation/overview-navigation.js +90 -141
- package/dist/molecules/share/share.js +15 -20
- package/dist/molecules/system-error/system-error.js +6 -9
- package/dist/organisms/accordion/accordion.js +44 -50
- package/dist/organisms/footer/footer.js +1 -1
- package/dist/organisms/haveibeenpwned/haveibeenpwned.js +17 -16
- package/dist/organisms/mailchimp/mailchimp.js +72 -89
- package/dist/organisms/map-box/map-box.js +3 -4
- package/dist/organisms/mega-menu/mega-menu.js +177 -212
- package/dist/organisms/podcast/podcast.js +192 -215
- package/dist/organisms/schedule/schedule-filter.js +9 -15
- package/dist/organisms/tabs/tabs.js +194 -253
- package/dist/organisms/timeline/openTimelineItem.js +38 -51
- package/dist/organisms/timeline/timeline.js +111 -128
- package/dist/organisms/video-guide/VideoGuidePlayback.js +210 -286
- package/dist/organisms/video-guide/VideoGuideSubtitles.js +57 -80
- package/dist/organisms/video-guide/VideoGuideTimeline.js +74 -108
- package/dist/organisms/video-guide/getCurrentCueIndex.js +11 -9
- package/dist/organisms/video-guide/video-guide.js +66 -103
- package/dist/utilities/tab-highlighting/tab-highlighting.js +14 -22
- package/dist/vendor/toggle/a11y.toggle-switcher.js +10 -16
- package/package.json +78 -99
- package/src/app.js +5 -5
- package/src/assets/js/anchorScroll.js +1 -1
- package/src/assets/js/offset.js +1 -1
- package/src/atoms/button/Button.js +1 -1
- package/src/atoms/icon/richtext-ordered-list.svg +1 -1
- package/src/atoms/icon/sprite.svg +6 -5
- package/src/molecules/glider/glider-course.js +0 -2
- package/src/molecules/glider/glider.js +2 -2
- package/src/organisms/accordion/accordion.js +1 -2
- package/src/organisms/timeline/timeline.js +2 -3
- package/dist/atoms/timeline/anchorScroll.js +0 -13
- package/dist/atoms/toggle-high-contrast/toggle-high-contrast.js +0 -12
- package/dist/molecules/glider/glider-single.js +0 -68
- package/dist/molecules/modal/modal-graph.js +0 -40
- package/dist/molecules/timeline-navigation/timeline-navigation.js +0 -34
- /package/src/atoms/icon/{heading-3.svg → richtext-heading-3.svg} +0 -0
- /package/src/molecules/alert/{_alert.scss → alert.scss} +0 -0
|
@@ -1,27 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
exports
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
clearQueue: function() {
|
|
13
|
+
return clearQueue;
|
|
14
|
+
},
|
|
15
|
+
close: function() {
|
|
16
|
+
return close;
|
|
17
|
+
},
|
|
18
|
+
onClose: function() {
|
|
19
|
+
return onClose;
|
|
20
|
+
},
|
|
21
|
+
onOpen: function() {
|
|
22
|
+
return onOpen;
|
|
23
|
+
},
|
|
24
|
+
open: function() {
|
|
25
|
+
return open;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const _focusTrap = /*#__PURE__*/ _interop_require_default(require("../../focusTrap"));
|
|
29
|
+
const _className = /*#__PURE__*/ _interop_require_default(require("../../assets/js/className"));
|
|
30
|
+
function _extends() {
|
|
31
|
+
_extends = Object.assign || function(target) {
|
|
32
|
+
for(var i = 1; i < arguments.length; i++){
|
|
33
|
+
var source = arguments[i];
|
|
34
|
+
for(var key in source){
|
|
35
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
36
|
+
target[key] = source[key];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return target;
|
|
41
|
+
};
|
|
42
|
+
return _extends.apply(this, arguments);
|
|
43
|
+
}
|
|
44
|
+
function _interop_require_default(obj) {
|
|
45
|
+
return obj && obj.__esModule ? obj : {
|
|
46
|
+
default: obj
|
|
47
|
+
};
|
|
48
|
+
}
|
|
25
49
|
/**
|
|
26
50
|
* Modal action
|
|
27
51
|
* @typedef {Object} ModalAction
|
|
@@ -34,369 +58,276 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
34
58
|
* @property {string} key - action click handler key shortcut
|
|
35
59
|
* @property {function} onClick - action click handler
|
|
36
60
|
* @property {object} attrs – action element attributes
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
/**
|
|
61
|
+
*/ /**
|
|
40
62
|
* Modal content
|
|
41
63
|
* @typedef {Object} ModalContent
|
|
42
64
|
* @property {string} title - Modal title
|
|
43
65
|
* @property {string} content - Modal content
|
|
44
66
|
* @property {ModalAction[]} actions - Modal actions
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
/**
|
|
67
|
+
*/ /**
|
|
48
68
|
* Modal settings
|
|
49
69
|
* @typedef {Object} ModalSettings
|
|
50
70
|
* @property {boolean} replaceCurrent - Replace currently displayed modal
|
|
51
71
|
* @property {boolean} skipIfCurrent - Skip if currently displaying modal
|
|
52
72
|
* @property {function} onClose - onClose callback
|
|
53
73
|
* @property {function} onOpen - onOpen callback
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
var modalClose = null;
|
|
65
|
-
var keyHandlers = {};
|
|
66
|
-
|
|
74
|
+
*/ const queue = [];
|
|
75
|
+
const globalOnCloseCallbacks = [];
|
|
76
|
+
const globalOnOpenCallbacks = [];
|
|
77
|
+
let active = null;
|
|
78
|
+
let incrementId = 0;
|
|
79
|
+
let modal = null;
|
|
80
|
+
let modalContent = null;
|
|
81
|
+
let modalActions = null;
|
|
82
|
+
let modalClose = null;
|
|
83
|
+
let keyHandlers = {};
|
|
67
84
|
/**
|
|
68
85
|
* Increase increment ID and return the latest
|
|
69
86
|
*
|
|
70
87
|
* @returns {number}
|
|
71
|
-
*/
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return incrementId;
|
|
88
|
+
*/ function getId() {
|
|
89
|
+
incrementId += 1;
|
|
90
|
+
return incrementId;
|
|
76
91
|
}
|
|
77
|
-
|
|
78
92
|
function objectToAttributes(obj) {
|
|
79
|
-
|
|
80
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
81
|
-
value = _ref2[1];
|
|
82
|
-
|
|
83
|
-
return value !== undefined;
|
|
84
|
-
}).map(function (_ref3) {
|
|
85
|
-
var _ref4 = _slicedToArray(_ref3, 2),
|
|
86
|
-
key = _ref4[0],
|
|
87
|
-
value = _ref4[1];
|
|
88
|
-
|
|
89
|
-
return value !== null ? key + '=' + value : key;
|
|
90
|
-
}).join(' ');
|
|
93
|
+
return Object.entries(obj).filter(([, value])=>value !== undefined).map(([key, value])=>value !== null ? `${key}=${value}` : key).join(' ');
|
|
91
94
|
}
|
|
92
|
-
|
|
93
95
|
/**
|
|
94
96
|
* Create an action DOM node and append to modal actions container.
|
|
95
97
|
*
|
|
96
98
|
* @param {ModalAction} action
|
|
97
|
-
*/
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
99
|
+
*/ function addAction(action) {
|
|
100
|
+
const icon = action.icon ? `
|
|
101
|
+
<svg class="icon ${(0, _className.default)('a-button__icon')}">
|
|
102
|
+
<use xlink:href="#icon-${action.icon}"></use>
|
|
103
|
+
</svg>
|
|
104
|
+
` : '';
|
|
105
|
+
let cls = `${(0, _className.default)('a-button')} u-m-l-2`;
|
|
106
|
+
if (action.color) {
|
|
107
|
+
cls += ` ${(0, _className.default)(`a-button--${action.color}`)}`;
|
|
108
|
+
}
|
|
109
|
+
if (action.modifier) {
|
|
110
|
+
cls += ` ${(0, _className.default)(`m-modal__button-${action.modifier}`)}`;
|
|
111
|
+
}
|
|
112
|
+
if (action.icon) {
|
|
113
|
+
cls += ` ${(0, _className.default)('a-button--icon')}`;
|
|
114
|
+
}
|
|
115
|
+
const tag = action.url ? 'a' : 'button';
|
|
116
|
+
const button = `
|
|
117
|
+
<${tag} ${objectToAttributes(_extends({}, action.attrs, {
|
|
118
|
+
href: action.url,
|
|
119
|
+
target: action.target
|
|
120
|
+
}))} class="${cls}">
|
|
121
|
+
<span class="${(0, _className.default)('a-button__text')}">${action.text}</span>
|
|
122
|
+
${icon}
|
|
123
|
+
</${tag}>
|
|
124
|
+
`;
|
|
125
|
+
const dummy = document.createElement('div');
|
|
126
|
+
dummy.innerHTML = button;
|
|
127
|
+
const el = dummy.firstElementChild;
|
|
128
|
+
modalActions.appendChild(el);
|
|
129
|
+
if (action.onClick) {
|
|
130
|
+
el.addEventListener('click', (e)=>{
|
|
131
|
+
action.onClick(e, modal, close);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
131
134
|
}
|
|
132
|
-
|
|
133
135
|
function handleKeyUp(e) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (e.key.toLowerCase() === key) {
|
|
140
|
-
|
|
141
|
-
handler(e, modal, close);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
136
|
+
Object.entries(keyHandlers).forEach(([key, handler])=>{
|
|
137
|
+
if (e.key.toLowerCase() === key) {
|
|
138
|
+
handler(e, modal, close);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
144
141
|
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Global onOpen handler
|
|
148
|
-
*
|
|
149
|
-
* @param {Function} cb
|
|
150
|
-
* @returns {number}
|
|
151
|
-
*/
|
|
152
142
|
function onOpen(cb) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
};
|
|
143
|
+
const index = globalOnOpenCallbacks.push(cb) - 1;
|
|
144
|
+
return ()=>{
|
|
145
|
+
globalOnOpenCallbacks.splice(index, 1);
|
|
146
|
+
};
|
|
158
147
|
}
|
|
159
|
-
|
|
160
148
|
function dispatchOnOpenHandlers(el, id) {
|
|
161
|
-
|
|
162
|
-
return cb(el, id);
|
|
163
|
-
});
|
|
149
|
+
globalOnOpenCallbacks.forEach((cb)=>cb(el, id));
|
|
164
150
|
}
|
|
165
|
-
|
|
166
151
|
/**
|
|
167
152
|
* Display the active modal.
|
|
168
|
-
*/
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
active.content.actions.forEach(function (action) {
|
|
209
|
-
if (action.key && action.onClick) {
|
|
210
|
-
keyHandlers[action.key] = action.onClick;
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
document.addEventListener('keyup', handleKeyUp);
|
|
153
|
+
*/ function display() {
|
|
154
|
+
if (active.content.nodeName) {
|
|
155
|
+
// Content is a custom modal
|
|
156
|
+
active.el = active.content;
|
|
157
|
+
} else {
|
|
158
|
+
active.el = modal;
|
|
159
|
+
modalContent.innerHTML = `
|
|
160
|
+
<h1>${active.content.title}</h1>
|
|
161
|
+
${active.content.content}
|
|
162
|
+
`;
|
|
163
|
+
if (active.content.actions) {
|
|
164
|
+
modalActions.innerHTML = '';
|
|
165
|
+
active.content.actions.forEach(addAction);
|
|
166
|
+
modalActions.classList.remove('u-hide');
|
|
167
|
+
} else {
|
|
168
|
+
modalActions.classList.add('u-hide');
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
(0, _focusTrap.default)(active.el);
|
|
172
|
+
active.el.setAttribute('aria-hidden', 'false');
|
|
173
|
+
active.el.setAttribute('data-a11y-toggle-open', 'true');
|
|
174
|
+
if (active.settings.onOpen) {
|
|
175
|
+
active.settings.onOpen(active.id, active.el);
|
|
176
|
+
}
|
|
177
|
+
dispatchOnOpenHandlers(active.el, active.id);
|
|
178
|
+
setTimeout(()=>{
|
|
179
|
+
if (active.el.focusTrap) {
|
|
180
|
+
active.el.focusTrap.activate();
|
|
181
|
+
}
|
|
182
|
+
}, 1);
|
|
183
|
+
// Just to make sure
|
|
184
|
+
keyHandlers = {};
|
|
185
|
+
if (active.content.actions) {
|
|
186
|
+
active.content.actions.forEach((action)=>{
|
|
187
|
+
if (action.key && action.onClick) {
|
|
188
|
+
keyHandlers[action.key] = action.onClick;
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
document.addEventListener('keyup', handleKeyUp);
|
|
216
193
|
}
|
|
217
|
-
|
|
218
194
|
/**
|
|
219
195
|
* Dispatch the next modal in queue.
|
|
220
|
-
*/
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
active = queue.shift();
|
|
227
|
-
|
|
228
|
-
display();
|
|
196
|
+
*/ function dispatch() {
|
|
197
|
+
if (!modal || active || !queue.length) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
active = queue.shift();
|
|
201
|
+
display();
|
|
229
202
|
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Global onClose handler
|
|
233
|
-
*
|
|
234
|
-
* @param {Function} cb
|
|
235
|
-
* @returns {number}
|
|
236
|
-
*/
|
|
237
203
|
function onClose(cb) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
};
|
|
204
|
+
const index = globalOnCloseCallbacks.push(cb) - 1;
|
|
205
|
+
return ()=>{
|
|
206
|
+
globalOnCloseCallbacks.splice(index, 1);
|
|
207
|
+
};
|
|
243
208
|
}
|
|
244
|
-
|
|
245
209
|
function dispatchOnCloseHandlers(el, id) {
|
|
246
|
-
|
|
247
|
-
return cb(el, id);
|
|
248
|
-
});
|
|
210
|
+
globalOnCloseCallbacks.forEach((cb)=>cb(el, id));
|
|
249
211
|
}
|
|
250
|
-
|
|
251
212
|
/**
|
|
252
213
|
* Close currently active modal
|
|
253
214
|
* and dispatch next in queue.
|
|
254
|
-
*/
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
keyHandlers = {};
|
|
273
|
-
active = null;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
setTimeout(function () {
|
|
277
|
-
dispatch();
|
|
278
|
-
}, 1);
|
|
215
|
+
*/ function close() {
|
|
216
|
+
if (active) {
|
|
217
|
+
active.el.setAttribute('aria-hidden', 'true');
|
|
218
|
+
active.el.removeAttribute('data-a11y-toggle-open');
|
|
219
|
+
if (active.settings.onClose) {
|
|
220
|
+
active.settings.onClose(active.id);
|
|
221
|
+
}
|
|
222
|
+
dispatchOnCloseHandlers(active.el, active.id);
|
|
223
|
+
document.removeEventListener('keyup', handleKeyUp);
|
|
224
|
+
if (active.el.focusTrap) {
|
|
225
|
+
active.el.focusTrap.deactivate();
|
|
226
|
+
}
|
|
227
|
+
keyHandlers = {};
|
|
228
|
+
active = null;
|
|
229
|
+
}
|
|
230
|
+
setTimeout(()=>{
|
|
231
|
+
dispatch();
|
|
232
|
+
}, 1);
|
|
279
233
|
}
|
|
280
|
-
|
|
281
234
|
/**
|
|
282
235
|
* Create the modal skeleton and add it to the DOM.
|
|
283
236
|
* Done once and cached.
|
|
284
|
-
*/
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
237
|
+
*/ function createModal() {
|
|
238
|
+
if (modal) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const id = 'iisModal';
|
|
242
|
+
const dummy = document.createElement('div');
|
|
243
|
+
dummy.innerHTML = `
|
|
244
|
+
<div id="${id}" class="${(0, _className.default)('m-modal m-modal--has-overlay')}" data-container="true" aria-hidden="true" aria-labelledby="${id}-close">
|
|
245
|
+
<div class="${(0, _className.default)('m-modal__container')}">
|
|
246
|
+
<button type="button" class="${(0, _className.default)('a-button a-button--standalone-icon a-button--transparent')}" data-modal-close aria-expanded="false" data-a11y-toggle="${id}" aria-controls="${id}" id="${id}-close">
|
|
247
|
+
<span class="${(0, _className.default)('a-button__text')} u-visuallyhidden">Stäng</span>
|
|
248
|
+
<svg class="icon ${(0, _className.default)('a-button__icon')}">
|
|
249
|
+
<use xlink:href="#icon-close"></use>
|
|
250
|
+
</svg>
|
|
251
|
+
</button>
|
|
252
|
+
<div class="${(0, _className.default)('m-modal__content')}" data-modal-content></div>
|
|
253
|
+
<div class="${(0, _className.default)('m-modal__buttons')} u-m-t-2 u-hide" data-modal-actions></div>
|
|
254
|
+
</div>
|
|
255
|
+
</div>
|
|
256
|
+
`;
|
|
257
|
+
modal = dummy.firstElementChild;
|
|
258
|
+
modalContent = modal.querySelector('[data-modal-content]');
|
|
259
|
+
modalActions = modal.querySelector('[data-modal-actions]');
|
|
260
|
+
modalClose = modal.querySelector('[data-modal-close]');
|
|
261
|
+
document.body.appendChild(modal);
|
|
262
|
+
modalClose.addEventListener('click', close);
|
|
263
|
+
setTimeout(()=>{
|
|
264
|
+
dispatch();
|
|
265
|
+
}, 1);
|
|
307
266
|
}
|
|
308
|
-
|
|
309
267
|
/**
|
|
310
268
|
* Clear the current modal queue
|
|
311
|
-
*/
|
|
312
|
-
|
|
313
|
-
queue.length = 0;
|
|
269
|
+
*/ function clearQueue() {
|
|
270
|
+
queue.length = 0;
|
|
314
271
|
}
|
|
315
|
-
|
|
316
272
|
/**
|
|
317
273
|
* Open a modal.
|
|
318
274
|
*
|
|
319
275
|
* @param {ModalContent|HTMLElement} content
|
|
320
276
|
* @param {ModalSettings} settings
|
|
321
|
-
*/
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
if (settings.replaceCurrent) {
|
|
336
|
-
close();
|
|
337
|
-
} else {
|
|
338
|
-
dispatch();
|
|
339
|
-
}
|
|
277
|
+
*/ function open(content, settings = {}) {
|
|
278
|
+
if (active && settings.skipIfCurrent) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
queue.push({
|
|
282
|
+
id: getId(),
|
|
283
|
+
content,
|
|
284
|
+
settings
|
|
285
|
+
});
|
|
286
|
+
if (settings.replaceCurrent) {
|
|
287
|
+
close();
|
|
288
|
+
} else {
|
|
289
|
+
dispatch();
|
|
290
|
+
}
|
|
340
291
|
}
|
|
341
|
-
|
|
342
292
|
function delegate(e) {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
if (active && active.el.id === _id) {
|
|
377
|
-
close();
|
|
378
|
-
|
|
379
|
-
[].forEach.call(document.querySelectorAll('[aria-controls="' + _id + '"]'), function (el) {
|
|
380
|
-
el.setAttribute('aria-expanded', 'false');
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
return false;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
return true;
|
|
293
|
+
const openModal = e.target.closest('[data-modal-open]');
|
|
294
|
+
if (openModal) {
|
|
295
|
+
e.preventDefault();
|
|
296
|
+
e.stopPropagation();
|
|
297
|
+
const id = openModal.getAttribute('data-modal-open');
|
|
298
|
+
const modalEl = document.getElementById(id);
|
|
299
|
+
document.querySelector('body').classList.add('prevent-scroll');
|
|
300
|
+
if (modalEl) {
|
|
301
|
+
open(modalEl, {
|
|
302
|
+
replaceCurrent: openModal.hasAttribute('data-modal-replace'),
|
|
303
|
+
skipIfCurrent: openModal.hasAttribute('data-modal-skip')
|
|
304
|
+
});
|
|
305
|
+
[].forEach.call(document.querySelectorAll(`[aria-controls="${id}"]`), (el)=>{
|
|
306
|
+
el.setAttribute('aria-expanded', 'true');
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
const closeModal = e.target.closest('[data-modal-close]');
|
|
312
|
+
if (closeModal) {
|
|
313
|
+
e.preventDefault();
|
|
314
|
+
e.stopPropagation();
|
|
315
|
+
const id = closeModal.getAttribute('data-modal-close') || active && active.el.id;
|
|
316
|
+
document.querySelector('body').classList.remove('prevent-scroll');
|
|
317
|
+
if (active && active.el.id === id) {
|
|
318
|
+
close();
|
|
319
|
+
[].forEach.call(document.querySelectorAll(`[aria-controls="${id}"]`), (el)=>{
|
|
320
|
+
el.setAttribute('aria-expanded', 'false');
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
return true;
|
|
388
326
|
}
|
|
389
|
-
|
|
390
327
|
/**
|
|
391
328
|
* Attach global listeners
|
|
392
|
-
*/
|
|
393
|
-
|
|
394
|
-
document.body.addEventListener('click', delegate);
|
|
329
|
+
*/ function attach() {
|
|
330
|
+
document.body.addEventListener('click', delegate);
|
|
395
331
|
}
|
|
396
|
-
|
|
397
332
|
createModal();
|
|
398
333
|
attach();
|
|
399
|
-
|
|
400
|
-
exports.clearQueue = clearQueue;
|
|
401
|
-
exports.open = open;
|
|
402
|
-
exports.close = close;
|