@cocreate/scroll 1.2.27 → 1.3.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ # [1.3.0](https://github.com/CoCreate-app/CoCreate-scroll/compare/v1.2.29...v1.3.0) (2022-06-07)
2
+
3
+
4
+ ### Features
5
+
6
+ * sortable-element to define a scroll element defaults to window ([dd0b493](https://github.com/CoCreate-app/CoCreate-scroll/commit/dd0b49330b89afc6526b5ea9c81f7166615a57c0))
7
+
8
+ ## [1.2.29](https://github.com/CoCreate-app/CoCreate-scroll/compare/v1.2.28...v1.2.29) (2022-05-23)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * bump all dependencies ([4c5dcd0](https://github.com/CoCreate-app/CoCreate-scroll/commit/4c5dcd0a3097c55289ed365a966718a09c9ca099))
14
+
15
+ ## [1.2.28](https://github.com/CoCreate-app/CoCreate-scroll/compare/v1.2.27...v1.2.28) (2022-05-19)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * update document_id on link index.css ([501ef76](https://github.com/CoCreate-app/CoCreate-scroll/commit/501ef76623dc3d0989387f70b053939247943539))
21
+
1
22
  ## [1.2.27](https://github.com/CoCreate-app/CoCreate-scroll/compare/v1.2.26...v1.2.27) (2022-05-06)
2
23
 
3
24
 
package/docs/index.html CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  <!-- CoCreate CSS -->
16
16
  <link rel="stylesheet" href="https://cdn.cocreate.app/latest/CoCreate.min.css" type="text/css" />
17
- <link rel="stylesheet" href="/docs/index.css" collection="files" document_id="60888216117c640e7596303f" name="src" type="text/css" save="true" />
17
+ <link rel="stylesheet" href="/docs/index.css" collection="files" document_id="62827d7e8082ce05b081430b" name="src" type="text/css" save="true" />
18
18
  </head>
19
19
 
20
20
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/scroll",
3
- "version": "1.2.27",
3
+ "version": "1.3.0",
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",
@@ -61,7 +61,7 @@
61
61
  "webpack-log": "^3.0.1"
62
62
  },
63
63
  "dependencies": {
64
- "@cocreate/docs": "^1.2.69",
65
- "@cocreate/observer": "^1.4.4"
64
+ "@cocreate/docs": "^1.3.1",
65
+ "@cocreate/observer": "^1.5.1"
66
66
  }
67
67
  }
package/src/index.js CHANGED
@@ -3,6 +3,8 @@ import observer from '@cocreate/observer';
3
3
  const CoCreateScroll = {
4
4
  delta: 3,
5
5
  observer: null,
6
+ elementList: new Map(),
7
+
6
8
  init: function() {
7
9
  let elements = document.querySelectorAll(`[scroll]`);
8
10
  this.__initIntersectionObserver();
@@ -20,6 +22,7 @@ const CoCreateScroll = {
20
22
  const downSize = this.__getSize(element.getAttribute('scroll-down'));
21
23
  const attrName = element.getAttribute('scroll-attribute') || 'class';
22
24
  const targetSelector = element.getAttribute('scroll-target');
25
+ const scrollSelector = element.getAttribute('scroll-element');
23
26
  const intersectValue = element.getAttribute('scroll-intersect');
24
27
 
25
28
  let values = element.getAttribute('scroll') || "";
@@ -47,31 +50,49 @@ const CoCreateScroll = {
47
50
 
48
51
  this.__runScrollEvent(element, scrollInfo);
49
52
 
53
+ let scrollableElements;
54
+ if (scrollSelector)
55
+ scrollableElements = document.querySelectorAll(scrollSelector);
56
+
57
+ if (scrollableElements) {
58
+ for (let scrollableEl of scrollableElements)
59
+ scrollableEl.addEventListener('scroll', function(event) {
60
+ self._scrollEvent(elements, element, scrollInfo, scrollableEl)
61
+ });
62
+ } else {
63
+ window.addEventListener('scroll', function(event) {
64
+ self._scrollEvent(elements, element, scrollInfo)
65
+ });
66
+ }
67
+
68
+ if (intersectValue && window.IntersectionObserver && this.observer) {
69
+ this.observer.observe(element);
70
+ }
71
+ },
72
+
73
+ _scrollEvent: function(elements, element, scrollInfo, scrollableEl) {
74
+ const self = this;
75
+ if (!element.scrollStatus) return;
76
+ let scrollEl = scrollableEl || window;
77
+ if (Math.abs(scrollEl.scrollTop - element.scrollStatus.currentPos) <= self.delta) {
78
+ return;
79
+ }
80
+
50
81
  let timer = null;
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
- }
82
+ if (timer != null) {
83
+ clearTimeout(timer);
84
+ }
56
85
 
57
- if (timer != null) {
58
- clearTimeout(timer);
59
- }
86
+ elements.forEach((el) => {
87
+ self.__runScrollEvent(el, scrollInfo, scrollableEl);
88
+ self.__setScrolling(el, scrollInfo, false);
89
+ });
60
90
 
91
+ timer = setTimeout(function() {
61
92
  elements.forEach((el) => {
62
- self.__runScrollEvent(el, scrollInfo);
63
- self.__setScrolling(el, scrollInfo, false);
93
+ self.__setScrolling(el, scrollInfo, true);
64
94
  });
65
-
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);
74
- }
95
+ }, 500);
75
96
  },
76
97
 
77
98
  __initIntersectionObserver: function() {
@@ -107,10 +128,19 @@ const CoCreateScroll = {
107
128
  }
108
129
  },
109
130
 
110
- __runScrollEvent: function(element, info) {
131
+ __runScrollEvent: function(element, info, scrollableEl) {
111
132
  if (!element.scrollStatus) return
112
133
  const currentPos = element.scrollStatus.currentPos;
113
- const scrollY = window.scrollY;
134
+ let scrollY, scrollHeight, innerHeight;
135
+ if (scrollableEl){
136
+ scrollY = scrollableEl.scrollTop;
137
+ scrollHeight = scrollableEl.scrollHeight
138
+ innerHeight = scrollableEl.clientHeight
139
+ } else {
140
+ scrollY = window.scrollY;
141
+ scrollHeight = document.body.scrollHeight
142
+ innerHeight = window.innerHeight
143
+ }
114
144
  const { upSize, downSize, attrName, values, scrollTop, scrollBottom, scrollLimbo } = info;
115
145
 
116
146
  if (upSize < (currentPos - scrollY)) {
@@ -134,7 +164,8 @@ const CoCreateScroll = {
134
164
  }
135
165
 
136
166
  //. scroll bottom case
137
- if ((window.innerHeight + scrollY) >= document.body.scrollHeight) {
167
+ // if ((window.innerHeight + scrollY) >= document.body.scrollHeight) {
168
+ if ((innerHeight + scrollY) >= scrollHeight) {
138
169
  // this.__removeAttrbuteValue(element, attrName, values[0]);
139
170
  // this.__removeAttrbuteValue(element, attrName, values[1]);
140
171
 
@@ -144,7 +175,8 @@ const CoCreateScroll = {
144
175
  this.__removeAttrbuteValue(element, attrName, scrollBottom);
145
176
  }
146
177
 
147
- if (scrollY != 0 && (scrollY + window.innerHeight) != document.body.scrollHeight){
178
+ // if (scrollY != 0 && (scrollY + window.innerHeight) != document.body.scrollHeight){
179
+ if (scrollY != 0 && (scrollY + innerHeight) != scrollHeight){
148
180
  this.__addAttributeValue(element, attrName, scrollLimbo);
149
181
  }
150
182
  else {
@@ -197,8 +229,6 @@ const CoCreateScroll = {
197
229
  return size;
198
230
  }
199
231
 
200
-
201
-
202
232
  };
203
233
 
204
234
  observer.init({