@aarhus-university/au-lib-react-components 11.3.2 → 11.4.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.
Files changed (97) hide show
  1. package/.eslintrc.js +34 -34
  2. package/.storybook/main.js +20 -20
  3. package/.storybook/preview.js +17 -17
  4. package/README.md +19 -19
  5. package/__tests__/jest/AUButtonComponent.test.tsx +165 -165
  6. package/__tests__/jest/AUErrorComponent.test.tsx +142 -142
  7. package/__tests__/jest/AUModalComponent.test.tsx +186 -186
  8. package/__tests__/jest/AUNotificationComponent.test.tsx +115 -115
  9. package/__tests__/jest/AUSpinnerComponent.test.tsx +57 -57
  10. package/__tests__/jest/AUToolbarComponent.test.tsx +46 -46
  11. package/__tests__/jest/context.test.ts +25 -25
  12. package/__tests__/jest/helpers.test.ts +15 -15
  13. package/__tests__/jest/setupTests.ts +2 -2
  14. package/babel.config.js +8 -8
  15. package/build/umd/all.css +2 -2
  16. package/build/umd/all.js +1 -1
  17. package/build/umd/alphabox.js +1 -1
  18. package/build/umd/databox.js +1 -1
  19. package/build/umd/diagramme.js +1 -1
  20. package/build/umd/flowbox.js +1 -1
  21. package/build/umd/universe.js +1 -1
  22. package/build-storybook.log +367 -367
  23. package/package.json +114 -114
  24. package/src/components/AUAlertComponent.tsx +70 -70
  25. package/src/components/AUAutoSuggestComponent.js +158 -158
  26. package/src/components/AUButtonComponent.tsx +84 -84
  27. package/src/components/AUCalendarComponent.tsx +493 -493
  28. package/src/components/AUContentToggleComponent.tsx +47 -47
  29. package/src/components/AUDatepickerComponent.tsx +121 -121
  30. package/src/components/AUErrorComponent.tsx +78 -78
  31. package/src/components/AUMobilePrefixComponent.tsx +15 -15
  32. package/src/components/AUModalComponent.tsx +68 -68
  33. package/src/components/AUNotificationComponent.tsx +43 -43
  34. package/src/components/AUReceiptComponent.tsx +33 -33
  35. package/src/components/AUSpinnerComponent.tsx +36 -36
  36. package/src/components/AUStepComponent.tsx +47 -41
  37. package/src/components/AUSubNavComponent.tsx +48 -48
  38. package/src/components/AUSubmitButtonContainerComponent.tsx +29 -29
  39. package/src/components/AUTabbedContentComponent.tsx +145 -145
  40. package/src/components/AUTableComponent.tsx +24 -24
  41. package/src/components/AUToastComponent.tsx +104 -104
  42. package/src/components/AUToolbarComponent.tsx +101 -101
  43. package/src/components/AUTruncatorComponent.tsx +124 -129
  44. package/src/components/wrapping/AUEmbedComponent.js +47 -47
  45. package/src/layout-2016/components/alphabox/AlphaBoxComponent.js +143 -143
  46. package/src/layout-2016/components/alphabox/AlphaBoxContentComponent.js +136 -136
  47. package/src/layout-2016/components/common/AUCollapsibleComponent.js +152 -152
  48. package/src/layout-2016/components/common/AUSpinnerComponent.js +103 -103
  49. package/src/layout-2016/components/databox/DataBoxAlphabetComponent.js +144 -144
  50. package/src/layout-2016/components/databox/DataBoxAssociationComponent.js +122 -122
  51. package/src/layout-2016/components/databox/DataBoxButtonComponent.js +157 -157
  52. package/src/layout-2016/components/databox/DataBoxComponent.js +297 -297
  53. package/src/layout-2016/components/databox/DataBoxGroupingComponent.js +64 -64
  54. package/src/layout-2016/components/databox/DataBoxSearchResultComponent.js +36 -36
  55. package/src/layout-2016/components/databox/DataBoxStackedAssociationComponent.js +54 -54
  56. package/src/layout-2016/components/databox/DataBoxSuggestionComponent.js +39 -39
  57. package/src/layout-2016/components/diagramme/AUDiagrammeComponent.js +309 -309
  58. package/src/layout-2016/components/flowbox/FlowBoxComponent.js +126 -126
  59. package/src/layout-2016/components/flowbox/FlowBoxPhoneComponent.js +104 -104
  60. package/src/layout-2016/components/profile/AUProfileAvatar2016Component.js +103 -103
  61. package/src/layout-2016/components/universe/StaffTopComponent.js +363 -363
  62. package/src/layout-2016/components/universe/StudentTopComponent.js +137 -137
  63. package/src/layout-2016/components/universe/UniverseContainerComponent.js +65 -65
  64. package/src/layout-2016/lib/all.js +3 -3
  65. package/src/layout-2016/lib/au-alphabox.js +100 -100
  66. package/src/layout-2016/lib/au-databox.js +400 -400
  67. package/src/layout-2016/lib/au-diagramme.js +85 -85
  68. package/src/layout-2016/lib/au-flowbox.js +93 -93
  69. package/src/layout-2016/lib/universe.js +9 -9
  70. package/src/lib/context.tsx +51 -51
  71. package/src/lib/dates.ts +50 -50
  72. package/src/lib/helpers.ts +208 -208
  73. package/src/lib/hooks.ts +75 -75
  74. package/src/lib/i18n.ts +600 -600
  75. package/src/lib/portals.tsx +119 -119
  76. package/src/lib/tracking.ts +69 -69
  77. package/src/lib/wrapping.ts +21 -21
  78. package/src/styles/_settings.scss +10 -10
  79. package/src/styles/alphabox.scss +222 -222
  80. package/src/styles/app.scss +7 -7
  81. package/src/styles/autosuggest.scss +57 -57
  82. package/src/styles/databox.scss +563 -563
  83. package/src/styles/diagramme.scss +119 -119
  84. package/src/styles/flowbox.scss +72 -72
  85. package/src/styles/maps.scss +395 -395
  86. package/stories/AUButtonComponent.stories.tsx +127 -127
  87. package/stories/AUContentToggleComponent.stories.tsx +63 -63
  88. package/stories/AUErrorComponent.stories.tsx +98 -98
  89. package/stories/AUModalComponent.stories.tsx +83 -83
  90. package/stories/AUNotificationComponent.stories.tsx +116 -116
  91. package/stories/AUSpinnerComponent.stories.tsx +41 -41
  92. package/stories/AUStepComponent.stories.tsx +40 -40
  93. package/stories/AUToolbarComponent.stories.tsx +326 -326
  94. package/stories/AUTruncatorComponent.stories.tsx +102 -0
  95. package/stories/lib/helpers.tsx +128 -128
  96. package/tsconfig.json +46 -46
  97. package/webpack.config.js +89 -89
@@ -1,400 +1,400 @@
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 på 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
+ tracking: '/virtual/databox/', // GA-tracking
19
+ buttons: [ // Teksten på 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;