@pushword/js-helper 0.0.104 → 0.0.106

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushword/js-helper",
3
- "version": "0.0.104",
3
+ "version": "0.0.106",
4
4
  "description": "Pushword front end helpers. ",
5
5
  "author": "Robin@PiedWeb <contact@piedweb.com>",
6
6
  "license": "MIT",
@@ -26,20 +26,32 @@ class ScrollYEnhancer {
26
26
 
27
27
  wheelScroll(element) {
28
28
  element.addEventListener('wheel', (evt) => {
29
+ if (window.isScrolling === true) return
29
30
  evt.preventDefault()
30
- //element.classList.toggle('scroll-smooth')
31
+ window.isScrolling = true
32
+
31
33
  const before = element.scrollTop
32
34
  element.scrollTop += evt.deltaY
33
- const after = element.scrollTop
34
- if (before === after) {
35
- window.scrollXWithoutDoingNothing++
36
- if (window.scrollXWithoutDoingNothing > 10) window.scrollBy(0, evt.deltaY / 2)
37
- } else {
38
- window.scrollXWithoutDoingNothing = 0
39
- }
40
- //element.classList.toggle('scroll-smooth')
35
+
36
+ if (before === element.scrollTop) {
37
+ if (
38
+ (parent = element.closest('.enhance-scroll-x')) &&
39
+ new Date().getTime() - window.lastScrollTime > 200 &&
40
+ scrollX(parent.parentNode.querySelector(evt.deltaY > 0 ? '.scroll-right' : '.scroll-left'))
41
+ ) {
42
+ window.lastScrollTime = new Date().getTime()
43
+ window.isScrolling = false
44
+ return
45
+ }
46
+
47
+ if (new Date().getTime() - window.lastScrollTime > 200) {
48
+ window.lastScrollTime = new Date().getTime()
49
+ const toScrollHeight = element.dataset.toscroll ?? 600
50
+ window.scrollBy({ top: evt.deltaY > 0 ? toScrollHeight : -toScrollHeight, left: 0, behavior: 'smooth' })
51
+ }
52
+ } else window.lastScrollTime = new Date().getTime()
53
+ window.isScrolling = false
41
54
  })
42
- return this
43
55
  }
44
56
 
45
57
  enhanceScrollY(element) {
@@ -132,20 +144,26 @@ class ScrollXEnhancer {
132
144
 
133
145
  wheelScroll(element) {
134
146
  element.addEventListener('wheel', (evt) => {
135
- evt.preventDefault()
136
- if (evt.target.closest('.enhance-scroll-y')) return
137
147
  if (window.isScrolling === true) return
138
- //element.classList.toggle('scroll-smooth')
148
+ evt.preventDefault()
149
+ window.isScrolling = true
150
+
151
+ if (evt.target.closest('.enhance-scroll-y')) {
152
+ window.isScrolling = false
153
+ return
154
+ }
155
+
139
156
  const before = element.scrollLeft
140
157
  element.scrollLeft += evt.deltaY
141
- const after = element.scrollLeft
142
- if (before === after) {
143
- window.scrollYWithoutDoingNothing++
144
- if (window.scrollYWithoutDoingNothing > 10) window.scrollBy(0, evt.deltaY / 2)
145
- } else {
146
- window.scrollYWithoutDoingNothing = 0
147
- }
148
- //element.classList.toggle('scroll-smooth')
158
+
159
+ if (before === element.scrollLeft) {
160
+ if (new Date().getTime() - window.lastScrollTime > 200) {
161
+ window.lastScrollTime = new Date().getTime()
162
+ const toScrollHeight = element.dataset.toscroll ?? 600
163
+ window.scrollBy({ top: evt.deltaY > 0 ? toScrollHeight : -toScrollHeight, left: 0, behavior: 'smooth' })
164
+ }
165
+ } else window.lastScrollTime = new Date().getTime()
166
+ window.isScrolling = false
149
167
  })
150
168
  }
151
169
 
@@ -165,7 +183,9 @@ class ScrollXEnhancer {
165
183
 
166
184
  const nextElementToScroll = element.children[3] // work only with equal width block
167
185
  const toScrollWidth = nextElementToScroll.offsetWidth + parseInt(window.getComputedStyle(nextElementToScroll).marginLeft)
186
+ const before = element.scrollLeft
168
187
  element.scrollLeft += scrollToRight ? toScrollWidth : -toScrollWidth
188
+ return before !== element.scrollLeft
169
189
  }
170
190
 
171
191
  manageScrollXControllerVisibility(element) {