hr-design-system-handlebars 1.124.10 → 1.125.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.
@@ -29,10 +29,7 @@ const ExternalService = function (context) {
29
29
  let embedCode = options.embedCode,
30
30
  iframe,
31
31
  settingsCookie = new SettingsCookie(),
32
- noResponsiveIframe,
33
- contentRefresher,
34
32
  gemeindewahlergebnis,
35
- uniqueId,
36
33
  isExternalServiceLoaded = false,
37
34
  tiktokOnPage = []
38
35
 
@@ -74,61 +71,34 @@ const ExternalService = function (context) {
74
71
  }
75
72
 
76
73
  const insertExternalService = function () {
77
- switch (embedType) {
78
- case 'js':
79
- switch (id) {
80
- case '23degrees':
81
- createTwentyThreeDegreesEmbed()
82
- break
83
- case 'facebook-post':
84
- createFacebookEmbed()
85
- break
86
- case 'instagram':
87
- createInstagramEmbed()
88
- break
89
- case 'tiktok':
90
- createTikTokEmbed()
91
- break
92
- case 'twitter':
93
- createTwitterEmbed()
94
- break
95
- case 'twitter-post':
96
- createTwitterPostEmbed()
97
- break
98
- case 'datawrapper_cdn':
99
- createDataWrapperEmbed()
100
- break
101
- case 'wahlmonitor':
102
- createWahlEmbed()
103
- break
104
- case 'wahlmonitor_v2':
105
- createWahlEmbed()
106
- break
107
- case 'wahlkreiskarte':
108
- createWahlEmbed()
109
- break
110
- case 'wahlkreiskarte_v2':
111
- createWahlEmbed()
112
- break
113
- case 'wahlomat-euwa':
114
- createWahlOMatEuwaEmbed()
115
- break
116
- case 'wahlomat-butawa':
117
- createWahlOMatButawaEmbed()
118
- break
119
- case 'wahl-gemeinde-ergebnis':
120
- createWahlGemeindeErgebnisEmbed()
121
- break
122
- case 'wer-waehlte-wen':
123
- werWaehlteWenEmbed()
124
- break
125
- default:
126
- console.error('No JS Config for external service ' + id)
127
- break
128
- }
129
- break
130
- default:
131
- loadIframe() //für alle Dienste die nicht der DSGVO Datapolicy unterliegen
74
+ if (embedType !== 'js') {
75
+ loadIframe() // Für alle Dienste, die nicht der DSGVO Datapolicy unterliegen
76
+ return
77
+ }
78
+
79
+ const externalServiceMap = {
80
+ '23degrees': createTwentyThreeDegreesEmbed,
81
+ 'facebook-post': createFacebookEmbed,
82
+ 'instagram': createInstagramEmbed,
83
+ 'tiktok': createTikTokEmbed,
84
+ 'twitter': createTwitterEmbed,
85
+ 'twitter-post': createTwitterPostEmbed,
86
+ 'datawrapper_cdn': createDataWrapperEmbed,
87
+ 'wahlmonitor': createWahlEmbed,
88
+ 'wahlmonitor_v2': createWahlEmbed,
89
+ 'wahlkreiskarte': createWahlEmbed,
90
+ 'wahlkreiskarte_v2': createWahlEmbed,
91
+ 'wahlomat-euwa': createWahlOMatEuwaEmbed,
92
+ 'wahlomat-butawa': createWahlOMatButawaEmbed,
93
+ 'wahl-gemeinde-ergebnis': createWahlGemeindeErgebnisEmbed,
94
+ 'wer-waehlte-wen': werWaehlteWenEmbed,
95
+ }
96
+
97
+ const service = externalServiceMap[id]
98
+ if (service) {
99
+ service()
100
+ } else {
101
+ console.error(`No JS Config for external service ${id}`)
132
102
  }
133
103
  }
134
104
 
@@ -206,14 +176,6 @@ const ExternalService = function (context) {
206
176
  })
207
177
  }
208
178
 
209
- const createUniqueID = function () {
210
- console.log('Erzeuge einzigartige ID')
211
- uniqueId = Math.random()
212
- .toString(36)
213
- .replace(/[^a-z]+/g, '')
214
- .substring(2, 10)
215
- }
216
-
217
179
  const getAspectRatioClass = function () {
218
180
  switch (iFrameConfig.aspectRatio) {
219
181
  case '16x9':
@@ -237,96 +199,104 @@ const ExternalService = function (context) {
237
199
 
238
200
  const createDataWrapperEmbed = function () {
239
201
  removeDatapolicyBox()
240
- createUniqueID()
241
- console.log('UniqueID' + uniqueId)
242
- if (iFrameConfig.noResponsiveIframe == 'true') {
202
+ const uniqueId = createUniqueID()
203
+ const {
204
+ isNoResponsiveIframe,
205
+ isWebcomponent,
206
+ refreshContent,
207
+ aspectRatio,
208
+ fixedHeight,
209
+ refreshIntervall,
210
+ } = iFrameConfig
211
+
212
+ const addContentRefresher = (isWebcomponent) => {
213
+ new DataWrapperContentRefresher({
214
+ rootElement,
215
+ id: uniqueId,
216
+ refreshIntervall,
217
+ isWebcomponent,
218
+ }).createRefresher()
219
+ }
220
+
221
+ if (isNoResponsiveIframe == 'true') {
243
222
  //Klassisches Iframe mit AR-Wrapper oder fester Höhe
244
- noResponsiveIframe = new DataWrapperNoResponsiveIframe(
245
- context,
246
- iFrameConfig.aspectRatio,
247
- iFrameConfig.fixedHeight,
248
- uniqueId,
249
- embedCode,
250
- lazyLoad
251
- )
252
- noResponsiveIframe.createNoResponsiveIframe()
253
-
254
- if (iFrameConfig.refreshContent == 'true') {
255
- console.log('contentRefresher anfügen')
256
- contentRefresher = new DataWrapperContentRefresher(
257
- context,
258
- uniqueId,
259
- iFrameConfig.refreshIntervall,
260
- false
261
- )
262
- contentRefresher.createRefresher()
223
+ new DataWrapperNoResponsiveIframe({
224
+ rootElement: rootElement,
225
+ aspectRatio: aspectRatio,
226
+ fixedHeight: fixedHeight,
227
+ id: uniqueId,
228
+ embedCode: embedCode,
229
+ lazyLoad: lazyLoad,
230
+ }).createNoResponsiveIframe()
231
+
232
+ if (refreshContent == 'true') {
233
+ addContentRefresher(false)
263
234
  }
264
- } else {
265
- if (iFrameConfig.webcomponent == 'true') {
266
- // Webcomponent
267
- const divTag = document.createElement('div')
268
- divTag.id = 'datawrapper-chart-' + uniqueId
269
- rootElement.insertBefore(divTag, null)
270
- const scriptTag = document.createElement('script')
271
- scriptTag.setAttribute('id', 'datawrapper-component-js')
272
- scriptTag.setAttribute('type', 'text/javascript')
273
- scriptTag.setAttribute('defer', 'defer')
274
- scriptTag.setAttribute('src', embedCode + 'embed.js?v=1')
275
- scriptTag.setAttribute('charset', 'utf-8')
276
- const noScriptTag = document.createElement('noscript')
277
- const imageTag = document.createElement('img')
278
- imageTag.src = embedCode + 'full.png'
279
- imageTag.alt = ''
280
- noScriptTag.appendChild(imageTag)
281
- divTag.appendChild(scriptTag)
282
- divTag.appendChild(noScriptTag)
283
-
284
- if (iFrameConfig.refreshContent == 'true') {
285
- console.log('contentRefresher anfügen')
286
- contentRefresher = new DataWrapperContentRefresher(
287
- context,
288
- uniqueId,
289
- iFrameConfig.refreshIntervall,
290
- true
291
- )
292
- contentRefresher.createRefresher()
293
- }
294
- } else {
295
- //Responsives Iframe
296
- var iframe = document.createElement('iframe')
297
- //Auflösen nach Tailwind-Klassen //dataWrapper-embed
298
- iframe.className = 'w-0 !min-w-full border-0'
299
- iframe.setAttribute('webkitallowfullscreen', '')
300
- iframe.setAttribute('mozallowfullscreen', '')
301
- iframe.setAttribute('allowfullscreen', '')
302
- iframe.setAttribute('scrolling', 'no')
303
- iframe.setAttribute('frameborder', '0')
304
- iframe.src = embedCode
305
- iframe.id = 'datawrapper-chart-' + uniqueId
306
- if (lazyLoad) {
307
- iframe.loading = 'lazy'
308
- }
309
- rootElement.insertBefore(iframe, null)
235
+ return
236
+ }
310
237
 
311
- loadScript(
312
- 'datawrapper-js',
313
- 'https://static.hr.de/hessenschau/datawrapper/responsiveIframe.js',
314
- true
315
- )
316
- if (iFrameConfig.refreshContent == 'true') {
317
- console.log('contentRefresher anfügen')
318
- contentRefresher = new DataWrapperContentRefresher(
319
- context,
320
- uniqueId,
321
- iFrameConfig.refreshIntervall,
322
- false
323
- )
324
- contentRefresher.createRefresher()
325
- }
238
+ if (isWebcomponent == 'true') {
239
+ // Webcomponent
240
+ const divTag = document.createElement('div')
241
+ divTag.id = `datawrapper-chart-${uniqueId}`
242
+ rootElement.appendChild(divTag)
243
+
244
+ const scriptTag = document.createElement('script')
245
+ Object.assign(scriptTag, {
246
+ id: 'datawrapper-component-js',
247
+ type: 'text/javascript',
248
+ defer: true,
249
+ src: `${embedCode}embed.js?v=1`,
250
+ charset: 'utf-8',
251
+ })
252
+
253
+ const noScriptTag = document.createElement('noscript')
254
+ const imageTag = document.createElement('img')
255
+ imageTag.src = `${embedCode}full.png`
256
+ imageTag.alt = ''
257
+ noScriptTag.appendChild(imageTag)
258
+
259
+ divTag.append(scriptTag, noScriptTag)
260
+
261
+ if (refreshContent == 'true') {
262
+ addContentRefresher(true)
326
263
  }
264
+ return
265
+ }
266
+ //Responsives Iframe
267
+ const iframe = document.createElement('iframe')
268
+ //Auflösen nach Tailwind-Klassen //dataWrapper-embed
269
+ iframe.className = 'w-0 !min-w-full border-0'
270
+ iframe.setAttribute('webkitallowfullscreen', '')
271
+ iframe.setAttribute('mozallowfullscreen', '')
272
+ iframe.setAttribute('allowfullscreen', '')
273
+ iframe.setAttribute('scrolling', 'no')
274
+ iframe.setAttribute('frameborder', '0')
275
+ iframe.src = embedCode
276
+ iframe.id = `datawrapper-chart-${uniqueId}`
277
+ if (lazyLoad) {
278
+ iframe.loading = 'lazy'
279
+ }
280
+ rootElement.appendChild(iframe)
281
+
282
+ loadScript(
283
+ 'datawrapper-js',
284
+ 'https://static.hr.de/hessenschau/datawrapper/responsiveIframe.js',
285
+ true
286
+ )
287
+ if (refreshContent == 'true') {
288
+ addContentRefresher(false)
327
289
  }
328
290
  }
329
291
 
292
+ const createUniqueID = function () {
293
+ console.log('Erzeuge einzigartige ID')
294
+ return Math.random()
295
+ .toString(36)
296
+ .replace(/[^a-z]+/g, '')
297
+ .substring(2, 10)
298
+ }
299
+
330
300
  const createTwentyThreeDegreesEmbed = function () {
331
301
  removeDatapolicyBox()
332
302
 
@@ -3,7 +3,7 @@
3
3
  <div class="c-externalService c-externalService__{{this.externalServiceConfig.externalServiceId}}{{#unless
4
4
  this.fixedHeight }} -noFixedHeight{{/unless}} js-load"
5
5
  data-hr-external-service-ds='{"id":"{{this.externalServiceConfig.externalServiceId}}","embedCode":"{{this.serviceUrl}}","embedType":"{{this.externalServiceConfig.externalServiceEmbedType}}","lazyLoad":{{defaultIfEmpty _lazyLoad false}},"dataPolicyCheck": true, "whiteList":{{this.externalServiceConfig.isWhitelisted}},"iFrameConfig": { {{~#if this.fixedHeight~}}
6
- "fixedHeight":"{{this.fixedHeight}}"{{~else~}}{{~#if this.aspectRatio}}"aspectRatio":"{{this.aspectRatio}}"{{~else~}}"aspectRatio":"16x9"{{/if}}{{~/if}},"noResponsiveIframe":"{{{this.setResponsiveIframe}}}","webcomponent":"{{{this.setWebcomponent}}}"{{~#if this.setTimedReloadIframe}},"refreshContent":"{{{this.setTimedReloadIframe}}}","refreshIntervall":"{{this.setTimeForReload}}"{{~/if}} }}'>
6
+ "fixedHeight":"{{this.fixedHeight}}"{{~else~}}{{~#if this.aspectRatio}}"aspectRatio":"{{this.aspectRatio}}"{{~else~}}"aspectRatio":"16x9"{{/if}}{{~/if}},"isNoResponsiveIframe":"{{{this.setResponsiveIframe}}}","isWebcomponent":"{{{this.setWebcomponent}}}"{{~#if this.setTimedReloadIframe}},"refreshContent":"{{{this.setTimedReloadIframe}}}","refreshIntervall":"{{this.setTimeForReload}}"{{~/if}} }}'>
7
7
  {{~> components/external-service/components/external_service_data_policy ~}}
8
8
  </div>
9
9
  {{~> components/external-service/components/external_service_caption ~}}
@@ -3,7 +3,7 @@
3
3
  <div class="c-externalService c-externalService__{{this.externalServiceConfig.externalServiceId}}{{#unless
4
4
  this.fixedHeight }} -noFixedHeight{{/unless}} js-load"
5
5
  data-hr-external-service-ds='{"id":"{{this.externalServiceConfig.externalServiceId}}","embedCode":"{{this.serviceUrl}}","embedType":"{{this.externalServiceConfig.externalServiceEmbedType}}","lazyLoad":{{defaultIfEmpty _lazyLoad false}},"dataPolicyCheck": true, "whiteList":{{this.externalServiceConfig.isWhitelisted}},"iFrameConfig": { {{~#if this.fixedHeight~}}
6
- "fixedHeight":"{{this.fixedHeight}}"{{~else~}}{{~#if this.aspectRatio}}"aspectRatio":"{{this.aspectRatio}}"{{~else~}}"aspectRatio":"16x9"{{/if}}{{~/if}},"noResponsiveIframe":"{{{this.setResponsiveIframe}}}","webcomponent":"{{{this.setWebcomponent}}}"{{~#if this.setTimedReloadIframe}},"refreshContent":"{{{this.setTimedReloadIframe}}}","refreshIntervall":"{{this.setTimeForReload}}"{{~/if}} }}'>
6
+ "fixedHeight":"{{this.fixedHeight}}"{{~else~}}{{~#if this.aspectRatio}}"aspectRatio":"{{this.aspectRatio}}"{{~else~}}"aspectRatio":"16x9"{{/if}}{{~/if}},"isNoResponsiveIframe":"{{{this.setResponsiveIframe}}}","isWebcomponent":"{{{this.setWebcomponent}}}"{{~#if this.setTimedReloadIframe}},"refreshContent":"{{{this.setTimedReloadIframe}}}","refreshIntervall":"{{this.setTimeForReload}}"{{~/if}} }}'>
7
7
  {{~> components/external-service/components/external_service_data_policy ~}}
8
8
  </div>
9
9
  {{~> components/external-service/components/external_service_caption ~}}
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "license": "MIT",
7
7
  "main": "dist/index.js",
8
8
  "repository": "https://github.com/szuelch/hr-design-system-handlebars",
9
- "version": "1.124.10",
9
+ "version": "1.125.0",
10
10
  "scripts": {
11
11
  "test": "echo \"Error: no test specified\" && exit 1",
12
12
  "storybook": "storybook dev -p 6006 public",
@@ -1,88 +1,95 @@
1
-
2
- const DataWrapperContentRefresher = function (context, id, refreshIntervall, webcomponent, datapolicy) {
3
- const { element: rootElement } = context
1
+ const DataWrapperContentRefresher = function ({
2
+ rootElement,
3
+ id,
4
+ refreshIntervall,
5
+ isWebcomponent,
6
+ datapolicy,
7
+ }) {
4
8
  let remainingTime
5
9
  let timer
6
- let uniqueID = id
7
10
  let intervall = refreshIntervall
8
11
  let container
9
- let script
12
+ let script
10
13
  let iframeRefresh
11
-
12
- if (webcomponent) {
13
- container = document.getElementById('datawrapper-chart-' + uniqueID)
14
- script = document.getElementById('datawrapper-component-js')
15
- }
16
- else{
17
- iframeRefresh = document.getElementById('datawrapper-chart-' + uniqueID)
14
+
15
+ if (isWebcomponent) {
16
+ container = document.getElementById(`datawrapper-chart-${id}`)
17
+ script = document.getElementById('datawrapper-component-js')
18
+ } else {
19
+ iframeRefresh = document.getElementById(`datawrapper-chart-${id}`)
18
20
  }
19
-
21
+
20
22
  const createRefresher = function () {
21
- console.log("Refresher bauen")
22
- let divCounter = document.createElement('div')
23
+ console.log('Refresher bauen')
24
+ const divCounter = document.createElement('div')
25
+ divCounter.id = 'counter' + id
26
+ Object.assign(divCounter.style, {
27
+ backgroundColor: '#006dc1',
28
+ color: '#fff',
29
+ fontSize: '12px',
30
+ padding: '8px',
31
+ borderRadius: '0 0 4px 4px',
32
+ })
33
+
23
34
  let divOverlay = document.createElement('div')
35
+ divOverlay.id = 'overlay' + id
36
+ Object.assign(divOverlay.style, {
37
+ position: 'absolute',
38
+ top: '0',
39
+ display: 'none',
40
+ alignItems: 'center',
41
+ justifyContent: 'center',
42
+ backgroundColor: '#d8e9f6',
43
+ width: '100%',
44
+ height: 'calc(100% - 36px)',
45
+ })
46
+
24
47
  let divTextOverlay = document.createElement('div')
25
- divOverlay.id = 'overlay' + uniqueID
26
- divOverlay.style.position = 'absolute'
27
- divOverlay.style.top = '0'
28
- divOverlay.style.display = 'none'
29
- divOverlay.style.alignItems = 'center'
30
- divOverlay.style.justifyContent = 'center'
31
- divOverlay.style.backgroundColor = '#fff'
32
- divOverlay.style.width = '100%'
33
- divOverlay.style.height = 'calc(100% - 36px)'
34
- divOverlay.style.backgroundColor = '#d8e9f6'
35
48
  divTextOverlay.innerHTML = 'Lade Inhalt neu...'
36
- divTextOverlay.style.backgroundColor = '#005293'
37
- divTextOverlay.style.padding = '8px'
38
- divTextOverlay.style.color = '#fff'
39
- divTextOverlay.style.fontWeight = '800'
40
- divTextOverlay.style.fontFamily = 'RobotoSlab'
41
- divTextOverlay.style.borderRadius = '6px 6px 6px 6px'
49
+ Object.assign(divTextOverlay.style, {
50
+ backgroundColor: '#005293',
51
+ padding: '8px',
52
+ color: '#fff',
53
+ fontWeight: '800',
54
+ fontFamily: 'RobotoSlab',
55
+ borderRadius: '6px',
56
+ })
57
+
42
58
  divOverlay.appendChild(divTextOverlay)
43
- divCounter.id = 'counter' + uniqueID
44
- divCounter.style.backgroundColor = '#006dc1'
45
- divCounter.style.color = '#fff'
46
- divCounter.style.fontSize = '12px'
47
- divCounter.style.padding = '8px'
48
- divCounter.style.borderRadius = '0 0 4px 4px'
49
-
59
+
50
60
  rootElement.style.position = 'relative'
51
- if(!datapolicy) {
52
- rootElement.appendChild(divCounter)
53
- rootElement.appendChild(divOverlay)
54
- startCountdown()
55
- }
56
- else {
57
- rootElement.removeChild(divCounter)
58
- rootElement.removeChild(divOverlay)
59
- stopCountdown()
61
+
62
+ if (!datapolicy) {
63
+ rootElement.appendChild(divCounter)
64
+ rootElement.appendChild(divOverlay)
65
+ startCountdown()
66
+ } else {
67
+ rootElement.removeChild(divCounter)
68
+ rootElement.removeChild(divOverlay)
69
+ stopCountdown()
60
70
  }
61
71
  }
62
72
 
63
73
  const refreshIframe = function () {
64
74
  console.log('Reload')
65
- if(webcomponent) {
75
+ if (isWebcomponent) {
66
76
  container.style.opacity = '0'
67
77
  script.src = script.src.split('?')[0] + '?_=' + new Date().getTime()
68
- }
69
- else{
78
+ } else {
70
79
  iframeRefresh.style.opacity = '0'
71
- iframeRefresh.src =
72
- iframeRefresh.src.split('?')[0] + '?_=' + new Date().getTime()
80
+ iframeRefresh.src = iframeRefresh.src.split('?')[0] + '?_=' + new Date().getTime()
73
81
  }
74
82
  clearInterval(timer)
75
83
  }
76
84
  const startCountdown = function () {
77
85
  remainingTime = Number(intervall)
78
86
  setTimeout(function () {
79
- if(webcomponent) {
80
- container.style.opacity = '1'
81
- }
82
- else{
87
+ if (isWebcomponent) {
88
+ container.style.opacity = '1'
89
+ } else {
83
90
  iframeRefresh.style.opacity = '1'
84
91
  }
85
- document.getElementById('overlay' + uniqueID).style.display = 'none'
92
+ document.getElementById('overlay' + id).style.display = 'none'
86
93
  }, 1000)
87
94
  timer = setInterval(function () {
88
95
  checkTimer()
@@ -92,33 +99,34 @@ const DataWrapperContentRefresher = function (context, id, refreshIntervall, web
92
99
  clearInterval(timer)
93
100
  }
94
101
  const checkTimer = function () {
95
- if(document.getElementById('counter' + uniqueID) !== null) {
102
+ if (document.getElementById('counter' + id) !== null) {
96
103
  if (remainingTime >= 0) {
97
- document.getElementById('counter' + uniqueID).innerHTML =
104
+ document.getElementById('counter' + id).innerHTML =
98
105
  'Dieser Inhalt wird automatisch aktualisiert in ' +
99
106
  secondsToTimeString(remainingTime) +
100
107
  ' Min.'
101
108
  remainingTime -= 1
102
109
  if (remainingTime == -1) {
103
- document.getElementById('overlay' + uniqueID).style.display = 'flex'
104
- document.getElementById('counter' + uniqueID).innerHTML =
110
+ document.getElementById('overlay' + id).style.display = 'flex'
111
+ document.getElementById('counter' + id).innerHTML =
105
112
  'Zeitintervall wird neu gestartet...'
106
113
  }
107
114
  } else {
108
115
  refreshIframe()
109
116
  startCountdown()
110
117
  }
111
- }else{
112
- console.log("Element wurde entfernt")
118
+ } else {
119
+ console.log('Element wurde entfernt')
113
120
  clearInterval(timer)
114
121
  }
115
122
  }
123
+
116
124
  const secondsToTimeString = function (seconds) {
117
125
  return new Date(seconds * 1000).toISOString().substr(14, 5)
118
126
  }
119
127
  return {
120
- createRefresher: createRefresher
128
+ createRefresher: createRefresher,
121
129
  }
122
130
  }
123
131
 
124
- export default DataWrapperContentRefresher
132
+ export default DataWrapperContentRefresher