@aarhus-university/au-lib-react-components 12.5.1 → 12.6.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.
Files changed (115) hide show
  1. package/.claude/settings.local.json +12 -0
  2. package/.eslintrc.js +35 -35
  3. package/.storybook/main.js +34 -34
  4. package/.storybook/preview.js +17 -17
  5. package/.vscode/settings.json +22 -0
  6. package/README.md +19 -19
  7. package/__tests__/jest/AUButtonComponent.test.tsx +165 -165
  8. package/__tests__/jest/AUDynamicContentComponent.test.tsx +386 -0
  9. package/__tests__/jest/AUErrorComponent.test.tsx +142 -142
  10. package/__tests__/jest/AUModalComponent.test.tsx +186 -186
  11. package/__tests__/jest/AUNotificationComponent.test.tsx +115 -115
  12. package/__tests__/jest/AUSpinnerComponent.test.tsx +57 -57
  13. package/__tests__/jest/AUToolbarComponent.test.tsx +46 -46
  14. package/__tests__/jest/context.test.ts +25 -25
  15. package/__tests__/jest/helpers.test.ts +15 -15
  16. package/__tests__/jest/setupTests.ts +2 -2
  17. package/babel.config.js +8 -8
  18. package/build/umd/all.css +3 -2
  19. package/build/umd/all.css.map +1 -7
  20. package/build/umd/all.js +2 -45
  21. package/build/umd/all.js.map +1 -7
  22. package/build/umd/alphabox.js +2 -45
  23. package/build/umd/alphabox.js.map +1 -7
  24. package/build/umd/databox.js +2 -45
  25. package/build/umd/databox.js.map +1 -7
  26. package/build/umd/diagramme.js +2 -44
  27. package/build/umd/diagramme.js.map +1 -7
  28. package/build/umd/flowbox.js +2 -44
  29. package/build/umd/flowbox.js.map +1 -7
  30. package/build/umd/universe.js +1 -1
  31. package/build-storybook.log +386 -386
  32. package/esbuild.mjs +22 -22
  33. package/package.json +107 -105
  34. package/src/components/AUAlertComponent.tsx +128 -128
  35. package/src/components/AUAutoSuggestComponent.js +148 -148
  36. package/src/components/AUButtonComponent.tsx +99 -97
  37. package/src/components/AUCalendarComponent.tsx +497 -497
  38. package/src/components/AUCharacterCountComponent.tsx +56 -56
  39. package/src/components/AUComboBoxComponent.tsx +195 -195
  40. package/src/components/AUContentToggleComponent.tsx +50 -50
  41. package/src/components/AUDatepickerComponent.tsx +124 -124
  42. package/src/components/AUDialogModalComponent.tsx +124 -124
  43. package/src/components/AUDynamicContentComponent.tsx +137 -0
  44. package/src/components/AUEditorComponent.tsx +126 -117
  45. package/src/components/AUErrorComponent.tsx +73 -73
  46. package/src/components/AUMobilePrefixComponent.tsx +20 -20
  47. package/src/components/AUModalComponent.tsx +72 -72
  48. package/src/components/AUNotificationComponent.tsx +44 -44
  49. package/src/components/AUReceiptComponent.tsx +34 -34
  50. package/src/components/AUSpinnerComponent.tsx +40 -40
  51. package/src/components/AUStepComponent.tsx +75 -75
  52. package/src/components/AUSubNavComponent.tsx +57 -57
  53. package/src/components/AUSubmitButtonContainerComponent.tsx +38 -38
  54. package/src/components/AUTabbedContentComponent.tsx +154 -154
  55. package/src/components/AUTableComponent.tsx +29 -29
  56. package/src/components/AUToastComponent.tsx +104 -104
  57. package/src/components/AUToolbarComponent.tsx +108 -108
  58. package/src/components/AUTruncatorComponent.tsx +141 -141
  59. package/src/components/wrapping/AUEmbedComponent.js +47 -47
  60. package/src/layout-2016/components/alphabox/AlphaBoxComponent.js +142 -143
  61. package/src/layout-2016/components/alphabox/AlphaBoxContentComponent.js +136 -136
  62. package/src/layout-2016/components/common/AUCollapsibleComponent.js +152 -152
  63. package/src/layout-2016/components/common/AUSpinnerComponent.js +103 -103
  64. package/src/layout-2016/components/databox/DataBoxAlphabetComponent.js +144 -144
  65. package/src/layout-2016/components/databox/DataBoxAssociationComponent.js +122 -122
  66. package/src/layout-2016/components/databox/DataBoxButtonComponent.js +157 -157
  67. package/src/layout-2016/components/databox/DataBoxComponent.js +297 -297
  68. package/src/layout-2016/components/databox/DataBoxGroupingComponent.js +64 -64
  69. package/src/layout-2016/components/databox/DataBoxSearchResultComponent.js +36 -36
  70. package/src/layout-2016/components/databox/DataBoxStackedAssociationComponent.js +54 -54
  71. package/src/layout-2016/components/databox/DataBoxSuggestionComponent.js +39 -39
  72. package/src/layout-2016/components/diagramme/AUDiagrammeComponent.js +309 -309
  73. package/src/layout-2016/components/flowbox/FlowBoxComponent.js +126 -126
  74. package/src/layout-2016/components/flowbox/FlowBoxPhoneComponent.js +104 -104
  75. package/src/layout-2016/lib/all.js +3 -3
  76. package/src/layout-2016/lib/au-alphabox.js +99 -100
  77. package/src/layout-2016/lib/au-databox.js +399 -400
  78. package/src/layout-2016/lib/au-diagramme.js +85 -85
  79. package/src/layout-2016/lib/au-flowbox.js +119 -93
  80. package/src/lib/context.tsx +59 -59
  81. package/src/lib/dates.ts +52 -52
  82. package/src/lib/helpers.ts +208 -208
  83. package/src/lib/hooks.ts +157 -157
  84. package/src/lib/i18n.ts +600 -600
  85. package/src/lib/portals.tsx +150 -150
  86. package/src/lib/tinymce.ts +84 -84
  87. package/src/lib/wrapping.ts +21 -21
  88. package/src/styles/_settings.scss +10 -10
  89. package/src/styles/alphabox.scss +222 -222
  90. package/src/styles/app.scss +7 -7
  91. package/src/styles/autosuggest.scss +57 -57
  92. package/src/styles/databox.scss +563 -563
  93. package/src/styles/diagramme.scss +119 -119
  94. package/src/styles/flowbox.scss +72 -72
  95. package/src/styles/maps.scss +395 -395
  96. package/stories/AUAlertComponent.stories.tsx +133 -133
  97. package/stories/AUAutoSuggestComponent.stories.tsx +95 -95
  98. package/stories/AUButtonComponent.stories.tsx +139 -139
  99. package/stories/AUCharacterCountComponent.stories.tsx +121 -121
  100. package/stories/AUComboBoxComponent.stories.tsx +101 -101
  101. package/stories/AUContentToggleComponent.stories.tsx +87 -87
  102. package/stories/AUDialogModalComponent.stories.tsx +75 -75
  103. package/stories/AUDynamicContentComponent.stories.tsx +119 -0
  104. package/stories/AUEditorComponent.stories.tsx +66 -66
  105. package/stories/AUErrorComponent.stories.tsx +132 -132
  106. package/stories/AUModalComponent.stories.tsx +160 -160
  107. package/stories/AUNotificationComponent.stories.tsx +151 -151
  108. package/stories/AUSpinnerComponent.stories.tsx +44 -44
  109. package/stories/AUStepComponent.stories.tsx +91 -91
  110. package/stories/AUToolbarComponent.stories.tsx +389 -389
  111. package/stories/AUTruncatorComponent.stories.tsx +123 -123
  112. package/stories/lib/helpers.tsx +146 -146
  113. package/tsconfig.json +46 -46
  114. package/webpack.config.js +88 -88
  115. package/src/lib/tracking.ts +0 -69
@@ -1,400 +1,399 @@
1
- /* eslint func-names: ["error", "never"] */
2
- /* eslint no-prototype-builtins: 0 */
3
- /* eslint no-restricted-syntax: 0 */
4
- /* eslint max-classes-per-file: 0 */
5
- /* eslint no-unused-vars: 0 */
6
- /* eslint-env browser */
7
- import React from 'react';
8
- import ReactDOM from 'react-dom';
9
- import DataBoxComponent from '../components/databox/DataBoxComponent';
10
-
11
- const defaultOptions = {
12
- config: {
13
- container: '.au_databox', // DOM-element
14
- firstline: true, // skal søgefeltet stå på en række for sig selv?
15
- alphabet: 2, // hvilken knap er alfabetet?
16
- initLetter: 'a', // Startbogstavet for alfabetet
17
- trigger: 0,
18
- tracking: '/virtual/databox/', // GA-tracking
19
- buttons: [ // Teksten knapperne - nyt!
20
- { text: 'Dummy knap 1', link: '' },
21
- { text: 'Dummy knap 2', link: '' },
22
- ],
23
- stacked: false,
24
- rememberState: false,
25
- expand: false,
26
- },
27
- background: {
28
- color: '#003d73',
29
- linkColor: '#003d73',
30
- src: '',
31
- height: 0,
32
- text: '',
33
- overlay: true,
34
- },
35
- search: {
36
- autocomplete: true,
37
- index: 1,
38
- minLength: 1,
39
- placeHolder: '',
40
- },
41
- data: {
42
- mode: 'json',
43
- source: '',
44
- callback: null,
45
- },
46
- };
47
-
48
- class AUDataboxParser {
49
- static json(source, callback) {
50
- if (source) {
51
- let sourceArr = [];
52
- if (!Array.isArray(source)) {
53
- sourceArr.push(source);
54
- } else {
55
- sourceArr = source;
56
- }
57
- const promises = [];
58
- sourceArr.forEach((s) => {
59
- promises.push(new Promise((resolve) => {
60
- fetch(s).then((promise) => promise.json()).then((data) => {
61
- resolve(data);
62
- });
63
- }));
64
- });
65
-
66
- Promise.all(promises).then((values) => {
67
- callback({
68
- items: values.map((x) => x.items)[0],
69
- groupings: values.map((x) => x.groupings)[0] || [],
70
- });
71
- });
72
- }
73
- }
74
-
75
- static xml(source, callback) {
76
- const xmlFunc = (data) => {
77
- const items = [];
78
- const children = [];
79
- const associations = [];
80
-
81
- let assocXML = [];
82
- let count = 1;
83
-
84
- do {
85
- assocXML = $(data).find(`associations${count} > item`);
86
-
87
- const assoc = [];
88
- for (let i = 0; i < assocXML.length; i += 1) {
89
- assoc.push({
90
- id: $(assocXML[i]).attr('id'),
91
- name: $(assocXML[i]).attr('name'),
92
- items: [],
93
- });
94
- }
95
-
96
- if (assoc.length > 0) {
97
- associations.push(assoc);
98
- }
99
-
100
- count += 1;
101
- } while (assocXML.length > 0);
102
-
103
- const itemsXML = $(data).find('items > item');
104
- $.each(itemsXML, function () {
105
- const extraXML = $(this).find('extra');
106
- const extra = [];
107
- $.each(extraXML.find('param'), () => {
108
- extra.push({
109
- param: $(this).text(),
110
- });
111
- });
112
- const obj = {
113
- id: $(this).attr('id'),
114
- name: $(this).attr('name'),
115
- url: $(this).attr('url'),
116
- parent: $(this).attr('parent'),
117
- extra,
118
- children: [],
119
- associations: [],
120
- };
121
-
122
- for (let i = 0; i < associations.length; i += 1) {
123
- const objAssoc = $(this).find(`association${parseInt(i + 1, 10)}`);
124
-
125
- obj.associations.push([]);
126
-
127
- for (let j = 0; j < objAssoc.length; j += 1) {
128
- const id = parseInt($(objAssoc[j]).attr('id'), 10) - 1;
129
- obj.associations[i].push({
130
- id: associations[i][id].id,
131
- name: associations[i][id].name,
132
- });
133
- associations[i][id].items.push(obj);
134
- }
135
- }
136
-
137
- items.push(obj);
138
- if (typeof obj.parent !== 'undefined' && obj.parent !== '') {
139
- children.push(obj);
140
- }
141
- });
142
-
143
- for (let c = 0; c < children.length; c += 1) {
144
- const pid = children[c].parent;
145
- for (let p = 0; p < items.length; p += 1) {
146
- if (items[p].id === pid) {
147
- items[p].children.push(children[c]);
148
- break;
149
- }
150
- }
151
- }
152
-
153
- const groupings = [];
154
- for (let i = 0; i < associations.length; i += 1) {
155
- groupings.push({
156
- id: i,
157
- associations: associations[i],
158
- });
159
- }
160
-
161
- callback({
162
- rawData: data,
163
- items,
164
- groupings,
165
- });
166
- };
167
-
168
- AU.helpers.getXML(source, (data) => {
169
- xmlFunc(data);
170
- });
171
- }
172
-
173
- static table(source, callback) {
174
- const table = $(`${source} > table`);
175
- const list = $(`${source} > ul`);
176
-
177
- const items = [];
178
- const children = [];
179
- const associations = [];
180
-
181
- $('li', list).each(function () {
182
- const assoc = [];
183
- $('> ul > li', this).each(function (i) {
184
- assoc.push({
185
- id: i,
186
- name: $(this).text(),
187
- items: [],
188
- });
189
- });
190
-
191
- if (assoc.length > 0) {
192
- associations.push(assoc);
193
- }
194
- });
195
-
196
- $('tr', table).each(function (i) {
197
- if (i > 0) {
198
- const cells = $('td', this);
199
-
200
- const id = parseInt(cells.eq(0).text(), 10);
201
- const parent = parseInt(cells.eq(1).text(), 10);
202
- let name = cells.eq(2).text();
203
- name = name.trim();
204
- const url = $('a', cells.eq(2)).attr('href');
205
- const skip = 3; // Antallet af celler, som ikke angiver associations!
206
-
207
- const obj = {
208
- id,
209
- name,
210
- url,
211
- parent,
212
- extra: [],
213
- children: [],
214
- associations: [],
215
- };
216
-
217
- for (let j = 0; j < associations.length; j += 1) {
218
- const assocCell = cells.eq(j + skip).text();
219
- const assocCellSplit = assocCell.split(',');
220
-
221
- obj.associations.push([]);
222
-
223
- for (let k = 0; k < assocCellSplit.length; k += 1) {
224
- const aid = parseInt(assocCellSplit[k], 10) - 1;
225
-
226
- if (typeof associations[j][aid] !== 'undefined') {
227
- obj.associations[j].push({
228
- id: associations[j][aid].id,
229
- name: associations[j][aid].name,
230
- });
231
-
232
- associations[j][aid].items.push(obj);
233
- }
234
- }
235
- }
236
-
237
- if (obj.parent === 0 || obj.parent === '') {
238
- items.push(obj);
239
- } else {
240
- children.push(obj);
241
- }
242
- }
243
- });
244
-
245
- for (let c = 0; c < children.length; c += 1) {
246
- const pid = children[c].parent;
247
- for (let p = 0; p < items.length; p += 1) {
248
- if (items[p].id === pid) {
249
- items[p].children.push(children[c]);
250
- break;
251
- }
252
- }
253
- }
254
-
255
- const groupings = [];
256
- for (let i = 0; i < associations.length; i += 1) {
257
- groupings.push({
258
- id: i,
259
- associations: associations[i],
260
- });
261
- }
262
-
263
- callback({
264
- items,
265
- groupings,
266
- });
267
- }
268
-
269
- static list(source, callback) {
270
- const list = $(source);
271
- const items = [];
272
- $('li', list).each(function (i) {
273
- items.push({
274
- id: i,
275
- label: $(this).text(),
276
- value: $(this).text(),
277
- name: $(this).text(),
278
- url: $('a', this).attr('href'),
279
- children: [],
280
- associations: [],
281
- });
282
- });
283
-
284
- callback({
285
- items,
286
- groupings: [],
287
- });
288
- }
289
- }
290
- class AUDatabox {
291
- constructor(boxes) {
292
- this.boxes = boxes;
293
- }
294
-
295
- static mergeOptions(_box) {
296
- const box = _box;
297
- if (!box.hasOwnProperty('config')) {
298
- box.config = {};
299
- }
300
-
301
- for (const conf in defaultOptions.config) {
302
- if (!box.config.hasOwnProperty(conf)) {
303
- box.config[conf] = defaultOptions.config[conf];
304
- }
305
- }
306
-
307
- if (!box.hasOwnProperty('background')) {
308
- box.background = {};
309
- }
310
-
311
- for (const bg in defaultOptions.background) {
312
- if (!box.background.hasOwnProperty(bg)) {
313
- box.background[bg] = defaultOptions.background[bg];
314
- }
315
- }
316
-
317
- if (!box.hasOwnProperty('search')) {
318
- box.search = {};
319
- }
320
-
321
- for (const sch in defaultOptions.search) {
322
- if (!box.search.hasOwnProperty(sch)) {
323
- box.search[sch] = defaultOptions.search[sch];
324
- }
325
- }
326
-
327
- if (!box.hasOwnProperty('data')) {
328
- box.data = {};
329
- }
330
-
331
- for (const data in defaultOptions.data) {
332
- if (!box.data.hasOwnProperty(data)) {
333
- box.data[data] = defaultOptions.data[data];
334
- }
335
- }
336
-
337
- return box;
338
- }
339
-
340
- static legacyCleanUp(_box) {
341
- const box = _box;
342
- const container = $(box.config.container);
343
- if (container !== null) {
344
- const containerChildren = $('> *:not(.no-header)', container); // Kan både være div og h2 elementer
345
- if (containerChildren.length > 0) {
346
- box.config.buttons = [];
347
- containerChildren.each(function () {
348
- box.config.buttons.push({
349
- text: $(this).text(),
350
- link: '',
351
- });
352
- });
353
- }
354
- }
355
- }
356
-
357
- init() {
358
- const parser = {
359
- json: AUDataboxParser.json,
360
- xml: AUDataboxParser.xml,
361
- table: AUDataboxParser.table,
362
- list: AUDataboxParser.list,
363
- };
364
-
365
- for (let i = 0; i < this.boxes.length; i += 1) {
366
- let box = this.boxes[i];
367
- if (!box.loaded) {
368
- box = AUDatabox.mergeOptions(box);
369
- box.id = i;
370
- AUDatabox.legacyCleanUp(box);
371
- // I stedet for at skulle rette alle gamle søgebokse,
372
- // hvor knappernes tekst er sat direkte i HTML'en,
373
- // finder vi knapperne her og indsætter dem som 'buttons' i config'en
374
- const mountNode = document.querySelector(box.config.container);
375
- const visible = mountNode && getComputedStyle(mountNode).visibility !== 'hidden';
376
- if (!box.config.stacked
377
- && AU.responsive.state
378
- && AU.responsive.state.NAME === 'PHONE') {
379
- box.config.stacked = true;
380
- }
381
- if (visible) {
382
- ReactDOM.render(<DataBoxComponent
383
- box={box}
384
- parse={parser[box.data.mode]}
385
- />, mountNode);
386
- box.loaded = true;
387
- }
388
-
389
- if (box.data.mode === 'table' || box.data.mode === 'list') {
390
- const dataElement = document.querySelector(box.data.source);
391
- if (dataElement) {
392
- dataElement.parentNode.removeChild(dataElement);
393
- }
394
- }
395
- }
396
- }
397
- }
398
- }
399
-
400
- window.AUDatabox = AUDatabox;
1
+ /* eslint func-names: ["error", "never"] */
2
+ /* eslint no-prototype-builtins: 0 */
3
+ /* eslint no-restricted-syntax: 0 */
4
+ /* eslint max-classes-per-file: 0 */
5
+ /* eslint no-unused-vars: 0 */
6
+ /* eslint-env browser */
7
+ import React from 'react';
8
+ import ReactDOM from 'react-dom';
9
+ import DataBoxComponent from '../components/databox/DataBoxComponent';
10
+
11
+ const defaultOptions = {
12
+ config: {
13
+ container: '.au_databox', // DOM-element
14
+ firstline: true, // skal søgefeltet stå på en række for sig selv?
15
+ alphabet: 2, // hvilken knap er alfabetet?
16
+ initLetter: 'a', // Startbogstavet for alfabetet
17
+ trigger: 0,
18
+ buttons: [ // Teksten på knapperne - nyt!
19
+ { text: 'Dummy knap 1', link: '' },
20
+ { text: 'Dummy knap 2', link: '' },
21
+ ],
22
+ stacked: false,
23
+ rememberState: false,
24
+ expand: false,
25
+ },
26
+ background: {
27
+ color: '#003d73',
28
+ linkColor: '#003d73',
29
+ src: '',
30
+ height: 0,
31
+ text: '',
32
+ overlay: true,
33
+ },
34
+ search: {
35
+ autocomplete: true,
36
+ index: 1,
37
+ minLength: 1,
38
+ placeHolder: '',
39
+ },
40
+ data: {
41
+ mode: 'json',
42
+ source: '',
43
+ callback: null,
44
+ },
45
+ };
46
+
47
+ class AUDataboxParser {
48
+ static json(source, callback) {
49
+ if (source) {
50
+ let sourceArr = [];
51
+ if (!Array.isArray(source)) {
52
+ sourceArr.push(source);
53
+ } else {
54
+ sourceArr = source;
55
+ }
56
+ const promises = [];
57
+ sourceArr.forEach((s) => {
58
+ promises.push(new Promise((resolve) => {
59
+ fetch(s).then((promise) => promise.json()).then((data) => {
60
+ resolve(data);
61
+ });
62
+ }));
63
+ });
64
+
65
+ Promise.all(promises).then((values) => {
66
+ callback({
67
+ items: values.map((x) => x.items)[0],
68
+ groupings: values.map((x) => x.groupings)[0] || [],
69
+ });
70
+ });
71
+ }
72
+ }
73
+
74
+ static xml(source, callback) {
75
+ const xmlFunc = (data) => {
76
+ const items = [];
77
+ const children = [];
78
+ const associations = [];
79
+
80
+ let assocXML = [];
81
+ let count = 1;
82
+
83
+ do {
84
+ assocXML = $(data).find(`associations${count} > item`);
85
+
86
+ const assoc = [];
87
+ for (let i = 0; i < assocXML.length; i += 1) {
88
+ assoc.push({
89
+ id: $(assocXML[i]).attr('id'),
90
+ name: $(assocXML[i]).attr('name'),
91
+ items: [],
92
+ });
93
+ }
94
+
95
+ if (assoc.length > 0) {
96
+ associations.push(assoc);
97
+ }
98
+
99
+ count += 1;
100
+ } while (assocXML.length > 0);
101
+
102
+ const itemsXML = $(data).find('items > item');
103
+ $.each(itemsXML, function () {
104
+ const extraXML = $(this).find('extra');
105
+ const extra = [];
106
+ $.each(extraXML.find('param'), () => {
107
+ extra.push({
108
+ param: $(this).text(),
109
+ });
110
+ });
111
+ const obj = {
112
+ id: $(this).attr('id'),
113
+ name: $(this).attr('name'),
114
+ url: $(this).attr('url'),
115
+ parent: $(this).attr('parent'),
116
+ extra,
117
+ children: [],
118
+ associations: [],
119
+ };
120
+
121
+ for (let i = 0; i < associations.length; i += 1) {
122
+ const objAssoc = $(this).find(`association${parseInt(i + 1, 10)}`);
123
+
124
+ obj.associations.push([]);
125
+
126
+ for (let j = 0; j < objAssoc.length; j += 1) {
127
+ const id = parseInt($(objAssoc[j]).attr('id'), 10) - 1;
128
+ obj.associations[i].push({
129
+ id: associations[i][id].id,
130
+ name: associations[i][id].name,
131
+ });
132
+ associations[i][id].items.push(obj);
133
+ }
134
+ }
135
+
136
+ items.push(obj);
137
+ if (typeof obj.parent !== 'undefined' && obj.parent !== '') {
138
+ children.push(obj);
139
+ }
140
+ });
141
+
142
+ for (let c = 0; c < children.length; c += 1) {
143
+ const pid = children[c].parent;
144
+ for (let p = 0; p < items.length; p += 1) {
145
+ if (items[p].id === pid) {
146
+ items[p].children.push(children[c]);
147
+ break;
148
+ }
149
+ }
150
+ }
151
+
152
+ const groupings = [];
153
+ for (let i = 0; i < associations.length; i += 1) {
154
+ groupings.push({
155
+ id: i,
156
+ associations: associations[i],
157
+ });
158
+ }
159
+
160
+ callback({
161
+ rawData: data,
162
+ items,
163
+ groupings,
164
+ });
165
+ };
166
+
167
+ AU.helpers.getXML(source, (data) => {
168
+ xmlFunc(data);
169
+ });
170
+ }
171
+
172
+ static table(source, callback) {
173
+ const table = $(`${source} > table`);
174
+ const list = $(`${source} > ul`);
175
+
176
+ const items = [];
177
+ const children = [];
178
+ const associations = [];
179
+
180
+ $('li', list).each(function () {
181
+ const assoc = [];
182
+ $('> ul > li', this).each(function (i) {
183
+ assoc.push({
184
+ id: i,
185
+ name: $(this).text(),
186
+ items: [],
187
+ });
188
+ });
189
+
190
+ if (assoc.length > 0) {
191
+ associations.push(assoc);
192
+ }
193
+ });
194
+
195
+ $('tr', table).each(function (i) {
196
+ if (i > 0) {
197
+ const cells = $('td', this);
198
+
199
+ const id = parseInt(cells.eq(0).text(), 10);
200
+ const parent = parseInt(cells.eq(1).text(), 10);
201
+ let name = cells.eq(2).text();
202
+ name = name.trim();
203
+ const url = $('a', cells.eq(2)).attr('href');
204
+ const skip = 3; // Antallet af celler, som ikke angiver associations!
205
+
206
+ const obj = {
207
+ id,
208
+ name,
209
+ url,
210
+ parent,
211
+ extra: [],
212
+ children: [],
213
+ associations: [],
214
+ };
215
+
216
+ for (let j = 0; j < associations.length; j += 1) {
217
+ const assocCell = cells.eq(j + skip).text();
218
+ const assocCellSplit = assocCell.split(',');
219
+
220
+ obj.associations.push([]);
221
+
222
+ for (let k = 0; k < assocCellSplit.length; k += 1) {
223
+ const aid = parseInt(assocCellSplit[k], 10) - 1;
224
+
225
+ if (typeof associations[j][aid] !== 'undefined') {
226
+ obj.associations[j].push({
227
+ id: associations[j][aid].id,
228
+ name: associations[j][aid].name,
229
+ });
230
+
231
+ associations[j][aid].items.push(obj);
232
+ }
233
+ }
234
+ }
235
+
236
+ if (obj.parent === 0 || obj.parent === '') {
237
+ items.push(obj);
238
+ } else {
239
+ children.push(obj);
240
+ }
241
+ }
242
+ });
243
+
244
+ for (let c = 0; c < children.length; c += 1) {
245
+ const pid = children[c].parent;
246
+ for (let p = 0; p < items.length; p += 1) {
247
+ if (items[p].id === pid) {
248
+ items[p].children.push(children[c]);
249
+ break;
250
+ }
251
+ }
252
+ }
253
+
254
+ const groupings = [];
255
+ for (let i = 0; i < associations.length; i += 1) {
256
+ groupings.push({
257
+ id: i,
258
+ associations: associations[i],
259
+ });
260
+ }
261
+
262
+ callback({
263
+ items,
264
+ groupings,
265
+ });
266
+ }
267
+
268
+ static list(source, callback) {
269
+ const list = $(source);
270
+ const items = [];
271
+ $('li', list).each(function (i) {
272
+ items.push({
273
+ id: i,
274
+ label: $(this).text(),
275
+ value: $(this).text(),
276
+ name: $(this).text(),
277
+ url: $('a', this).attr('href'),
278
+ children: [],
279
+ associations: [],
280
+ });
281
+ });
282
+
283
+ callback({
284
+ items,
285
+ groupings: [],
286
+ });
287
+ }
288
+ }
289
+ class AUDatabox {
290
+ constructor(boxes) {
291
+ this.boxes = boxes;
292
+ }
293
+
294
+ static mergeOptions(_box) {
295
+ const box = _box;
296
+ if (!box.hasOwnProperty('config')) {
297
+ box.config = {};
298
+ }
299
+
300
+ for (const conf in defaultOptions.config) {
301
+ if (!box.config.hasOwnProperty(conf)) {
302
+ box.config[conf] = defaultOptions.config[conf];
303
+ }
304
+ }
305
+
306
+ if (!box.hasOwnProperty('background')) {
307
+ box.background = {};
308
+ }
309
+
310
+ for (const bg in defaultOptions.background) {
311
+ if (!box.background.hasOwnProperty(bg)) {
312
+ box.background[bg] = defaultOptions.background[bg];
313
+ }
314
+ }
315
+
316
+ if (!box.hasOwnProperty('search')) {
317
+ box.search = {};
318
+ }
319
+
320
+ for (const sch in defaultOptions.search) {
321
+ if (!box.search.hasOwnProperty(sch)) {
322
+ box.search[sch] = defaultOptions.search[sch];
323
+ }
324
+ }
325
+
326
+ if (!box.hasOwnProperty('data')) {
327
+ box.data = {};
328
+ }
329
+
330
+ for (const data in defaultOptions.data) {
331
+ if (!box.data.hasOwnProperty(data)) {
332
+ box.data[data] = defaultOptions.data[data];
333
+ }
334
+ }
335
+
336
+ return box;
337
+ }
338
+
339
+ static legacyCleanUp(_box) {
340
+ const box = _box;
341
+ const container = $(box.config.container);
342
+ if (container !== null) {
343
+ const containerChildren = $('> *:not(.no-header)', container); // Kan både være div og h2 elementer
344
+ if (containerChildren.length > 0) {
345
+ box.config.buttons = [];
346
+ containerChildren.each(function () {
347
+ box.config.buttons.push({
348
+ text: $(this).text(),
349
+ link: '',
350
+ });
351
+ });
352
+ }
353
+ }
354
+ }
355
+
356
+ init() {
357
+ const parser = {
358
+ json: AUDataboxParser.json,
359
+ xml: AUDataboxParser.xml,
360
+ table: AUDataboxParser.table,
361
+ list: AUDataboxParser.list,
362
+ };
363
+
364
+ for (let i = 0; i < this.boxes.length; i += 1) {
365
+ let box = this.boxes[i];
366
+ if (!box.loaded) {
367
+ box = AUDatabox.mergeOptions(box);
368
+ box.id = i;
369
+ AUDatabox.legacyCleanUp(box);
370
+ // I stedet for at skulle rette alle gamle søgebokse,
371
+ // hvor knappernes tekst er sat direkte i HTML'en,
372
+ // finder vi knapperne her og indsætter dem som 'buttons' i config'en
373
+ const mountNode = document.querySelector(box.config.container);
374
+ const visible = mountNode && getComputedStyle(mountNode).visibility !== 'hidden';
375
+ if (!box.config.stacked
376
+ && AU.responsive.state
377
+ && AU.responsive.state.NAME === 'PHONE') {
378
+ box.config.stacked = true;
379
+ }
380
+ if (visible) {
381
+ ReactDOM.render(<DataBoxComponent
382
+ box={box}
383
+ parse={parser[box.data.mode]}
384
+ />, mountNode);
385
+ box.loaded = true;
386
+ }
387
+
388
+ if (box.data.mode === 'table' || box.data.mode === 'list') {
389
+ const dataElement = document.querySelector(box.data.source);
390
+ if (dataElement) {
391
+ dataElement.parentNode.removeChild(dataElement);
392
+ }
393
+ }
394
+ }
395
+ }
396
+ }
397
+ }
398
+
399
+ window.AUDatabox = AUDatabox;