@newlogic-digital/ui 3.3.0 → 3.5.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 (151) hide show
  1. package/README.md +10 -14
  2. package/package.json +23 -23
  3. package/src/data/main.json +2 -8
  4. package/src/emails/{templates/Content.twig → templates.test/Content.latte} +10 -2
  5. package/src/emails/{templates/Header.twig → templates.test/Header.latte} +1 -1
  6. package/src/emails/{templates/Layout.twig → templates.test/Layout.latte} +2 -2
  7. package/src/icons.svg +34 -28
  8. package/src/scripts/Components/CookieConsent.js +22 -28
  9. package/src/scripts/Layout/Header.js +25 -11
  10. package/src/scripts/Layout/Main.js +25 -55
  11. package/src/scripts/Libraries/+.js +4 -5
  12. package/src/scripts/Libraries/Dialog.js +37 -72
  13. package/src/scripts/Libraries/Drawer.js +22 -21
  14. package/src/scripts/Libraries/Form.js +8 -13
  15. package/src/scripts/Libraries/Naja.js +33 -0
  16. package/src/scripts/Libraries/ReCaptcha.js +14 -4
  17. package/src/scripts/Libraries/Ripple.js +6 -22
  18. package/src/scripts/Libraries/Script.js +1 -2
  19. package/src/scripts/Libraries/Slider.js +160 -0
  20. package/src/scripts/Libraries/Stimulus.js +0 -1
  21. package/src/scripts/Libraries/Swup.js +54 -38
  22. package/src/scripts/Libraries/Tippy.js +17 -20
  23. package/src/scripts/Ui/+.js +3 -3
  24. package/src/scripts/Ui/Check.js +8 -0
  25. package/src/scripts/Ui/Control.js +186 -0
  26. package/src/scripts/Ui/ControlSelect.js +24 -0
  27. package/src/scripts/Ui/Text.js +8 -10
  28. package/src/scripts/Utils/Functions/+.js +3 -3
  29. package/src/scripts/Utils/Functions/importScript.js +1 -1
  30. package/src/scripts/Utils/Functions/importStyle.js +1 -1
  31. package/src/scripts/Utils/Functions/inputStep.js +9 -0
  32. package/src/scripts/Utils/Functions/inputValidity.js +57 -0
  33. package/src/scripts/Utils/Functions/loadStimulus.js +12 -9
  34. package/src/scripts/Utils/Functions/replaceScript.js +4 -0
  35. package/src/scripts/Utils/Functions/replaceTag.js +1 -5
  36. package/src/scripts/Utils/cdn.js +2 -3
  37. package/src/scripts/Utils/global.js +1 -1
  38. package/src/styles/Components/+.css +1 -1
  39. package/src/styles/Components/CookieConsent.css +22 -25
  40. package/src/styles/Components/Dialog/Default.css +10 -62
  41. package/src/styles/Components/Dropdown/Default.css +6 -3
  42. package/src/styles/Components/Field.css +1 -0
  43. package/src/styles/Layout/Header.css +13 -17
  44. package/src/styles/Layout/Main.css +8 -91
  45. package/src/styles/Layout/Nav.css +31 -27
  46. package/src/styles/Libraries/+.css +1 -2
  47. package/src/styles/Libraries/Datepicker.css +38 -229
  48. package/src/styles/Libraries/Dialog.css +1 -19
  49. package/src/styles/Libraries/Drawer.css +17 -29
  50. package/src/styles/Libraries/Hint.css +86 -101
  51. package/src/styles/Libraries/Pickr.css +13 -0
  52. package/src/styles/Libraries/Ripple.css +1 -29
  53. package/src/styles/Libraries/Tippy.css +25 -39
  54. package/src/styles/Ui/+.css +6 -5
  55. package/src/styles/Ui/Badge.css +7 -82
  56. package/src/styles/Ui/Btn.css +13 -226
  57. package/src/styles/Ui/Check.css +1 -0
  58. package/src/styles/Ui/Control.css +47 -0
  59. package/src/styles/Ui/ControlSelect.css +66 -0
  60. package/src/styles/Ui/Dot.css +22 -0
  61. package/src/styles/Ui/Group.css +1 -0
  62. package/src/styles/Ui/Heading.css +3 -22
  63. package/src/styles/Ui/Image.css +1 -17
  64. package/src/styles/Ui/Info.css +1 -0
  65. package/src/styles/Ui/Label.css +1 -14
  66. package/src/styles/Ui/Link.css +2 -41
  67. package/src/styles/Ui/Notice.css +1 -47
  68. package/src/styles/Ui/Progress.css +1 -56
  69. package/src/styles/Ui/Switch.css +1 -70
  70. package/src/styles/Ui/Text.css +4 -245
  71. package/src/styles/Ui/Title.css +5 -13
  72. package/src/styles/Utils/+.css +3 -4
  73. package/src/styles/Utils/breakpoints.css +1 -0
  74. package/src/styles/Utils/config.css +5 -0
  75. package/src/styles/Utils/default.css +8 -122
  76. package/src/styles/Utils/icons.css +3 -7
  77. package/src/styles/Utils/keyframes.css +1 -182
  78. package/src/styles/Utils/{tailwind/base.css → tailwind.css} +31 -21
  79. package/src/styles/Utils/theme/+.css +1 -1
  80. package/src/styles/Utils/theme/main.css +14 -23
  81. package/src/styles/main.css +19 -15
  82. package/src/styles/tinymce.css +34 -0
  83. package/src/templates/Components/CookieConsent.latte +28 -0
  84. package/src/templates/Components/Dialogs/Basic.latte +22 -0
  85. package/src/templates/Layout/{Header.twig → Header.latte} +15 -17
  86. package/src/templates/Layout/Main.latte +62 -0
  87. package/src/templates/Sections/Gdpr.latte +127 -0
  88. package/src/templates/Sections/Site.latte +141 -0
  89. package/src/templates/Sections/Ui/Docs/@intro.html +13 -62
  90. package/src/templates/Sections/Ui/Docs/@nav.html +41 -92
  91. package/src/templates/Sections/Ui/Docs/@styles.html +2 -6
  92. package/src/templates/Sections/Ui/Docs/Default.latte +1059 -0
  93. package/src/templates/Sections/Ui/Icons.html +11 -9
  94. package/src/templates/Sections/Ui/Intro.html +66 -37
  95. package/src/templates/Sections/Ui.latte +8 -0
  96. package/src/templates/Ui/+.latte +5 -0
  97. package/src/templates/Ui/Check.latte +7 -0
  98. package/src/templates/Ui/Control.latte +9 -0
  99. package/src/templates/Ui/ControlDate.latte +14 -0
  100. package/src/templates/Ui/ControlSelect.latte +9 -0
  101. package/src/templates/Ui/ControlTime.latte +14 -0
  102. package/src/templates/Utils/sections.latte +3 -0
  103. package/src/views/dialog/basic.json.latte +5 -0
  104. package/src/views/dropdown/{tippy.json.twig → tippy.json.latte} +7 -4
  105. package/src/views/email/email.latte +6 -0
  106. package/src/views/email/email.test.latte +6 -0
  107. package/src/views/gdpr.json +1 -1
  108. package/src/views/index.json +1 -1
  109. package/src/views/site.json +11 -0
  110. package/src/views/ui-icons.json +1 -1
  111. package/src/views/ui.json +1 -1
  112. package/vite.config.js +16 -6
  113. package/.eslintrc +0 -13
  114. package/.stylelintrc +0 -18
  115. package/public/sw.js +0 -30
  116. package/src/emails/email.prod.html +0 -6
  117. package/src/emails/email.twig.html +0 -6
  118. package/src/scripts/Libraries/Anchor.js +0 -35
  119. package/src/scripts/Libraries/NativeSlider.js +0 -138
  120. package/src/scripts/Libraries/Tabs.js +0 -16
  121. package/src/scripts/Ui/Checkbox.js +0 -10
  122. package/src/scripts/Ui/Input.js +0 -259
  123. package/src/scripts/Ui/Select.js +0 -53
  124. package/src/scripts/Utils/Functions/checkValidity.js +0 -44
  125. package/src/scripts/Utils/Functions/dataValue.js +0 -52
  126. package/src/scripts/Utils/Functions/inView.js +0 -24
  127. package/src/styles/Components/Form/+.css +0 -1
  128. package/src/styles/Components/Form/CookieConsent.css +0 -31
  129. package/src/styles/Libraries/NativeSlider.css +0 -60
  130. package/src/styles/Libraries/Tabs.css +0 -19
  131. package/src/styles/Ui/Checkbox.css +0 -151
  132. package/src/styles/Ui/Icon.css +0 -33
  133. package/src/styles/Ui/Input.css +0 -467
  134. package/src/styles/Ui/Radio.css +0 -4
  135. package/src/styles/Ui/Select.css +0 -137
  136. package/src/styles/Utils/normalize.css +0 -223
  137. package/src/styles/Utils/tailwind/+.css +0 -2
  138. package/src/styles/Utils/tailwind/gutters.css +0 -346
  139. package/src/styles/Utils/vars.css +0 -126
  140. package/src/styles/Utils/vendor.css +0 -1
  141. package/src/templates/Components/CookieConsent.twig +0 -30
  142. package/src/templates/Components/Dialogs/Basic.twig +0 -24
  143. package/src/templates/Layout/Main.twig +0 -49
  144. package/src/templates/Sections/Gdpr.twig +0 -64
  145. package/src/templates/Sections/Ui/Docs/Default.twig +0 -1600
  146. package/src/templates/Sections/Ui.twig +0 -8
  147. package/src/templates/Utils/sections.twig +0 -3
  148. package/src/views/dialog/basic.json.twig +0 -3
  149. package/tailwind.config.cjs +0 -69
  150. /package/src/emails/{templates.prod → templates}/.gitkeep +0 -0
  151. /package/src/templates/Layout/{Footer.twig → Footer.latte} +0 -0
@@ -1,82 +1,47 @@
1
- import { loadStimulus } from './Stimulus.js'
2
-
3
- const LibDialog = {
4
- show: async(content) => {
5
- return new Promise(resolve => {
6
- if (document.querySelector('.lib-dialog > [class^="c-dialog"]') !== null) {
7
- document.querySelector('.lib-dialog > [class^="c-dialog"]').remove()
8
- }
9
-
10
- if (document.querySelector('.lib-dialog') === null) {
11
- document.body.insertAdjacentHTML('beforeend', '<div class="lib-dialog" tabindex="0"></div>')
12
- }
13
-
14
- document.querySelector('.lib-dialog').insertAdjacentHTML('beforeend', content)
15
- document.querySelector('.lib-dialog').style.display = 'flex'
16
-
17
- function outerHeight(el) {
18
- return el.offsetHeight + parseInt(getComputedStyle(el).marginTop) + parseInt(getComputedStyle(el).marginBottom)
19
- }
20
-
21
- if (outerHeight(document.querySelector('.lib-dialog > [class^="c-dialog"]')) > window.innerHeight) {
22
- const offset = window.innerWidth - document.body.clientWidth
23
-
24
- document.documentElement.style.paddingRight = `${offset}px`
25
- document.documentElement.classList.add('overflow-hidden')
1
+ import { Controller, LibStimulus, loadStimulus } from './Stimulus.js'
2
+ import { insertDialog, closeDialog, fetchDialog, dialogSelector } from 'winduum/src/libraries/dialog.js'
3
+ import { replaceScript } from '../Utils/Functions/+.js'
4
+
5
+ LibStimulus.register('lib-dialog', class extends Controller {
6
+ static values = {
7
+ open: String,
8
+ url: String
9
+ }
26
10
 
27
- if (document.querySelector('#l-header') !== null) {
28
- document.querySelector('#l-header').style.right = `${offset}px`
29
- }
11
+ async connect () {
12
+ if (this.hasOpenValue) {
13
+ if (this.hasUrlValue) {
14
+ await fetchDialog({
15
+ url: this.urlValue, insertOptions: { remove: true }
16
+ })
17
+ } else {
18
+ await insertDialog(document.querySelector(this.openValue).innerHTML, {
19
+ remove: true
20
+ })
30
21
  }
31
22
 
32
- loadStimulus(document.querySelector('.lib-dialog'))
33
-
34
- document.querySelector('.lib-dialog').focus()
23
+ loadStimulus(dialogSelector('.lib-dialog'))
24
+ }
25
+ }
35
26
 
36
- resolve()
27
+ async show ({ currentTarget, params }) {
28
+ currentTarget.classList.add('loading', 'cursor-wait')
37
29
 
38
- document.querySelector('.lib-dialog').addEventListener('mousedown', e => {
39
- if (e.target.classList.contains('lib-dialog')) {
40
- document.documentElement.addEventListener('mouseup', function e() {
41
- LibDialog.hide()
42
- document.documentElement.removeEventListener('mouseup', e)
43
- })
44
- }
45
- }, true)
46
- })
47
- },
48
- hide: async() => {
49
- return new Promise(resolve => {
50
- if (document.querySelector('.lib-dialog') !== null) {
51
- document.querySelector('.lib-dialog')._addDataValue('state', 'hiding')
30
+ await fetchDialog({
31
+ url: params.url,
32
+ insertOptions: {
33
+ remove: params.remove ?? true,
34
+ append: params.append ?? false
52
35
  }
53
-
54
- setTimeout(() => {
55
- if (document.querySelector('.lib-dialog') !== null) {
56
- document.querySelector('.lib-dialog').style.display = 'none'
57
- document.documentElement.classList.remove('overflow-hidden')
58
-
59
- if (document.querySelector('#l-header') !== null) {
60
- document.querySelector('#l-header').style.right = ''
61
- }
62
-
63
- document.querySelector('.lib-dialog').remove()
64
- }
65
-
66
- resolve()
67
- }, 300)
36
+ }).then(() => {
37
+ loadStimulus(dialogSelector('.lib-dialog'))
38
+ replaceScript(dialogSelector('.lib-dialog'))
68
39
  })
69
- },
70
- action: async(element, url) => {
71
- element._addDataValue('state', 'loading')
72
- element.classList.add('cursor-wait')
73
40
 
74
- fetch(url, { headers: { 'X-Requested-With': 'XMLHttpRequest' } }).then(response => response.json()).then(({ dialog }) => {
75
- LibDialog.show(dialog)
76
- element._removeDataValue('state', 'loading')
77
- element.classList.remove('cursor-wait')
78
- })
41
+ currentTarget.classList.remove('loading', 'cursor-wait')
79
42
  }
80
- }
81
43
 
82
- export default LibDialog
44
+ async close ({ currentTarget, params }) {
45
+ await closeDialog(currentTarget.closest('dialog'), { remove: params.remove ?? false })
46
+ }
47
+ })
@@ -1,40 +1,41 @@
1
1
  import { LibStimulus, Controller } from './Stimulus.js'
2
2
 
3
- LibStimulus.register('lib-drawer', class extends Controller {
4
- static targets = ['nav']
5
-
6
- init() {
7
- setTimeout(() => this.navTarget.classList.add('is-transition'), 50)
8
- this.navTarget.addEventListener('click', ({ target }) => {
9
- if (target === this.navTarget) {
3
+ LibStimulus.register('lib-drawer', class LibDrawer extends Controller {
4
+ connect () {
5
+ setTimeout(() => this.element.classList.add('is-transition'), 50)
6
+ this.element.addEventListener('click', ({ target }) => {
7
+ if (target === this.element) {
10
8
  this.hide()
11
9
  }
12
10
  })
13
11
  }
14
12
 
15
- show() {
16
- this.navTarget.scrollLeft = 0
17
- this.navTarget.style.setProperty('--lib-drawer-opacity', '1')
18
- this.navTarget.classList.add('is-opacity')
19
- this.navTarget._addDataValue('state', 'active')
13
+ show () {
14
+ this.element.scrollLeft = 0
15
+ this.element.style.setProperty('--lib-drawer-opacity', '1')
16
+ this.element.classList.add('is-opacity', 'active')
17
+ this.element.setAttribute('aria-hidden', 'false')
18
+ this.element.removeAttribute('inert')
20
19
  document.documentElement.classList.add('overflow-hidden')
21
20
  }
22
21
 
23
- hide() {
24
- this.navTarget._removeDataValue('state', 'active')
25
- this.navTarget.classList.add('is-opacity')
26
- this.navTarget.style.setProperty('--lib-drawer-opacity', '0')
22
+ hide () {
23
+ this.element.setAttribute('inert', '')
24
+ this.element.setAttribute('aria-hidden', 'true')
25
+ this.element.classList.remove('active')
26
+ this.element.classList.add('is-opacity')
27
+ this.element.style.setProperty('--lib-drawer-opacity', '0')
27
28
  document.documentElement.classList.remove('overflow-hidden')
28
29
  }
29
30
 
30
- scroll({ target }) {
31
+ scroll ({ target }) {
31
32
  if (target.scrollLeft > 1) {
32
- this.navTarget.classList.remove('is-opacity')
33
- this.navTarget.style.setProperty('--lib-drawer-opacity', `${Math.abs((target.scrollLeft / this.navTarget.children[0].clientWidth) - 1)}`)
33
+ this.element.classList.remove('is-opacity')
34
+ this.element.style.setProperty('--lib-drawer-opacity', `${Math.abs((target.scrollLeft / this.element.children[0].clientWidth) - 1)}`)
34
35
  }
35
36
 
36
- if (target.scrollLeft === this.navTarget.children[0].clientWidth) {
37
- this.navTarget._removeDataValue('state', 'active')
37
+ if (target.scrollLeft === this.element.children[0].clientWidth) {
38
+ this.element.classList.remove('active')
38
39
  document.documentElement.classList.remove('overflow-hidden')
39
40
  }
40
41
  }
@@ -1,31 +1,26 @@
1
1
  import { LibStimulus, Controller } from './Stimulus.js'
2
- import { checkValidity } from '../Utils/Functions/+.js'
2
+ import { inputValidity } from '../Utils/Functions/+.js'
3
3
 
4
4
  LibStimulus.register('lib-form', class extends Controller {
5
- connect() {
5
+ connect () {
6
6
  this.element.setAttribute('novalidate', '')
7
7
  this.element.addEventListener('submit', e => this.validation(e))
8
8
  }
9
9
 
10
- validation(e) {
10
+ validation (e) {
11
11
  if (this.element.checkValidity() === false) {
12
12
  e.preventDefault()
13
13
  e.stopPropagation()
14
14
 
15
15
  this.element.querySelector(':invalid').scrollIntoView({ behavior: 'smooth', block: 'center' })
16
16
  this.element.querySelector(':invalid').focus()
17
+ } else {
18
+ this.element.querySelector('[type="submit"]').classList.add('loading')
17
19
  }
18
20
 
19
- this.element.querySelectorAll('.ui-input, [data-controller="ui-checkbox"], [data-controller="ui-radio"]').forEach(element => {
20
- checkValidity(element, { message: true })
21
+ this.element.querySelectorAll('.ui-control, .ui-check, .ui-switch').forEach(element => {
22
+ console.log(element)
23
+ inputValidity(element, { message: true })
21
24
  })
22
-
23
- this.element.querySelectorAll('.ui-select:not([data-state*="active"]) select[required]').forEach(select => {
24
- checkValidity(select.closest('.ui-select'), { message: true })
25
- })
26
- }
27
-
28
- submitForm({ currentTarget }) {
29
- currentTarget.form.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }))
30
25
  }
31
26
  })
@@ -0,0 +1,33 @@
1
+ import naja from 'naja'
2
+ import { Controller, LibStimulus, loadStimulus } from './Stimulus.js'
3
+
4
+ LibStimulus.register('lib-naja', class extends Controller {
5
+ async connect () {
6
+ naja.uiHandler.addEventListener('interaction', ({ detail }) => {
7
+ const element = detail.element
8
+
9
+ detail.options.target = element
10
+
11
+ element.dispatchEvent(new CustomEvent('naja:interaction', { bubbles: true, cancelable: true }))
12
+
13
+ if (element?.form && !element.form.reportValidity()) {
14
+ arguments[0].preventDefault()
15
+ }
16
+ })
17
+
18
+ naja.snippetHandler.addEventListener('afterUpdate', ({ detail }) => {
19
+ detail?.options.target.dispatchEvent(new CustomEvent('naja:afterUpdate', { bubbles: true, cancelable: true }))
20
+
21
+ loadStimulus(document.body, false)
22
+ })
23
+
24
+ naja.uiHandler.selector = '[data-naja]'
25
+ naja.initialize({
26
+ history: false
27
+ })
28
+ }
29
+
30
+ async get ({ params }) {
31
+ await naja.makeRequest('GET', params.url, params.data ? JSON.parse(params.data) : null, { history: params.history ?? false })
32
+ }
33
+ })
@@ -1,4 +1,5 @@
1
1
  import { LibStimulus, Controller } from './Stimulus.js'
2
+ import naja from 'naja'
2
3
  import importScript from '../Utils/Functions/importScript.js'
3
4
  import cdn from '../Utils/cdn.js'
4
5
 
@@ -8,11 +9,11 @@ LibStimulus.register('lib-recaptcha', class extends Controller {
8
9
  action: String
9
10
  }
10
11
 
11
- connect() {
12
+ connect () {
12
13
  importScript(cdn.recaptcha.replace('{apikey}', this.apiValue))
13
14
  }
14
15
 
15
- async execute() {
16
+ async execute () {
16
17
  return new Promise(resolve => {
17
18
  window.grecaptcha.enterprise.ready(() => {
18
19
  window.grecaptcha.enterprise.execute(this.apiValue, { action: this.actionValue ?? 'form' }).then(token => {
@@ -23,10 +24,19 @@ LibStimulus.register('lib-recaptcha', class extends Controller {
23
24
  })
24
25
  }
25
26
 
26
- async submit() {
27
+ async submit ({ params }) {
28
+ if (this.element.reportValidity() === false) {
29
+ return false
30
+ }
31
+
27
32
  arguments[0].preventDefault()
28
33
 
29
34
  await this.execute()
30
- this.element.submit()
35
+
36
+ if (!params.naja) {
37
+ this.element.submit()
38
+ } else {
39
+ await naja.makeRequest(this.element.method, this.element.action, new FormData(this.element), { history: 'replace' })
40
+ }
31
41
  }
32
42
  })
@@ -1,24 +1,8 @@
1
- const LibRipple = ({ currentTarget, layerX, layerY }) => {
2
- const container = currentTarget
1
+ import { Controller, LibStimulus } from './Stimulus.js'
2
+ import { showRipple } from 'winduum/src/libraries/ripple.js'
3
3
 
4
- if (container.querySelector('.lib-ripple') === null) {
5
- container.insertAdjacentHTML('beforeend', "<div class='lib-ripple'></div>")
4
+ LibStimulus.register('lib-ripple', class extends Controller {
5
+ async show (e) {
6
+ showRipple(e)
6
7
  }
7
-
8
- const ink = container.querySelector('.lib-ripple')
9
-
10
- ink.classList.remove('animation')
11
-
12
- if (ink.clientWidth === 0 && ink.clientHeight === 0) {
13
- const d = Math.max(container.offsetWidth, container.offsetHeight)
14
-
15
- ink.style.width = d + 'px'
16
- ink.style.height = d + 'px'
17
- }
18
-
19
- ink.style.top = layerY - (ink.clientHeight / 2) + 'px'
20
- ink.style.left = layerX - (ink.clientWidth / 2) + 'px'
21
- ink.classList.add('animation')
22
- }
23
-
24
- export default LibRipple
8
+ })
@@ -1,7 +1,7 @@
1
1
  import { LibStimulus, Controller } from './Stimulus.js'
2
2
 
3
3
  LibStimulus.register('lib-script', class extends Controller {
4
- connect() {
4
+ connect () {
5
5
  const element = this.element
6
6
  const script = document.createElement('script')
7
7
 
@@ -12,7 +12,6 @@ LibStimulus.register('lib-script', class extends Controller {
12
12
  })
13
13
 
14
14
  script.innerHTML = element.innerHTML
15
-
16
15
  element.parentElement.appendChild(script)
17
16
  element.remove()
18
17
  }
@@ -0,0 +1,160 @@
1
+ const defaultOptions = {
2
+ behavior: 'smooth',
3
+ init: {
4
+ pauseSelector: [],
5
+ paginationSelector: null,
6
+ paginationItemClass: null,
7
+ progressSelector: null,
8
+ counterMinSelector: null,
9
+ counterMaxSelector: null,
10
+ autoplay: false
11
+ }
12
+ }
13
+
14
+ export const prevSlide = (selector) => {
15
+ selector.scroll({ left: selector.scrollLeft - selector.children[0].clientWidth, behavior: defaultOptions.behavior })
16
+ }
17
+
18
+ export const nextSlide = (selector) => {
19
+ selector.scroll({ left: selector.scrollLeft + selector.children[0].clientWidth, behavior: defaultOptions.behavior })
20
+ }
21
+
22
+ export const selectSlide = (selector, selected = 0) => {
23
+ const position = selector.scrollLeft / selector.children[0].clientWidth
24
+
25
+ if (position - selected <= 0) {
26
+ selector.scroll({ left: selector.scrollLeft + selector.children[0].clientWidth * (selected - 1 - position), behavior: defaultOptions.behavior })
27
+ } else {
28
+ selector.scroll({ left: selector.scrollLeft - selector.children[0].clientWidth * (position - selected + 1), behavior: defaultOptions.behavior })
29
+ }
30
+ }
31
+
32
+ export const initSlider = (selector, options = defaultOptions.init) => {
33
+ let isDown; let paused; let startX; let scrollLeft = null
34
+
35
+ function isElementInViewport (element) {
36
+ const rect = element.getBoundingClientRect()
37
+ const sliderRect = selector.getBoundingClientRect()
38
+
39
+ return (
40
+ rect.left >= sliderRect.left &&
41
+ rect.right <= sliderRect.right
42
+ )
43
+ }
44
+
45
+ function setProgressValue () {
46
+ if (options.progressSelector) {
47
+ options.progressSelector.value = ((selector.scrollLeft + selector.clientWidth) / selector.scrollWidth * 100).toFixed(2)
48
+ }
49
+ }
50
+
51
+ if (!selector.classList.contains('is-fade')) {
52
+ const grabbing = () => {
53
+ isDown = false
54
+ paused = false
55
+ selector.classList.remove('is-grabbing')
56
+ selector.scrollLeft = selector.scrollLeft - 1
57
+ }
58
+
59
+ selector.addEventListener('mouseleave', grabbing)
60
+
61
+ selector.addEventListener('mouseup', grabbing)
62
+
63
+ selector.addEventListener('mousedown', ({ pageX }) => {
64
+ isDown = true
65
+ paused = true
66
+ startX = pageX - selector.offsetLeft
67
+ scrollLeft = selector.scrollLeft
68
+ })
69
+
70
+ selector.addEventListener('mousemove', e => {
71
+ if (!isDown) return
72
+ e.preventDefault()
73
+ const x = e.pageX - selector.offsetLeft
74
+ const walk = (x - startX) * 1.25
75
+
76
+ selector.classList.add('is-grabbing')
77
+ selector.scrollLeft = scrollLeft - walk
78
+
79
+ selector.ondragstart = dragEvent => dragEvent.preventDefault()
80
+ })
81
+ }
82
+
83
+ const itemsCount = selector.clientWidth > selector.children[0].clientWidth
84
+ ? [...selector.children].reduce((item, children) =>
85
+ (selector.scrollWidth - selector.clientWidth > item.itemsWidth + children.clientWidth / 2)
86
+ ? { itemsWidth: item.itemsWidth + children.clientWidth, count: item.count + 1 }
87
+ : item, { itemsWidth: 0, count: 0 }).count + 1
88
+ : Math.ceil((selector.scrollWidth) / selector.children[0].clientWidth)
89
+
90
+ if (options.counterMinSelector) {
91
+ options.counterMinSelector.textContent = 1
92
+ }
93
+
94
+ if (options.counterMaxSelector) {
95
+ options.counterMaxSelector.textContent = itemsCount
96
+ }
97
+
98
+ if (options.paginationSelector) {
99
+ options.paginationSelector.insertAdjacentHTML('beforeend', [...Array(itemsCount)].map((_, i) => `
100
+ <div class="${options.paginationItemClass ?? ''}${i === 0 ? ' active' : ''}"></div>
101
+ `).join(''))
102
+
103
+ ;[...options.paginationSelector.children].forEach((children) => {
104
+ children.addEventListener('click', ({ currentTarget }) => {
105
+ selectSlide(selector, [...options.paginationSelector.children].indexOf(currentTarget) + 1)
106
+ })
107
+ })
108
+ }
109
+
110
+ setProgressValue()
111
+
112
+ selector.addEventListener('scroll', () => {
113
+ const activeSlide = parseInt((selector.scrollLeft / selector.children[0].clientWidth).toFixed(0))
114
+
115
+ for (const children of [...selector.children]) {
116
+ if (isElementInViewport(children)) {
117
+ children.classList.add('active')
118
+ } else {
119
+ children.classList.remove('active')
120
+ }
121
+ }
122
+
123
+ if (options.paginationSelector) {
124
+ [...options.paginationSelector.children].forEach(children => children.classList.remove('active'))
125
+
126
+ options.paginationSelector.children[activeSlide].classList.add('active')
127
+ }
128
+
129
+ setProgressValue()
130
+
131
+ if (options.counterMinSelector) {
132
+ options.counterMinSelector.textContent = activeSlide + 1
133
+ }
134
+ }, { passive: true })
135
+
136
+ if (options.progressSelector) {
137
+ options.progressSelector.addEventListener('click', ({ clientX, target }) => {
138
+ selector.scrollLeft = (selector.scrollWidth / 100) * (clientX - target.offsetLeft) / target.clientWidth * 100
139
+ })
140
+ }
141
+
142
+ ;[...options.pauseSelector, options.progressSelector, options.paginationSelector, selector].forEach(element => {
143
+ if (typeof element !== 'undefined' && element !== null) {
144
+ element.addEventListener('mouseenter', () => (paused = true))
145
+ element.addEventListener('mouseleave', () => (paused = false))
146
+ }
147
+ })
148
+
149
+ if (options.autoplay && !isNaN(options.autoplay)) {
150
+ setInterval(() => {
151
+ if (!paused) {
152
+ if (selector.scrollLeft < selector.children[0].clientWidth * (selector.children.length - 1)) {
153
+ selector.scroll({ left: selector.scrollLeft + selector.children[0].clientWidth, behavior: self.behavior })
154
+ } else {
155
+ selector.scroll({ left: 0, behavior: options.behavior })
156
+ }
157
+ }
158
+ }, options.autoplay)
159
+ }
160
+ }
@@ -2,7 +2,6 @@ import { Application, Controller } from '@hotwired/stimulus'
2
2
  import loadStimulus from '../Utils/Functions/loadStimulus.js'
3
3
 
4
4
  const LibStimulus = new Application(document.documentElement)
5
-
6
5
  const getController = (element, identifier) => LibStimulus.getControllerForElementAndIdentifier(element, identifier)
7
6
 
8
7
  LibStimulus.start().then(() => loadStimulus(document.body))
@@ -1,28 +1,50 @@
1
1
  import Swup from 'swup'
2
+ import { closeDialog } from 'winduum/src/libraries/dialog.js'
3
+ import { hideTippy } from './Tippy.js'
2
4
  import { getController, loadStimulus } from './Stimulus.js'
3
- import LibAnchor from './Anchor.js'
4
- import LibDialog from './Dialog.js'
5
5
  import LibCookieConsent from './CookieConsent.js'
6
- import replaceTag from '../Utils/Functions/replaceTag.js'
6
+ import { replaceTag, replaceScript } from '../Utils/Functions/+.js'
7
+
8
+ document.addEventListener('click', ({ target }) => {
9
+ const noSwup = target.closest('[data-no-swup]')
10
+
11
+ if (!noSwup) {
12
+ return
13
+ }
14
+
15
+ if (noSwup.classList.contains('ui-btn')) {
16
+ noSwup.classList.add('loading')
17
+ } else {
18
+ noSwup.classList.add('cursor-wait')
19
+ }
20
+ })
7
21
 
8
22
  const LibSwup = new Swup({
9
23
  containers: ['#l-main', '#l-header'].filter(element => document.querySelector(element)),
10
24
  linkSelector: `:is(a[href^="${window.location.origin}"], a[href^="/"]):not([data-no-swup], [data-naja], [target="_blank"])`
11
25
  })
12
26
 
13
- LibSwup.on('clickLink', async({ target }) => {
27
+ LibSwup.on('clickLink', async ({ target }) => {
14
28
  document.body.classList.remove('overflow-hidden')
15
29
 
16
- if (document.querySelector('.lib-drawer[data-state~="active"]') !== null) {
17
- getController(document.body, 'lib-drawer').hide()
30
+ const LibDrawerSelector = document.querySelector('.lib-drawer.active')
31
+ const LibDialogSelector = document.querySelector('.lib-dialog')
32
+
33
+ hideTippy()
34
+
35
+ if (LibDrawerSelector) {
36
+ /** @type {LibDrawer} */
37
+ const LibDrawer = getController(LibDrawerSelector, 'lib-drawer')
38
+
39
+ LibDrawer.hide()
18
40
  }
19
41
 
20
- if (document.querySelector('.lib-dialog') !== null) {
21
- await LibDialog.hide()
42
+ if (LibDialogSelector) {
43
+ await closeDialog(LibDialogSelector)
22
44
  }
23
45
 
24
46
  if (window.location.href === target.closest('a').href) {
25
- document.documentElement.scroll({ top: 0 })
47
+ document.documentElement.scroll({ top: 0, behavior: 'smooth' })
26
48
  }
27
49
  })
28
50
 
@@ -30,47 +52,41 @@ LibSwup.on('animationOutDone', () => {
30
52
  document.documentElement.scroll({ top: 0, behavior: 'instant' })
31
53
  })
32
54
 
55
+ /** @var {Array} dataLayer */
56
+ /** @var {Function} rc */
57
+ /** @var {Function} retargetingHit */
58
+ /** @var {Function} conversionHit */
59
+ /** @var {Object} retargetingConf */
60
+ /** @var {Object} conversionConf */
61
+ /** @var {Function} fbq */
33
62
  LibSwup.on('contentReplaced', () => {
34
63
  const content = new DOMParser().parseFromString(LibSwup.cache.getCurrentPage().originalContent, 'text/html')
35
64
 
36
65
  replaceTag(content)
37
66
 
38
- LibAnchor.init()
67
+ if (window.location.hash) {
68
+ document.documentElement.scroll({ top: document.querySelector(`${window.location.hash}`)?.offsetTop, behavior: 'smooth' })
69
+ }
70
+
71
+ LibCookieConsent.init()
39
72
 
40
73
  LibSwup.options.containers.forEach(selector => {
41
74
  loadStimulus(document.querySelector(selector))
75
+ replaceScript(document.querySelector(selector))
42
76
  })
43
77
 
44
- if (typeof window.fbq !== 'undefined') {
45
- window.fbq('track', 'PageView')
46
- }
47
-
48
- if (typeof gtag !== 'undefined') {
49
- const configs = []
50
- window.dataLayer.forEach(function(config) {
51
- if (config[0] === 'config') {
52
- if (typeof config[1] !== 'undefined' && !configs.includes(config[1])) {
53
- configs.push(config[1])
54
- window.gtag('config', config[1], {
55
- page_title: document.title,
56
- page_path: window.location.pathname + window.location.search
57
- })
58
- }
59
- }
60
- })
61
- }
78
+ window.dataLayer && window.dataLayer.push({
79
+ event: 'page_view'
80
+ })
62
81
 
63
- if (typeof window.dataLayer !== 'undefined') {
64
- window.dataLayer.push({
65
- event: 'VirtualPageview',
66
- virtualPageURL: window.location.pathname + window.location.search,
67
- virtualPageTitle: document.title
68
- })
69
- }
82
+ window.rc?.retargetingHit && window.rc.retargetingHit(window.retargetingConf)
83
+ window.rc?.conversionHit && window.rc.conversionHit(window.conversionConf)
70
84
 
71
- if (typeof LibCookieConsent !== 'undefined') {
72
- LibCookieConsent.init()
73
- }
85
+ window.fbq && window.fbq('track', 'PageView')
74
86
  })
75
87
 
88
+ LibSwup.options.cache && setInterval(() => {
89
+ LibSwup.cache.empty()
90
+ }, 90 * 1000)
91
+
76
92
  export default LibSwup