hr-design-system-handlebars 0.56.8 → 0.56.9

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/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # v0.56.9 (Fri Sep 02 2022)
2
+
3
+ #### 🐛 Bug Fix
4
+
5
+ - Feature/dpe 1567 [#314](https://github.com/mumprod/hr-design-system-handlebars/pull/314) ([@szuelch](https://github.com/szuelch))
6
+
7
+ #### Authors: 1
8
+
9
+ - [@szuelch](https://github.com/szuelch)
10
+
11
+ ---
12
+
1
13
  # v0.56.8 (Thu Sep 01 2022)
2
14
 
3
15
  #### 🐛 Bug Fix
@@ -1897,7 +1897,7 @@ video {
1897
1897
  transition-timing-function: cubic-bezier(0.4, 0, 1, 1);
1898
1898
  }
1899
1899
  .counter-reset {
1900
- counter-reset: cnt1662058116451;
1900
+ counter-reset: cnt1662109528702;
1901
1901
  }
1902
1902
  .placeholder-text-xs::-webkit-input-placeholder {
1903
1903
  font-size: 0.75rem;
@@ -2280,7 +2280,7 @@ video {
2280
2280
  --tw-ring-color: rgba(255, 255, 255, 0.5);
2281
2281
  }
2282
2282
  .-ordered {
2283
- counter-increment: cnt1662058116451 1;
2283
+ counter-increment: cnt1662109528702 1;
2284
2284
  }
2285
2285
  .-ordered::before {
2286
2286
  position: absolute;
@@ -2297,7 +2297,7 @@ video {
2297
2297
  letter-spacing: .0125em;
2298
2298
  --tw-text-opacity: 1;
2299
2299
  color: rgba(0, 0, 0, var(--tw-text-opacity));
2300
- content: counter(cnt1662058116451);
2300
+ content: counter(cnt1662109528702);
2301
2301
  }
2302
2302
  /*! purgecss start ignore */
2303
2303
  :root,
@@ -1,7 +1,7 @@
1
1
  import Initializer from 'initializer'
2
2
  import loadFeature from 'loadFeature'
3
3
 
4
- const hr$ = (selector, element) => {
4
+ const hr$ = function (selector, element) {
5
5
  // if element set, use it
6
6
  // if not use document as default
7
7
  const rootElement = element || document
@@ -34,24 +34,19 @@ const hr$ = (selector, element) => {
34
34
  return rootElement.querySelectorAll(selector)
35
35
  }
36
36
 
37
- const stripTags = text => {
38
- if (text) {
39
- return text.replace(/(<([^>]+)>)/gi, '')
40
- }
41
- return false
42
- }
37
+ const stripTags = (text) => (text ? text.replace(/(<([^>]+)>)/gi, '') : false)
43
38
 
44
39
  const getViewportWidth = () =>
45
40
  Math.max(document.documentElement.clientWidth, window.innerWidth || 0)
46
41
 
47
- const isString = value => Object.prototype.toString.call(value) === '[object String]'
42
+ const isString = (value) => Object.prototype.toString.call(value) === '[object String]'
48
43
 
49
- const isElementInViewport = el => {
44
+ const isElementInViewport = (el) => {
50
45
  const rect = el.getBoundingClientRect()
51
46
  return rect.top <= (document.documentElement || document.body).clientHeight
52
47
  }
53
48
 
54
- const getClosestParentWithTag = (tagName, node) => {
49
+ const getClosestParentWithTag = function (tagName, node) {
55
50
  while (node !== null && node.tagName !== 'BODY') {
56
51
  if (node.tagName && node.tagName.toLowerCase() === tagName) {
57
52
  return node
@@ -61,7 +56,7 @@ const getClosestParentWithTag = (tagName, node) => {
61
56
  return false
62
57
  }
63
58
 
64
- const getNodeWithClassInPath = (className, startNode) => {
59
+ const getNodeWithClassInPath = function (className, startNode) {
65
60
  let node = startNode
66
61
 
67
62
  while (node && node !== document) {
@@ -73,7 +68,7 @@ const getNodeWithClassInPath = (className, startNode) => {
73
68
  return false
74
69
  }
75
70
 
76
- const isDescendant = (parent, child) => {
71
+ const isDescendant = function (parent, child) {
77
72
  let node = child.parentNode
78
73
  while (node !== null) {
79
74
  if (node === parent) {
@@ -85,9 +80,9 @@ const isDescendant = (parent, child) => {
85
80
  }
86
81
 
87
82
  /* wartet x ms seit dem letzen aufruf bis es ausgeführt wird */
88
- const debounce = (fn, delay) => {
83
+ const debounce = function (fn, delay) {
89
84
  let timer = null
90
- return (...args) => {
85
+ return function (...args) {
91
86
  const context = this
92
87
  clearTimeout(timer)
93
88
  timer = setTimeout(() => {
@@ -96,11 +91,11 @@ const debounce = (fn, delay) => {
96
91
  }
97
92
  }
98
93
  /* feuert all x ms */
99
- const throttle = (fn, threshhold, scope) => {
94
+ const throttle = function (fn, threshhold, scope) {
100
95
  threshhold = threshhold || 250
101
96
  let last
102
97
  let deferTimer
103
- return (...args) => {
98
+ return function (...args) {
104
99
  const context = scope || this
105
100
 
106
101
  const now = +new Date()
@@ -128,10 +123,10 @@ const throttle = (fn, threshhold, scope) => {
128
123
  canOnlyFireOnce(); // nada
129
124
  *
130
125
  */
131
- const once = (fn, context) => {
126
+ const once = function (fn, context) {
132
127
  let result
133
128
 
134
- return (...args) => {
129
+ return function (...args) {
135
130
  if (fn) {
136
131
  result = fn.apply(context || this, args)
137
132
  fn = null
@@ -141,16 +136,25 @@ const once = (fn, context) => {
141
136
  }
142
137
  }
143
138
 
144
- const listen = (eventName, fn, documentNode) => {
139
+ const listen = function (eventName, fn, documentNode, forceActive = false) {
145
140
  documentNode = documentNode === undefined ? document : documentNode
146
141
 
142
+ // Use passive listeners to improve scrolling performance
143
+ // See:
144
+ // https://web.dev/uses-passive-event-listeners/
145
+ // https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
146
+
147
+ const isTouchOrMouseEvent =
148
+ eventName === 'touchstart' || eventName === 'touchmove' || eventName === 'wheel'
149
+ const isPassive = Modernizr.passiveeventlisteners && !forceActive && isTouchOrMouseEvent
150
+
147
151
  if (window.attachEvent) {
148
152
  documentNode.attachEvent(eventName, fn)
149
153
  } else {
150
- documentNode.addEventListener(eventName, fn)
154
+ documentNode.addEventListener(eventName, fn, isPassive ? { passive: true } : false)
151
155
  }
152
156
  }
153
- const unlisten = (eventName, fn, documentNode) => {
157
+ const unlisten = function (eventName, fn, documentNode) {
154
158
  documentNode = documentNode === undefined ? document : documentNode
155
159
 
156
160
  if (window.attachEvent) {
@@ -159,7 +163,7 @@ const unlisten = (eventName, fn, documentNode) => {
159
163
  documentNode.removeEventListener(eventName, fn)
160
164
  }
161
165
  }
162
- const listenOnce = (eventName, fn, documentNode) => {
166
+ const listenOnce = function (eventName, fn, documentNode) {
163
167
  documentNode = documentNode === undefined ? document : documentNode
164
168
 
165
169
  documentNode.addEventListener(eventName, fn, { once: true })
@@ -194,7 +198,7 @@ const setJSONCookie = (cookieName, cookieValue, cookieLifetime) => {
194
198
  setCookie(cookieName, JSON.stringify(cookieValue), cookieLifetime)
195
199
  }
196
200
 
197
- const setCookie = (cookieName, cookieValue, cookieLifetime) => {
201
+ const setCookie = function (cookieName, cookieValue, cookieLifetime) {
198
202
  let expires
199
203
 
200
204
  const domain = getDomain()
@@ -211,7 +215,7 @@ const setCookie = (cookieName, cookieValue, cookieLifetime) => {
211
215
  cookieName + '=' + cookieValue + ';expires=' + expires + ';domain=' + domain + ';path=/;'
212
216
  }
213
217
 
214
- const getJSONCookie = cookieName => {
218
+ const getJSONCookie = (cookieName) => {
215
219
  let cookie
216
220
 
217
221
  try {
@@ -221,12 +225,12 @@ const getJSONCookie = cookieName => {
221
225
  return cookie
222
226
  }
223
227
 
224
- const getCookie = cookieName => {
228
+ const getCookie = (cookieName) => {
225
229
  let cookieString = RegExp('' + cookieName + '[^;]+').exec(document.cookie)
226
230
  return unescape(!!cookieString ? cookieString.toString().replace(/^[^=]+./, '') : '')
227
231
  }
228
232
 
229
- const deleteCookie = cookieName => {
233
+ const deleteCookie = (cookieName) => {
230
234
  const domain = getDomain()
231
235
  document.cookie =
232
236
  cookieName + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;domain=' + domain + ';path=/;'
@@ -235,17 +239,18 @@ const deleteCookie = cookieName => {
235
239
  const getDomain = () => {
236
240
  return window.location.hostname.substring(window.location.hostname.indexOf('.') + 1)
237
241
  }
238
- const requestTimeout = (fn, delay) => {
239
- var requestAnimFrame = (function() {
242
+ const requestTimeout = function (fn, delay) {
243
+ var requestAnimFrame = (function () {
240
244
  return (
241
245
  window.requestAnimationFrame ||
242
- function(callback, element) {
246
+ function (callback, element) {
243
247
  window.setTimeout(callback, 1000 / 60)
244
248
  }
245
249
  )
246
250
  })(),
247
251
  start = new Date().getTime(),
248
252
  handle = {}
253
+
249
254
  function loop() {
250
255
  var current = new Date().getTime(),
251
256
  delta = current - start
@@ -255,11 +260,12 @@ const requestTimeout = (fn, delay) => {
255
260
  handle.value = requestAnimFrame(loop)
256
261
  }
257
262
  }
263
+
258
264
  handle.value = requestAnimFrame(loop)
259
265
  return handle
260
266
  }
261
267
 
262
- const replaceAnimated = (
268
+ const replaceAnimated = function (
263
269
  elem,
264
270
  data,
265
271
  rescan,
@@ -269,7 +275,7 @@ const replaceAnimated = (
269
275
  valueTo,
270
276
  easing,
271
277
  duration
272
- ) => {
278
+ ) {
273
279
  const property = 'opacity'
274
280
  timeoutDelay = timeoutDelay || 800
275
281
  valueFrom = valueFrom || 0.2
@@ -283,7 +289,7 @@ const replaceAnimated = (
283
289
 
284
290
  elem.style[property] = valueFrom
285
291
 
286
- requestTimeout(function() {
292
+ requestTimeout(function () {
287
293
  if (data) {
288
294
  elem.innerHTML = data
289
295
  }
@@ -300,33 +306,33 @@ const replaceAnimated = (
300
306
  }, timeoutDelay)
301
307
  }
302
308
 
303
- hr$.loadScript = function(id, scriptUrl, async, callback) {
304
- if (document.getElementById(id)) return
309
+ const getScrollY = () =>
310
+ window.pageYOffset !== undefined
311
+ ? window.pageYOffset
312
+ : (document.documentElement || document.body.parentNode || document.body).scrollTop
305
313
 
306
- var firstScriptTagInPage = hr$('script')[0],
307
- scriptTag = document.createElement('script')
314
+ //Funktion um X & Y Offset eines Elements zu ermitteln
315
+ const getElementOffset = function (el) {
316
+ let _x = 0
317
+ let _y = 0
318
+ _x = Math.round(el.getBoundingClientRect().left)
319
+ _y = Math.round(el.getBoundingClientRect().top)
308
320
 
309
- scriptTag.id = id
310
- scriptTag.src = scriptUrl
321
+ return { top: _y, left: _x }
322
+ }
311
323
 
312
- if (async) {
313
- scriptTag.setAttribute('async', !!async)
314
- }
324
+ const reinitializeFeature = function (element) {
325
+ Initializer.run(element, loadFeature)
326
+ }
315
327
 
316
- if (callback) {
317
- scriptTag.addEventListener(
318
- 'load',
319
- function(e) {
320
- callback(null, e)
321
- },
322
- false
323
- )
328
+ const removeScript = function (id) {
329
+ const element = document.getElementById(id)
330
+ if (element) {
331
+ element.parentNode.removeChild(element)
324
332
  }
325
-
326
- firstScriptTagInPage.parentNode.insertBefore(scriptTag, firstScriptTagInPage)
327
333
  }
328
334
 
329
- const loadScript = (id, scriptUrl, async, callback) => {
335
+ const loadScript = function (id, scriptUrl, async, callback) {
330
336
  if (document.getElementById(id)) return
331
337
 
332
338
  let firstScriptTagInPage = hr$('script')[0],
@@ -342,7 +348,7 @@ const loadScript = (id, scriptUrl, async, callback) => {
342
348
  if (callback) {
343
349
  scriptTag.addEventListener(
344
350
  'load',
345
- function(e) {
351
+ function (e) {
346
352
  callback(null, e)
347
353
  },
348
354
  false
@@ -352,7 +358,94 @@ const loadScript = (id, scriptUrl, async, callback) => {
352
358
  firstScriptTagInPage.parentNode.insertBefore(scriptTag, firstScriptTagInPage)
353
359
  }
354
360
 
361
+ /*
362
+ * Fügt ein "style" bereich zum dokument hinzu
363
+ * und gibt eine referenz darauf zurück
364
+ * auf der man dann mit insertRule arbeiten kann
365
+ */
366
+ const addStyle = function (css, mediaQuery) {
367
+ // Create the <style> tag
368
+ const style = document.createElement('style')
369
+
370
+ if (mediaQuery) {
371
+ style.setAttribute('media', mediaQuery)
372
+ }
373
+
374
+ // Add the <style> element to the page
375
+ if (style.styleSheet) {
376
+ style.styleSheet.cssText = css || ''
377
+ } else {
378
+ style.appendChild(document.createTextNode(css || ''))
379
+ }
380
+
381
+ document.head.appendChild(style)
382
+
383
+ return style.sheet
384
+ }
385
+
386
+ const simulateClickOn = function (elem) {
387
+ elem.dispatchEvent(
388
+ new MouseEvent('click', {
389
+ view: window,
390
+ bubbles: true,
391
+ cancelable: true,
392
+ })
393
+ )
394
+ }
395
+
396
+ /*!
397
+ * Behaves the same as setInterval except uses requestAnimationFrame() where possible for better performance
398
+ * modified gist.github.com/joelambert/1002116
399
+ * the fallback function requestAnimFrame is incorporated
400
+ * gist.github.com/joelambert/1002116
401
+ * gist.github.com/englishextra/873c8f78bfda7cafc905f48a963df07b
402
+ * jsfiddle.net/englishextra/sxrzktkz/
403
+ * @param {Object} fn The callback function
404
+ * @param {Int} delay The delay in milliseconds
405
+ * requestInterval(fn, delay);
406
+ */
407
+ const requestInterval = function (fn, delay) {
408
+ const requestAnimFrame = (function () {
409
+ return (
410
+ window.requestAnimationFrame ||
411
+ function (callback, element) {
412
+ window.setTimeout(callback, 1000 / 60)
413
+ }
414
+ )
415
+ })(),
416
+ handle = {}
417
+ let start = new Date().getTime()
418
+
419
+ function loop() {
420
+ handle.value = requestAnimFrame(loop)
421
+ const current = new Date().getTime(),
422
+ delta = current - start
423
+ if (delta >= delay) {
424
+ fn.call()
425
+ start = new Date().getTime()
426
+ }
427
+ }
428
+
429
+ handle.value = requestAnimFrame(loop)
430
+ return handle
431
+ }
432
+
433
+ /*!
434
+ * Behaves the same as clearInterval except uses cancelRequestAnimationFrame()
435
+ * where possible for better performance
436
+ * gist.github.com/joelambert/1002116
437
+ * gist.github.com/englishextra/873c8f78bfda7cafc905f48a963df07b
438
+ * jsfiddle.net/englishextra/sxrzktkz/
439
+ * @param {Int|Object} handle function handle, or function
440
+ * clearRequestInterval(handle);
441
+ */
442
+ const clearRequestInterval = (handle) =>
443
+ window.cancelAnimationFrame && handle
444
+ ? window.cancelAnimationFrame(handle.value)
445
+ : window.clearInterval(handle)
446
+
355
447
  export {
448
+ addStyle,
356
449
  hr$,
357
450
  stripTags,
358
451
  getViewportWidth,
@@ -373,8 +466,15 @@ export {
373
466
  setJSONCookie,
374
467
  getJSONCookie,
375
468
  getCookie,
469
+ getScrollY,
470
+ getElementOffset,
376
471
  deleteCookie,
472
+ requestInterval,
473
+ clearRequestInterval,
377
474
  requestTimeout,
378
475
  replaceAnimated,
379
- loadScript
476
+ loadScript,
477
+ removeScript,
478
+ reinitializeFeature,
479
+ simulateClickOn,
380
480
  }
@@ -1,7 +1,7 @@
1
1
  import Initializer from 'initializer'
2
2
  import loadFeature from 'loadFeature'
3
3
 
4
- const hr$ = (selector, element) => {
4
+ const hr$ = function (selector, element) {
5
5
  // if element set, use it
6
6
  // if not use document as default
7
7
  const rootElement = element || document
@@ -34,24 +34,19 @@ const hr$ = (selector, element) => {
34
34
  return rootElement.querySelectorAll(selector)
35
35
  }
36
36
 
37
- const stripTags = text => {
38
- if (text) {
39
- return text.replace(/(<([^>]+)>)/gi, '')
40
- }
41
- return false
42
- }
37
+ const stripTags = (text) => (text ? text.replace(/(<([^>]+)>)/gi, '') : false)
43
38
 
44
39
  const getViewportWidth = () =>
45
40
  Math.max(document.documentElement.clientWidth, window.innerWidth || 0)
46
41
 
47
- const isString = value => Object.prototype.toString.call(value) === '[object String]'
42
+ const isString = (value) => Object.prototype.toString.call(value) === '[object String]'
48
43
 
49
- const isElementInViewport = el => {
44
+ const isElementInViewport = (el) => {
50
45
  const rect = el.getBoundingClientRect()
51
46
  return rect.top <= (document.documentElement || document.body).clientHeight
52
47
  }
53
48
 
54
- const getClosestParentWithTag = (tagName, node) => {
49
+ const getClosestParentWithTag = function (tagName, node) {
55
50
  while (node !== null && node.tagName !== 'BODY') {
56
51
  if (node.tagName && node.tagName.toLowerCase() === tagName) {
57
52
  return node
@@ -61,7 +56,7 @@ const getClosestParentWithTag = (tagName, node) => {
61
56
  return false
62
57
  }
63
58
 
64
- const getNodeWithClassInPath = (className, startNode) => {
59
+ const getNodeWithClassInPath = function (className, startNode) {
65
60
  let node = startNode
66
61
 
67
62
  while (node && node !== document) {
@@ -73,7 +68,7 @@ const getNodeWithClassInPath = (className, startNode) => {
73
68
  return false
74
69
  }
75
70
 
76
- const isDescendant = (parent, child) => {
71
+ const isDescendant = function (parent, child) {
77
72
  let node = child.parentNode
78
73
  while (node !== null) {
79
74
  if (node === parent) {
@@ -85,9 +80,9 @@ const isDescendant = (parent, child) => {
85
80
  }
86
81
 
87
82
  /* wartet x ms seit dem letzen aufruf bis es ausgeführt wird */
88
- const debounce = (fn, delay) => {
83
+ const debounce = function (fn, delay) {
89
84
  let timer = null
90
- return (...args) => {
85
+ return function (...args) {
91
86
  const context = this
92
87
  clearTimeout(timer)
93
88
  timer = setTimeout(() => {
@@ -96,11 +91,11 @@ const debounce = (fn, delay) => {
96
91
  }
97
92
  }
98
93
  /* feuert all x ms */
99
- const throttle = (fn, threshhold, scope) => {
94
+ const throttle = function (fn, threshhold, scope) {
100
95
  threshhold = threshhold || 250
101
96
  let last
102
97
  let deferTimer
103
- return (...args) => {
98
+ return function (...args) {
104
99
  const context = scope || this
105
100
 
106
101
  const now = +new Date()
@@ -128,10 +123,10 @@ const throttle = (fn, threshhold, scope) => {
128
123
  canOnlyFireOnce(); // nada
129
124
  *
130
125
  */
131
- const once = (fn, context) => {
126
+ const once = function (fn, context) {
132
127
  let result
133
128
 
134
- return (...args) => {
129
+ return function (...args) {
135
130
  if (fn) {
136
131
  result = fn.apply(context || this, args)
137
132
  fn = null
@@ -141,16 +136,25 @@ const once = (fn, context) => {
141
136
  }
142
137
  }
143
138
 
144
- const listen = (eventName, fn, documentNode) => {
139
+ const listen = function (eventName, fn, documentNode, forceActive = false) {
145
140
  documentNode = documentNode === undefined ? document : documentNode
146
141
 
142
+ // Use passive listeners to improve scrolling performance
143
+ // See:
144
+ // https://web.dev/uses-passive-event-listeners/
145
+ // https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
146
+
147
+ const isTouchOrMouseEvent =
148
+ eventName === 'touchstart' || eventName === 'touchmove' || eventName === 'wheel'
149
+ const isPassive = Modernizr.passiveeventlisteners && !forceActive && isTouchOrMouseEvent
150
+
147
151
  if (window.attachEvent) {
148
152
  documentNode.attachEvent(eventName, fn)
149
153
  } else {
150
- documentNode.addEventListener(eventName, fn)
154
+ documentNode.addEventListener(eventName, fn, isPassive ? { passive: true } : false)
151
155
  }
152
156
  }
153
- const unlisten = (eventName, fn, documentNode) => {
157
+ const unlisten = function (eventName, fn, documentNode) {
154
158
  documentNode = documentNode === undefined ? document : documentNode
155
159
 
156
160
  if (window.attachEvent) {
@@ -159,7 +163,7 @@ const unlisten = (eventName, fn, documentNode) => {
159
163
  documentNode.removeEventListener(eventName, fn)
160
164
  }
161
165
  }
162
- const listenOnce = (eventName, fn, documentNode) => {
166
+ const listenOnce = function (eventName, fn, documentNode) {
163
167
  documentNode = documentNode === undefined ? document : documentNode
164
168
 
165
169
  documentNode.addEventListener(eventName, fn, { once: true })
@@ -194,7 +198,7 @@ const setJSONCookie = (cookieName, cookieValue, cookieLifetime) => {
194
198
  setCookie(cookieName, JSON.stringify(cookieValue), cookieLifetime)
195
199
  }
196
200
 
197
- const setCookie = (cookieName, cookieValue, cookieLifetime) => {
201
+ const setCookie = function (cookieName, cookieValue, cookieLifetime) {
198
202
  let expires
199
203
 
200
204
  const domain = getDomain()
@@ -211,7 +215,7 @@ const setCookie = (cookieName, cookieValue, cookieLifetime) => {
211
215
  cookieName + '=' + cookieValue + ';expires=' + expires + ';domain=' + domain + ';path=/;'
212
216
  }
213
217
 
214
- const getJSONCookie = cookieName => {
218
+ const getJSONCookie = (cookieName) => {
215
219
  let cookie
216
220
 
217
221
  try {
@@ -221,12 +225,12 @@ const getJSONCookie = cookieName => {
221
225
  return cookie
222
226
  }
223
227
 
224
- const getCookie = cookieName => {
228
+ const getCookie = (cookieName) => {
225
229
  let cookieString = RegExp('' + cookieName + '[^;]+').exec(document.cookie)
226
230
  return unescape(!!cookieString ? cookieString.toString().replace(/^[^=]+./, '') : '')
227
231
  }
228
232
 
229
- const deleteCookie = cookieName => {
233
+ const deleteCookie = (cookieName) => {
230
234
  const domain = getDomain()
231
235
  document.cookie =
232
236
  cookieName + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;domain=' + domain + ';path=/;'
@@ -235,17 +239,18 @@ const deleteCookie = cookieName => {
235
239
  const getDomain = () => {
236
240
  return window.location.hostname.substring(window.location.hostname.indexOf('.') + 1)
237
241
  }
238
- const requestTimeout = (fn, delay) => {
239
- var requestAnimFrame = (function() {
242
+ const requestTimeout = function (fn, delay) {
243
+ var requestAnimFrame = (function () {
240
244
  return (
241
245
  window.requestAnimationFrame ||
242
- function(callback, element) {
246
+ function (callback, element) {
243
247
  window.setTimeout(callback, 1000 / 60)
244
248
  }
245
249
  )
246
250
  })(),
247
251
  start = new Date().getTime(),
248
252
  handle = {}
253
+
249
254
  function loop() {
250
255
  var current = new Date().getTime(),
251
256
  delta = current - start
@@ -255,11 +260,12 @@ const requestTimeout = (fn, delay) => {
255
260
  handle.value = requestAnimFrame(loop)
256
261
  }
257
262
  }
263
+
258
264
  handle.value = requestAnimFrame(loop)
259
265
  return handle
260
266
  }
261
267
 
262
- const replaceAnimated = (
268
+ const replaceAnimated = function (
263
269
  elem,
264
270
  data,
265
271
  rescan,
@@ -269,7 +275,7 @@ const replaceAnimated = (
269
275
  valueTo,
270
276
  easing,
271
277
  duration
272
- ) => {
278
+ ) {
273
279
  const property = 'opacity'
274
280
  timeoutDelay = timeoutDelay || 800
275
281
  valueFrom = valueFrom || 0.2
@@ -283,7 +289,7 @@ const replaceAnimated = (
283
289
 
284
290
  elem.style[property] = valueFrom
285
291
 
286
- requestTimeout(function() {
292
+ requestTimeout(function () {
287
293
  if (data) {
288
294
  elem.innerHTML = data
289
295
  }
@@ -300,33 +306,33 @@ const replaceAnimated = (
300
306
  }, timeoutDelay)
301
307
  }
302
308
 
303
- hr$.loadScript = function(id, scriptUrl, async, callback) {
304
- if (document.getElementById(id)) return
309
+ const getScrollY = () =>
310
+ window.pageYOffset !== undefined
311
+ ? window.pageYOffset
312
+ : (document.documentElement || document.body.parentNode || document.body).scrollTop
305
313
 
306
- var firstScriptTagInPage = hr$('script')[0],
307
- scriptTag = document.createElement('script')
314
+ //Funktion um X & Y Offset eines Elements zu ermitteln
315
+ const getElementOffset = function (el) {
316
+ let _x = 0
317
+ let _y = 0
318
+ _x = Math.round(el.getBoundingClientRect().left)
319
+ _y = Math.round(el.getBoundingClientRect().top)
308
320
 
309
- scriptTag.id = id
310
- scriptTag.src = scriptUrl
321
+ return { top: _y, left: _x }
322
+ }
311
323
 
312
- if (async) {
313
- scriptTag.setAttribute('async', !!async)
314
- }
324
+ const reinitializeFeature = function (element) {
325
+ Initializer.run(element, loadFeature)
326
+ }
315
327
 
316
- if (callback) {
317
- scriptTag.addEventListener(
318
- 'load',
319
- function(e) {
320
- callback(null, e)
321
- },
322
- false
323
- )
328
+ const removeScript = function (id) {
329
+ const element = document.getElementById(id)
330
+ if (element) {
331
+ element.parentNode.removeChild(element)
324
332
  }
325
-
326
- firstScriptTagInPage.parentNode.insertBefore(scriptTag, firstScriptTagInPage)
327
333
  }
328
334
 
329
- const loadScript = (id, scriptUrl, async, callback) => {
335
+ const loadScript = function (id, scriptUrl, async, callback) {
330
336
  if (document.getElementById(id)) return
331
337
 
332
338
  let firstScriptTagInPage = hr$('script')[0],
@@ -342,7 +348,7 @@ const loadScript = (id, scriptUrl, async, callback) => {
342
348
  if (callback) {
343
349
  scriptTag.addEventListener(
344
350
  'load',
345
- function(e) {
351
+ function (e) {
346
352
  callback(null, e)
347
353
  },
348
354
  false
@@ -352,7 +358,94 @@ const loadScript = (id, scriptUrl, async, callback) => {
352
358
  firstScriptTagInPage.parentNode.insertBefore(scriptTag, firstScriptTagInPage)
353
359
  }
354
360
 
361
+ /*
362
+ * Fügt ein "style" bereich zum dokument hinzu
363
+ * und gibt eine referenz darauf zurück
364
+ * auf der man dann mit insertRule arbeiten kann
365
+ */
366
+ const addStyle = function (css, mediaQuery) {
367
+ // Create the <style> tag
368
+ const style = document.createElement('style')
369
+
370
+ if (mediaQuery) {
371
+ style.setAttribute('media', mediaQuery)
372
+ }
373
+
374
+ // Add the <style> element to the page
375
+ if (style.styleSheet) {
376
+ style.styleSheet.cssText = css || ''
377
+ } else {
378
+ style.appendChild(document.createTextNode(css || ''))
379
+ }
380
+
381
+ document.head.appendChild(style)
382
+
383
+ return style.sheet
384
+ }
385
+
386
+ const simulateClickOn = function (elem) {
387
+ elem.dispatchEvent(
388
+ new MouseEvent('click', {
389
+ view: window,
390
+ bubbles: true,
391
+ cancelable: true,
392
+ })
393
+ )
394
+ }
395
+
396
+ /*!
397
+ * Behaves the same as setInterval except uses requestAnimationFrame() where possible for better performance
398
+ * modified gist.github.com/joelambert/1002116
399
+ * the fallback function requestAnimFrame is incorporated
400
+ * gist.github.com/joelambert/1002116
401
+ * gist.github.com/englishextra/873c8f78bfda7cafc905f48a963df07b
402
+ * jsfiddle.net/englishextra/sxrzktkz/
403
+ * @param {Object} fn The callback function
404
+ * @param {Int} delay The delay in milliseconds
405
+ * requestInterval(fn, delay);
406
+ */
407
+ const requestInterval = function (fn, delay) {
408
+ const requestAnimFrame = (function () {
409
+ return (
410
+ window.requestAnimationFrame ||
411
+ function (callback, element) {
412
+ window.setTimeout(callback, 1000 / 60)
413
+ }
414
+ )
415
+ })(),
416
+ handle = {}
417
+ let start = new Date().getTime()
418
+
419
+ function loop() {
420
+ handle.value = requestAnimFrame(loop)
421
+ const current = new Date().getTime(),
422
+ delta = current - start
423
+ if (delta >= delay) {
424
+ fn.call()
425
+ start = new Date().getTime()
426
+ }
427
+ }
428
+
429
+ handle.value = requestAnimFrame(loop)
430
+ return handle
431
+ }
432
+
433
+ /*!
434
+ * Behaves the same as clearInterval except uses cancelRequestAnimationFrame()
435
+ * where possible for better performance
436
+ * gist.github.com/joelambert/1002116
437
+ * gist.github.com/englishextra/873c8f78bfda7cafc905f48a963df07b
438
+ * jsfiddle.net/englishextra/sxrzktkz/
439
+ * @param {Int|Object} handle function handle, or function
440
+ * clearRequestInterval(handle);
441
+ */
442
+ const clearRequestInterval = (handle) =>
443
+ window.cancelAnimationFrame && handle
444
+ ? window.cancelAnimationFrame(handle.value)
445
+ : window.clearInterval(handle)
446
+
355
447
  export {
448
+ addStyle,
356
449
  hr$,
357
450
  stripTags,
358
451
  getViewportWidth,
@@ -373,8 +466,15 @@ export {
373
466
  setJSONCookie,
374
467
  getJSONCookie,
375
468
  getCookie,
469
+ getScrollY,
470
+ getElementOffset,
376
471
  deleteCookie,
472
+ requestInterval,
473
+ clearRequestInterval,
377
474
  requestTimeout,
378
475
  replaceAnimated,
379
- loadScript
476
+ loadScript,
477
+ removeScript,
478
+ reinitializeFeature,
479
+ simulateClickOn,
380
480
  }
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": "0.56.8",
9
+ "version": "0.56.9",
10
10
  "scripts": {
11
11
  "test": "echo \"Error: no test specified\" && exit 1",
12
12
  "storybook": "start-storybook -p 6006 public",
@@ -1,7 +1,7 @@
1
1
  import Initializer from 'initializer'
2
2
  import loadFeature from 'loadFeature'
3
3
 
4
- const hr$ = (selector, element) => {
4
+ const hr$ = function (selector, element) {
5
5
  // if element set, use it
6
6
  // if not use document as default
7
7
  const rootElement = element || document
@@ -34,24 +34,19 @@ const hr$ = (selector, element) => {
34
34
  return rootElement.querySelectorAll(selector)
35
35
  }
36
36
 
37
- const stripTags = text => {
38
- if (text) {
39
- return text.replace(/(<([^>]+)>)/gi, '')
40
- }
41
- return false
42
- }
37
+ const stripTags = (text) => (text ? text.replace(/(<([^>]+)>)/gi, '') : false)
43
38
 
44
39
  const getViewportWidth = () =>
45
40
  Math.max(document.documentElement.clientWidth, window.innerWidth || 0)
46
41
 
47
- const isString = value => Object.prototype.toString.call(value) === '[object String]'
42
+ const isString = (value) => Object.prototype.toString.call(value) === '[object String]'
48
43
 
49
- const isElementInViewport = el => {
44
+ const isElementInViewport = (el) => {
50
45
  const rect = el.getBoundingClientRect()
51
46
  return rect.top <= (document.documentElement || document.body).clientHeight
52
47
  }
53
48
 
54
- const getClosestParentWithTag = (tagName, node) => {
49
+ const getClosestParentWithTag = function (tagName, node) {
55
50
  while (node !== null && node.tagName !== 'BODY') {
56
51
  if (node.tagName && node.tagName.toLowerCase() === tagName) {
57
52
  return node
@@ -61,7 +56,7 @@ const getClosestParentWithTag = (tagName, node) => {
61
56
  return false
62
57
  }
63
58
 
64
- const getNodeWithClassInPath = (className, startNode) => {
59
+ const getNodeWithClassInPath = function (className, startNode) {
65
60
  let node = startNode
66
61
 
67
62
  while (node && node !== document) {
@@ -73,7 +68,7 @@ const getNodeWithClassInPath = (className, startNode) => {
73
68
  return false
74
69
  }
75
70
 
76
- const isDescendant = (parent, child) => {
71
+ const isDescendant = function (parent, child) {
77
72
  let node = child.parentNode
78
73
  while (node !== null) {
79
74
  if (node === parent) {
@@ -85,9 +80,9 @@ const isDescendant = (parent, child) => {
85
80
  }
86
81
 
87
82
  /* wartet x ms seit dem letzen aufruf bis es ausgeführt wird */
88
- const debounce = (fn, delay) => {
83
+ const debounce = function (fn, delay) {
89
84
  let timer = null
90
- return (...args) => {
85
+ return function (...args) {
91
86
  const context = this
92
87
  clearTimeout(timer)
93
88
  timer = setTimeout(() => {
@@ -96,11 +91,11 @@ const debounce = (fn, delay) => {
96
91
  }
97
92
  }
98
93
  /* feuert all x ms */
99
- const throttle = (fn, threshhold, scope) => {
94
+ const throttle = function (fn, threshhold, scope) {
100
95
  threshhold = threshhold || 250
101
96
  let last
102
97
  let deferTimer
103
- return (...args) => {
98
+ return function (...args) {
104
99
  const context = scope || this
105
100
 
106
101
  const now = +new Date()
@@ -128,10 +123,10 @@ const throttle = (fn, threshhold, scope) => {
128
123
  canOnlyFireOnce(); // nada
129
124
  *
130
125
  */
131
- const once = (fn, context) => {
126
+ const once = function (fn, context) {
132
127
  let result
133
128
 
134
- return (...args) => {
129
+ return function (...args) {
135
130
  if (fn) {
136
131
  result = fn.apply(context || this, args)
137
132
  fn = null
@@ -141,16 +136,25 @@ const once = (fn, context) => {
141
136
  }
142
137
  }
143
138
 
144
- const listen = (eventName, fn, documentNode) => {
139
+ const listen = function (eventName, fn, documentNode, forceActive = false) {
145
140
  documentNode = documentNode === undefined ? document : documentNode
146
141
 
142
+ // Use passive listeners to improve scrolling performance
143
+ // See:
144
+ // https://web.dev/uses-passive-event-listeners/
145
+ // https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
146
+
147
+ const isTouchOrMouseEvent =
148
+ eventName === 'touchstart' || eventName === 'touchmove' || eventName === 'wheel'
149
+ const isPassive = Modernizr.passiveeventlisteners && !forceActive && isTouchOrMouseEvent
150
+
147
151
  if (window.attachEvent) {
148
152
  documentNode.attachEvent(eventName, fn)
149
153
  } else {
150
- documentNode.addEventListener(eventName, fn)
154
+ documentNode.addEventListener(eventName, fn, isPassive ? { passive: true } : false)
151
155
  }
152
156
  }
153
- const unlisten = (eventName, fn, documentNode) => {
157
+ const unlisten = function (eventName, fn, documentNode) {
154
158
  documentNode = documentNode === undefined ? document : documentNode
155
159
 
156
160
  if (window.attachEvent) {
@@ -159,7 +163,7 @@ const unlisten = (eventName, fn, documentNode) => {
159
163
  documentNode.removeEventListener(eventName, fn)
160
164
  }
161
165
  }
162
- const listenOnce = (eventName, fn, documentNode) => {
166
+ const listenOnce = function (eventName, fn, documentNode) {
163
167
  documentNode = documentNode === undefined ? document : documentNode
164
168
 
165
169
  documentNode.addEventListener(eventName, fn, { once: true })
@@ -194,7 +198,7 @@ const setJSONCookie = (cookieName, cookieValue, cookieLifetime) => {
194
198
  setCookie(cookieName, JSON.stringify(cookieValue), cookieLifetime)
195
199
  }
196
200
 
197
- const setCookie = (cookieName, cookieValue, cookieLifetime) => {
201
+ const setCookie = function (cookieName, cookieValue, cookieLifetime) {
198
202
  let expires
199
203
 
200
204
  const domain = getDomain()
@@ -211,7 +215,7 @@ const setCookie = (cookieName, cookieValue, cookieLifetime) => {
211
215
  cookieName + '=' + cookieValue + ';expires=' + expires + ';domain=' + domain + ';path=/;'
212
216
  }
213
217
 
214
- const getJSONCookie = cookieName => {
218
+ const getJSONCookie = (cookieName) => {
215
219
  let cookie
216
220
 
217
221
  try {
@@ -221,12 +225,12 @@ const getJSONCookie = cookieName => {
221
225
  return cookie
222
226
  }
223
227
 
224
- const getCookie = cookieName => {
228
+ const getCookie = (cookieName) => {
225
229
  let cookieString = RegExp('' + cookieName + '[^;]+').exec(document.cookie)
226
230
  return unescape(!!cookieString ? cookieString.toString().replace(/^[^=]+./, '') : '')
227
231
  }
228
232
 
229
- const deleteCookie = cookieName => {
233
+ const deleteCookie = (cookieName) => {
230
234
  const domain = getDomain()
231
235
  document.cookie =
232
236
  cookieName + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;domain=' + domain + ';path=/;'
@@ -235,17 +239,18 @@ const deleteCookie = cookieName => {
235
239
  const getDomain = () => {
236
240
  return window.location.hostname.substring(window.location.hostname.indexOf('.') + 1)
237
241
  }
238
- const requestTimeout = (fn, delay) => {
239
- var requestAnimFrame = (function() {
242
+ const requestTimeout = function (fn, delay) {
243
+ var requestAnimFrame = (function () {
240
244
  return (
241
245
  window.requestAnimationFrame ||
242
- function(callback, element) {
246
+ function (callback, element) {
243
247
  window.setTimeout(callback, 1000 / 60)
244
248
  }
245
249
  )
246
250
  })(),
247
251
  start = new Date().getTime(),
248
252
  handle = {}
253
+
249
254
  function loop() {
250
255
  var current = new Date().getTime(),
251
256
  delta = current - start
@@ -255,11 +260,12 @@ const requestTimeout = (fn, delay) => {
255
260
  handle.value = requestAnimFrame(loop)
256
261
  }
257
262
  }
263
+
258
264
  handle.value = requestAnimFrame(loop)
259
265
  return handle
260
266
  }
261
267
 
262
- const replaceAnimated = (
268
+ const replaceAnimated = function (
263
269
  elem,
264
270
  data,
265
271
  rescan,
@@ -269,7 +275,7 @@ const replaceAnimated = (
269
275
  valueTo,
270
276
  easing,
271
277
  duration
272
- ) => {
278
+ ) {
273
279
  const property = 'opacity'
274
280
  timeoutDelay = timeoutDelay || 800
275
281
  valueFrom = valueFrom || 0.2
@@ -283,7 +289,7 @@ const replaceAnimated = (
283
289
 
284
290
  elem.style[property] = valueFrom
285
291
 
286
- requestTimeout(function() {
292
+ requestTimeout(function () {
287
293
  if (data) {
288
294
  elem.innerHTML = data
289
295
  }
@@ -300,33 +306,33 @@ const replaceAnimated = (
300
306
  }, timeoutDelay)
301
307
  }
302
308
 
303
- hr$.loadScript = function(id, scriptUrl, async, callback) {
304
- if (document.getElementById(id)) return
309
+ const getScrollY = () =>
310
+ window.pageYOffset !== undefined
311
+ ? window.pageYOffset
312
+ : (document.documentElement || document.body.parentNode || document.body).scrollTop
305
313
 
306
- var firstScriptTagInPage = hr$('script')[0],
307
- scriptTag = document.createElement('script')
314
+ //Funktion um X & Y Offset eines Elements zu ermitteln
315
+ const getElementOffset = function (el) {
316
+ let _x = 0
317
+ let _y = 0
318
+ _x = Math.round(el.getBoundingClientRect().left)
319
+ _y = Math.round(el.getBoundingClientRect().top)
308
320
 
309
- scriptTag.id = id
310
- scriptTag.src = scriptUrl
321
+ return { top: _y, left: _x }
322
+ }
311
323
 
312
- if (async) {
313
- scriptTag.setAttribute('async', !!async)
314
- }
324
+ const reinitializeFeature = function (element) {
325
+ Initializer.run(element, loadFeature)
326
+ }
315
327
 
316
- if (callback) {
317
- scriptTag.addEventListener(
318
- 'load',
319
- function(e) {
320
- callback(null, e)
321
- },
322
- false
323
- )
328
+ const removeScript = function (id) {
329
+ const element = document.getElementById(id)
330
+ if (element) {
331
+ element.parentNode.removeChild(element)
324
332
  }
325
-
326
- firstScriptTagInPage.parentNode.insertBefore(scriptTag, firstScriptTagInPage)
327
333
  }
328
334
 
329
- const loadScript = (id, scriptUrl, async, callback) => {
335
+ const loadScript = function (id, scriptUrl, async, callback) {
330
336
  if (document.getElementById(id)) return
331
337
 
332
338
  let firstScriptTagInPage = hr$('script')[0],
@@ -342,7 +348,7 @@ const loadScript = (id, scriptUrl, async, callback) => {
342
348
  if (callback) {
343
349
  scriptTag.addEventListener(
344
350
  'load',
345
- function(e) {
351
+ function (e) {
346
352
  callback(null, e)
347
353
  },
348
354
  false
@@ -352,7 +358,94 @@ const loadScript = (id, scriptUrl, async, callback) => {
352
358
  firstScriptTagInPage.parentNode.insertBefore(scriptTag, firstScriptTagInPage)
353
359
  }
354
360
 
361
+ /*
362
+ * Fügt ein "style" bereich zum dokument hinzu
363
+ * und gibt eine referenz darauf zurück
364
+ * auf der man dann mit insertRule arbeiten kann
365
+ */
366
+ const addStyle = function (css, mediaQuery) {
367
+ // Create the <style> tag
368
+ const style = document.createElement('style')
369
+
370
+ if (mediaQuery) {
371
+ style.setAttribute('media', mediaQuery)
372
+ }
373
+
374
+ // Add the <style> element to the page
375
+ if (style.styleSheet) {
376
+ style.styleSheet.cssText = css || ''
377
+ } else {
378
+ style.appendChild(document.createTextNode(css || ''))
379
+ }
380
+
381
+ document.head.appendChild(style)
382
+
383
+ return style.sheet
384
+ }
385
+
386
+ const simulateClickOn = function (elem) {
387
+ elem.dispatchEvent(
388
+ new MouseEvent('click', {
389
+ view: window,
390
+ bubbles: true,
391
+ cancelable: true,
392
+ })
393
+ )
394
+ }
395
+
396
+ /*!
397
+ * Behaves the same as setInterval except uses requestAnimationFrame() where possible for better performance
398
+ * modified gist.github.com/joelambert/1002116
399
+ * the fallback function requestAnimFrame is incorporated
400
+ * gist.github.com/joelambert/1002116
401
+ * gist.github.com/englishextra/873c8f78bfda7cafc905f48a963df07b
402
+ * jsfiddle.net/englishextra/sxrzktkz/
403
+ * @param {Object} fn The callback function
404
+ * @param {Int} delay The delay in milliseconds
405
+ * requestInterval(fn, delay);
406
+ */
407
+ const requestInterval = function (fn, delay) {
408
+ const requestAnimFrame = (function () {
409
+ return (
410
+ window.requestAnimationFrame ||
411
+ function (callback, element) {
412
+ window.setTimeout(callback, 1000 / 60)
413
+ }
414
+ )
415
+ })(),
416
+ handle = {}
417
+ let start = new Date().getTime()
418
+
419
+ function loop() {
420
+ handle.value = requestAnimFrame(loop)
421
+ const current = new Date().getTime(),
422
+ delta = current - start
423
+ if (delta >= delay) {
424
+ fn.call()
425
+ start = new Date().getTime()
426
+ }
427
+ }
428
+
429
+ handle.value = requestAnimFrame(loop)
430
+ return handle
431
+ }
432
+
433
+ /*!
434
+ * Behaves the same as clearInterval except uses cancelRequestAnimationFrame()
435
+ * where possible for better performance
436
+ * gist.github.com/joelambert/1002116
437
+ * gist.github.com/englishextra/873c8f78bfda7cafc905f48a963df07b
438
+ * jsfiddle.net/englishextra/sxrzktkz/
439
+ * @param {Int|Object} handle function handle, or function
440
+ * clearRequestInterval(handle);
441
+ */
442
+ const clearRequestInterval = (handle) =>
443
+ window.cancelAnimationFrame && handle
444
+ ? window.cancelAnimationFrame(handle.value)
445
+ : window.clearInterval(handle)
446
+
355
447
  export {
448
+ addStyle,
356
449
  hr$,
357
450
  stripTags,
358
451
  getViewportWidth,
@@ -373,8 +466,15 @@ export {
373
466
  setJSONCookie,
374
467
  getJSONCookie,
375
468
  getCookie,
469
+ getScrollY,
470
+ getElementOffset,
376
471
  deleteCookie,
472
+ requestInterval,
473
+ clearRequestInterval,
377
474
  requestTimeout,
378
475
  replaceAnimated,
379
- loadScript
476
+ loadScript,
477
+ removeScript,
478
+ reinitializeFeature,
479
+ simulateClickOn,
380
480
  }