@cocreate/scroll 1.3.4 → 1.3.5

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,10 @@
1
+ ## [1.3.5](https://github.com/CoCreate-app/CoCreate-scroll/compare/v1.3.4...v1.3.5) (2022-06-19)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * removed scroll-element support as it was causing a loop. Moved to branch newScroll fordebugging ([f8d99c7](https://github.com/CoCreate-app/CoCreate-scroll/commit/f8d99c707b0e87032f7dd547b3342d308182c6d6))
7
+
1
8
  ## [1.3.4](https://github.com/CoCreate-app/CoCreate-scroll/compare/v1.3.3...v1.3.4) (2022-06-18)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/scroll",
3
- "version": "1.3.4",
3
+ "version": "1.3.5",
4
4
  "description": "A simple scroll component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "scroll",
package/src/index.js CHANGED
@@ -3,9 +3,6 @@ import observer from '@cocreate/observer';
3
3
  const CoCreateScroll = {
4
4
  delta: 3,
5
5
  observer: null,
6
- timer: null,
7
- firedEvents: new Map(),
8
-
9
6
  init: function() {
10
7
  let elements = document.querySelectorAll(`[scroll]`);
11
8
  this.__initIntersectionObserver();
@@ -23,7 +20,6 @@ const CoCreateScroll = {
23
20
  const downSize = this.__getSize(element.getAttribute('scroll-down'));
24
21
  const attrName = element.getAttribute('scroll-attribute') || 'class';
25
22
  const targetSelector = element.getAttribute('scroll-target');
26
- const scrollSelector = element.getAttribute('scroll-element');
27
23
  const intersectValue = element.getAttribute('scroll-intersect');
28
24
 
29
25
  let values = element.getAttribute('scroll') || "";
@@ -49,66 +45,33 @@ const CoCreateScroll = {
49
45
  el.scrollStatus = { currentPos: 0 };
50
46
  });
51
47
 
52
- // this.__runScrollEvent(element, scrollInfo);
53
-
54
- let scrollableElements;
55
- if (scrollSelector)
56
- scrollableElements = document.querySelectorAll(scrollSelector);
57
-
58
- if (scrollableElements) {
59
- for (let scrollableEl of scrollableElements) {
60
- scrollableEl.addEventListener('scroll', function(event) {
61
- self._scrollEvent(elements, element, scrollInfo, scrollableEl)
62
- });
63
- }
64
- } else{
65
- // this.WindowInit = true;
66
- window.addEventListener('scroll', function(event) {
67
- self._scrollEvent(elements, element, scrollInfo)
68
- });
69
- }
70
-
71
- if (intersectValue && window.IntersectionObserver && this.observer) {
72
- this.observer.observe(element);
73
- }
74
- },
75
-
76
- _scrollEvent: function(elements, element, scrollInfo, scrollableEl) {
77
- const self = this;
78
- if (!element.scrollStatus) return;
79
- let scrollEl = scrollableEl || window;
80
- if (Math.abs(scrollEl.scrollTop || scrollEl.scrollY - element.scrollStatus.currentPos) <= self.delta) {
81
- return;
82
- }
48
+ this.__runScrollEvent(element, scrollInfo);
83
49
 
84
50
  let timer = null;
85
- if (timer != null) {
86
- clearTimeout(timer);
87
- }
88
-
89
- elements.forEach((el) => {
90
- self.__setScrolling(el, scrollInfo, false);
91
- // self.__runScrollEvent(el, scrollInfo, scrollableEl);
51
+ window.addEventListener('scroll', function(event) {
52
+ if (!element.scrollStatus) return;
53
+ if (Math.abs(window.scrollY - element.scrollStatus.currentPos) <= self.delta) {
54
+ return;
55
+ }
92
56
 
93
- });
57
+ if (timer != null) {
58
+ clearTimeout(timer);
59
+ }
94
60
 
95
- timer = setTimeout(function() {
96
61
  elements.forEach((el) => {
97
- self.__setScrolling(el, scrollInfo, true);
62
+ self.__runScrollEvent(el, scrollInfo);
63
+ self.__setScrolling(el, scrollInfo, false);
98
64
  });
99
- }, 500);
100
65
 
101
- if (!self.firedEvents.has(element)) {
102
- self.firedEvents.set(element, element)
103
- elements.forEach((el) => {
104
- self.__runScrollEvent(el, scrollInfo, scrollableEl);
105
- });
106
- setTimeout(function() {
107
- self.firedEvents.delete(element)
108
- // clearTimeout(eventTimer)
109
- }, 300);
66
+ timer = setTimeout(function() {
67
+ elements.forEach((el) => {
68
+ self.__setScrolling(el, scrollInfo, true);
69
+ });
70
+ }, 500);
71
+ });
72
+ if (intersectValue && window.IntersectionObserver && this.observer) {
73
+ this.observer.observe(element);
110
74
  }
111
-
112
75
  },
113
76
 
114
77
  __initIntersectionObserver: function() {
@@ -144,19 +107,10 @@ const CoCreateScroll = {
144
107
  }
145
108
  },
146
109
 
147
- __runScrollEvent: function(element, info, scrollableEl) {
110
+ __runScrollEvent: function(element, info) {
148
111
  if (!element.scrollStatus) return
149
112
  const currentPos = element.scrollStatus.currentPos;
150
- let scrollY, scrollHeight, innerHeight;
151
- if (scrollableEl){
152
- scrollY = scrollableEl.scrollTop;
153
- scrollHeight = scrollableEl.scrollHeight
154
- innerHeight = scrollableEl.clientHeight
155
- } else {
156
- scrollY = window.scrollY;
157
- scrollHeight = document.body.scrollHeight
158
- innerHeight = window.innerHeight
159
- }
113
+ const scrollY = window.scrollY;
160
114
  const { upSize, downSize, attrName, values, scrollTop, scrollBottom, scrollLimbo } = info;
161
115
 
162
116
  if (upSize < (currentPos - scrollY)) {
@@ -180,8 +134,7 @@ const CoCreateScroll = {
180
134
  }
181
135
 
182
136
  //. scroll bottom case
183
- // if ((window.innerHeight + scrollY) >= document.body.scrollHeight) {
184
- if ((innerHeight + scrollY) >= scrollHeight) {
137
+ if ((window.innerHeight + scrollY) >= document.body.scrollHeight) {
185
138
  // this.__removeAttrbuteValue(element, attrName, values[0]);
186
139
  // this.__removeAttrbuteValue(element, attrName, values[1]);
187
140
 
@@ -191,8 +144,7 @@ const CoCreateScroll = {
191
144
  this.__removeAttrbuteValue(element, attrName, scrollBottom);
192
145
  }
193
146
 
194
- // if (scrollY != 0 && (scrollY + window.innerHeight) != document.body.scrollHeight){
195
- if (scrollY != 0 && (scrollY + innerHeight) != scrollHeight){
147
+ if (scrollY != 0 && (scrollY + window.innerHeight) != document.body.scrollHeight){
196
148
  this.__addAttributeValue(element, attrName, scrollLimbo);
197
149
  }
198
150
  else {
@@ -245,6 +197,8 @@ const CoCreateScroll = {
245
197
  return size;
246
198
  }
247
199
 
200
+
201
+
248
202
  };
249
203
 
250
204
  observer.init({
@@ -259,4 +213,4 @@ observer.init({
259
213
 
260
214
  CoCreateScroll.init();
261
215
 
262
- export default CoCreateScroll;
216
+ export default CoCreateScroll;