@cocreate/scroll 1.5.27 → 1.6.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.6.0](https://github.com/CoCreate-app/CoCreate-scroll/compare/v1.5.28...v1.6.0) (2023-08-16)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * crud attributes renamed ([973d02d](https://github.com/CoCreate-app/CoCreate-scroll/commit/973d02d5cfaa0f091d5b7ddd809d9221da6cf90d))
7
+ * replace -target -selector ([bc8aecc](https://github.com/CoCreate-app/CoCreate-scroll/commit/bc8aecc98134e9e8ff032527dfc61aef16cb87bc))
8
+ * webpack.config and package.json make use of mode=production instead of process.env ([bffad89](https://github.com/CoCreate-app/CoCreate-scroll/commit/bffad894608346a240a1d62969b878277a0e6ef4))
9
+
10
+
11
+ ### Features
12
+
13
+ * name attribute and variable renamed to key ([6f7e1b0](https://github.com/CoCreate-app/CoCreate-scroll/commit/6f7e1b04f300350c7423075998c11d56173cb098))
14
+
15
+ ## [1.5.28](https://github.com/CoCreate-app/CoCreate-scroll/compare/v1.5.27...v1.5.28) (2023-06-14)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * Update dependencies versions for [@cocreate](https://github.com/cocreate) libraries ([3a75aef](https://github.com/CoCreate-app/CoCreate-scroll/commit/3a75aefc5ce12450444d4c916b3d785a617bade8))
21
+
1
22
  ## [1.5.27](https://github.com/CoCreate-app/CoCreate-scroll/compare/v1.5.26...v1.5.27) (2023-06-11)
2
23
 
3
24
 
@@ -4,8 +4,8 @@ module.exports = {
4
4
  "host": "",
5
5
  "sources": [
6
6
  {
7
- "collection": "files",
8
- "document": {
7
+ "array": "files",
8
+ "object": {
9
9
  "_id": "602095e13c260207bf49cac4",
10
10
  "name": "index.html",
11
11
  "path": "/docs/scroll/index.html",
package/demo/index.html CHANGED
@@ -4,7 +4,7 @@
4
4
  <meta charset="utf-8" />
5
5
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
6
6
  <meta
7
- name="description"
7
+ key="description"
8
8
  content="Instantly create a start-up or manage and grow an existing business, all-in-one Realtime callobrative solution complete with many automation's and a customizable website." />
9
9
  <meta name="keywords" content="CoCreate, app landing, responsive" />
10
10
  <meta name="viewport" content="width=device-width, initial-scale=1" />
package/docs/index.html CHANGED
@@ -11,10 +11,10 @@
11
11
  sizes="32x32"
12
12
  href="https://cocreate.app/images/favicon.ico" />
13
13
  <meta
14
- name="description"
14
+ key="description"
15
15
  content="A simple HTML5 and pure javascript component. Easy configuration using HTML5 attributes or Javscript api and highly styleable." />
16
16
  <meta
17
- name="keywords"
17
+ key="keywords"
18
18
  content="helper classes, utility classes, css framework, css library, inline style classes" />
19
19
  <meta name="robots" content="index,follow" />
20
20
  <meta
@@ -29,9 +29,9 @@
29
29
  <link
30
30
  rel="stylesheet"
31
31
  href="/docs/index.css"
32
- collection="files"
33
- document_id="60888216117c640e7596303f"
34
- name="src"
32
+ array="files"
33
+ object="60888216117c640e7596303f"
34
+ key="src"
35
35
  type="text/css"
36
36
  save="true" />
37
37
  <link rel="manifest" href="/manifest.webmanifest" />
@@ -44,20 +44,20 @@
44
44
  scroll="sticky-nav,hide-nav"
45
45
  scroll-up="10"
46
46
  scroll-down="10"
47
- collection="files"
48
- document_id="60395ef42b3ac232657040fd"
49
- name="src"></nav>
47
+ array="files"
48
+ object="60395ef42b3ac232657040fd"
49
+ key="src"></nav>
50
50
  <sidenav
51
51
  id="menuL"
52
52
  class="position:fixed top:0px left:0px overflow:hidden background:whitesmoke height:100vh width:0px width:300px@xl"
53
53
  resizable
54
- resize-target="[content_id='content']"
54
+ resize-selector="[content_id='content']"
55
55
  resize-property="margin-left"
56
56
  resize-value="width">
57
57
  <menu
58
- collection="files"
59
- document_id="603717b07de7fb350ae9fec8"
60
- name="src"></menu>
58
+ array="files"
59
+ object="603717b07de7fb350ae9fec8"
60
+ key="src"></menu>
61
61
  <div resize="right"></div>
62
62
  </sidenav>
63
63
  <main
@@ -80,7 +80,7 @@
80
80
  share-width="700"
81
81
  share-media="https://cdn.cocreate.app/docs/scroll.png"
82
82
  hover="display:block!important"
83
- hover-target=".social-networks">
83
+ hover-selector=".social-networks">
84
84
  <div class="display:none social-networks">
85
85
  <a
86
86
  class="margin-right:15px"
@@ -139,11 +139,11 @@
139
139
  class="border-bottom:1px_solid_lightgrey"
140
140
  scroll
141
141
  scroll-intersect="color:dodgerblue"
142
- scroll-target="#scroll-install-section">
142
+ scroll-selector="#scroll-install-section">
143
143
  <span
144
144
  class="display:flex align-items:center width:fit-content"
145
145
  hover="display:block!important"
146
- hover-target="[href='#scroll-install']">
146
+ hover-selector="[href='#scroll-install']">
147
147
  <h2 class="padding:5px_0px">Install</h2>
148
148
  <a
149
149
  class="margin-left:10px display:none"
@@ -165,11 +165,11 @@
165
165
  class="margin-top:80px border-bottom:1px_solid_lightgrey"
166
166
  scroll
167
167
  scroll-intersect="color:dodgerblue"
168
- scroll-target="#scroll-usage-section">
168
+ scroll-selector="#scroll-usage-section">
169
169
  <span
170
170
  class="display:flex align-items:center width:fit-content"
171
171
  hover="display:block!important"
172
- hover-target="[href='#scroll-usage']">
172
+ hover-selector="[href='#scroll-usage']">
173
173
  <h2 class="padding:5px_0px">Usage</h2>
174
174
  <a
175
175
  class="margin-left:10px display:none"
@@ -203,11 +203,11 @@
203
203
  class="margin-top:80px border-bottom:1px_solid_lightgrey"
204
204
  scroll
205
205
  scroll-intersect="color:dodgerblue"
206
- scroll-target="#scroll-attributes-section">
206
+ scroll-selector="#scroll-attributes-section">
207
207
  <span
208
208
  class="display:flex align-items:center width:fit-content"
209
209
  hover="display:block!important"
210
- hover-target="[href='#scroll-attributes']">
210
+ hover-selector="[href='#scroll-attributes']">
211
211
  <h2 class="padding:5px_0px">Attributes</h2>
212
212
  <a
213
213
  class="margin-left:10px display:none"
@@ -321,11 +321,11 @@
321
321
  class="border-bottom:1px_solid_lightgrey"
322
322
  scroll
323
323
  scroll-intersect="color:dodgerblue"
324
- scroll-target="#scroll-demo-section">
324
+ scroll-selector="#scroll-demo-section">
325
325
  <span
326
326
  class="display:flex align-items:center width:fit-content"
327
327
  hover="display:block!important"
328
- hover-target="[href='#scroll-demo']">
328
+ hover-selector="[href='#scroll-demo']">
329
329
  <h2 class="padding:5px_0px">Demo</h2>
330
330
  <a
331
331
  class="margin-left:10px display:none"
@@ -349,12 +349,12 @@
349
349
  <textarea
350
350
  type="code"
351
351
  lang="html"
352
- collection="demos"
353
- document_id=""
354
- name="demo"
352
+ array="demos"
353
+ object=""
354
+ key="demo"
355
355
  save="false"
356
356
  id="demo"
357
- input-target=".demopreview"
357
+ input-selector=".demopreview"
358
358
  input-attribute="value"
359
359
  input-events="input, onload"
360
360
  class="height:100% width:100% outline:none border:none resize:none padding:5px"></textarea>
@@ -377,7 +377,7 @@
377
377
  show="#eye-slash"
378
378
  hide="#eye, #demo-preview"
379
379
  toggle="code-height"
380
- toggle-target="#demo-code"
380
+ toggle-selector="#demo-code"
381
381
  ><i
382
382
  class="height:18px fill:#505050"
383
383
  src="/assets/svg/eye.svg"></i
@@ -389,7 +389,7 @@
389
389
  show="#eye, #demo-preview"
390
390
  hide="#eye-slash"
391
391
  toggle="code-height"
392
- toggle-target="#demo-code"
392
+ toggle-selector="#demo-code"
393
393
  ><i
394
394
  class="height:20px fill:#505050"
395
395
  src="/assets/svg/eye-slash.svg"></i
@@ -416,7 +416,7 @@
416
416
  <a
417
417
  class="margin-right:5px"
418
418
  fullscreen
419
- fullscreen-target="#playground"></a>
419
+ fullscreen-selector="#playground"></a>
420
420
  </div>
421
421
  </div>
422
422
  <!-- End SandBox -->
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/scroll",
3
- "version": "1.5.27",
3
+ "version": "1.6.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",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "scripts": {
27
27
  "start": "npx webpack --config webpack.config.js",
28
- "build": "NODE_ENV=production npx webpack --config webpack.config.js",
28
+ "build": "npx webpack --mode=production --config webpack.config.js",
29
29
  "dev": "npx webpack --config webpack.config.js --watch",
30
30
  "postinstall": "node -e \"const { execSync } = require('child_process'); try { execSync('coc --version', { stdio: 'ignore' }); } catch (error) { try { execSync('npm install -g @cocreate/cli', { stdio: 'inherit' }); console.log('Installed \"@cocreate/cli\" globally.'); } catch (error) { console.error('Failed to install \"@cocreate/cli\" globally:', error); } }\""
31
31
  },
@@ -58,7 +58,6 @@
58
58
  "webpack-log": "^3.0.1"
59
59
  },
60
60
  "dependencies": {
61
- "@cocreate/cli": "^1.33.8",
62
- "@cocreate/observer": "^1.8.17"
61
+ "@cocreate/observer": "^1.8.19"
63
62
  }
64
63
  }
package/src/index.js CHANGED
@@ -1,252 +1,252 @@
1
1
  import observer from '@cocreate/observer';
2
2
 
3
3
  const CoCreateScroll = {
4
- delta: 3,
5
- observer: null,
6
- timer: null,
7
- firedEvents: new Map(),
8
-
9
- init: function() {
10
- let elements = document.querySelectorAll(`[scroll]`);
11
- this.__initIntersectionObserver();
12
- this.initElements(elements);
13
- },
14
-
15
- initElements: function(elements) {
16
- for (let el of elements)
17
- this.initElement(el);
18
- },
19
-
20
- initElement: function(element) {
21
- const self = this;
22
- const upSize = this.__getSize(element.getAttribute('scroll-up'));
23
- const downSize = this.__getSize(element.getAttribute('scroll-down'));
24
- const attrName = element.getAttribute('scroll-attribute') || 'class';
25
- const targetSelector = element.getAttribute('scroll-target');
26
- const scrollSelector = element.getAttribute('scroll-element');
27
- const intersectValue = element.getAttribute('scroll-intersect');
28
-
29
- let values = element.getAttribute('scroll') || "";
30
- values = values.split(",").map(x => x.trim());
31
-
32
- let scrollInfo = {
33
- attrName: attrName,
34
- values: values,
35
- upSize: upSize,
36
- downSize: downSize,
37
- scrollTop: element.getAttribute('scroll-top'),
38
- scrollLimbo: element.getAttribute('scroll-limbo'),
39
- scrollBottom: element.getAttribute('scroll-bottom'),
40
- scrolling: element.getAttribute('scrolling')
41
- };
42
-
43
- let elements = [element];
44
- if (targetSelector) {
45
- elements = document.querySelectorAll(targetSelector);
46
- }
47
-
48
- elements.forEach(el => {
49
- el.scrollStatus = { currentPos: 0 };
50
- });
51
-
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
- }
83
-
84
- 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);
92
-
93
- });
94
-
95
- timer = setTimeout(function() {
96
- elements.forEach((el) => {
97
- self.__setScrolling(el, scrollInfo, true);
98
- });
99
- }, 500);
100
- },
101
-
102
- __initIntersectionObserver: function() {
103
- const self = this;
104
- this.observer = new IntersectionObserver(entries => {
105
- entries.forEach(entry => {
106
- let element = entry.target;
107
- const attrName = element.getAttribute('scroll-attribute') || 'class';
108
- const targetSelector = element.getAttribute('scroll-target');
109
- const intersectValue = element.getAttribute('scroll-intersect');
110
-
111
- let targetElements = [element];
112
- if (targetSelector) {
113
- targetElements = document.querySelectorAll(targetSelector);
114
- }
115
- if (entry.isIntersecting > 0) {
116
- targetElements.forEach((el) => self.__addAttributeValue(el, attrName, intersectValue));
117
- }
118
- else {
119
- targetElements.forEach((el) => self.__removeAttrbuteValue(el, attrName, intersectValue));
120
- }
121
- });
122
- });
123
- },
124
-
125
- __setScrolling: function(element, info, stopped = false) {
126
- const { scrolling, attrName } = info;
127
- if (stopped) {
128
- this.__removeAttrbuteValue(element, attrName, scrolling);
129
- }
130
- else {
131
- this.__addAttributeValue(element, attrName, scrolling);
132
- }
133
- },
134
-
135
- __runScrollEvent: function(element, info, scrollableEl) {
136
- if (!element.scrollStatus) return
137
- const currentPos = element.scrollStatus.currentPos;
138
- let scrollY, scrollHeight, innerHeight;
139
- if (scrollableEl){
140
- scrollY = scrollableEl.scrollTop;
141
- scrollHeight = scrollableEl.scrollHeight
142
- innerHeight = scrollableEl.clientHeight
143
- } else {
144
- scrollY = window.scrollY;
145
- scrollHeight = document.body.scrollHeight
146
- innerHeight = window.innerHeight
147
- }
148
- const { upSize, downSize, attrName, values, scrollTop, scrollBottom, scrollLimbo } = info;
149
-
150
- let newTime = new Date().getTime()
151
- if (!info.datetime || (newTime - info.datetime) > 200 ) {
152
- info['datetime'] = newTime
153
-
154
- if (upSize <= (currentPos - scrollY)) {
155
- this.__addAttributeValue(element, attrName, values[0]);
156
- this.__removeAttrbuteValue(element, attrName, values[1]);
157
- }
158
- else if (downSize <= (scrollY - currentPos)) {
159
- this.__removeAttrbuteValue(element, attrName, values[0]);
160
- this.__addAttributeValue(element, attrName, values[1]);
161
- }
162
- }
163
- //. scroll top case
164
- if (scrollY <= this.delta) {
165
- this.__removeAttrbuteValue(element, attrName, values[0]);
166
- this.__removeAttrbuteValue(element, attrName, values[1]);
167
-
168
- this.__addAttributeValue(element, attrName, scrollTop);
169
- }
170
- else {
171
- this.__removeAttrbuteValue(element, attrName, scrollTop);
172
- }
173
-
174
- //. scroll bottom case
175
- // if ((window.innerHeight + scrollY) >= document.body.scrollHeight) {
176
- if ((innerHeight + scrollY) >= scrollHeight) {
177
- // this.__removeAttrbuteValue(element, attrName, values[0]);
178
- // this.__removeAttrbuteValue(element, attrName, values[1]);
179
-
180
- this.__addAttributeValue(element, attrName, scrollBottom);
181
- }
182
- else {
183
- this.__removeAttrbuteValue(element, attrName, scrollBottom);
184
- }
185
-
186
- // if (scrollY != 0 && (scrollY + window.innerHeight) != document.body.scrollHeight){
187
- if (scrollY != 0 && (scrollY + innerHeight) != scrollHeight){
188
- this.__addAttributeValue(element, attrName, scrollLimbo);
189
- }
190
- else {
191
- this.__removeAttrbuteValue(element, attrName, scrollLimbo);
192
- }
193
-
194
- element.scrollStatus.currentPos = scrollY;
195
- },
196
-
197
- __addAttributeValue: function(element, attrName, value) {
198
- if (!value) return;
199
- let check = new RegExp("(\\s|^)" + value + "(\\s|$)");
200
- let attrValue = element.getAttribute(attrName) || "";
201
-
202
- if (!check.test(attrValue)) {
203
- attrValue += " " + value;
204
- element.setAttribute(attrName, attrValue);
205
- }
206
- },
207
-
208
- __removeAttrbuteValue: function(element, attrName, value) {
209
- if (!value) return;
210
- let check = new RegExp("(\\s|^)" + value + "(\\s|$)");
211
- let attrValue = element.getAttribute(attrName) || "";
212
-
213
- if (check.test(attrValue)) {
214
- attrValue = attrValue.replace(check, " ").trim();
215
- element.setAttribute(attrName, attrValue);
216
- }
217
- },
218
-
219
- __getSize: function(attrValue, isWidth) {
220
- let size = 0;
221
- if (!attrValue) {
222
- return 0;
223
- }
224
-
225
- if (attrValue.includes('%')) {
226
- size = attrValue.replace('%', '').trim();
227
- size = Number(size) || 0;
228
-
229
- size = isWidth ? window.innerWidth / size : window.innerHeight / size;
230
-
231
- }
232
- else {
233
- size = attrValue.replace('px', '').trim();
234
- size = Number(size) || 0;
235
- }
236
-
237
- return size;
238
- }
4
+ delta: 3,
5
+ observer: null,
6
+ timer: null,
7
+ firedEvents: new Map(),
8
+
9
+ init: function () {
10
+ let elements = document.querySelectorAll(`[scroll]`);
11
+ this.__initIntersectionObserver();
12
+ this.initElements(elements);
13
+ },
14
+
15
+ initElements: function (elements) {
16
+ for (let el of elements)
17
+ this.initElement(el);
18
+ },
19
+
20
+ initElement: function (element) {
21
+ const self = this;
22
+ const upSize = this.__getSize(element.getAttribute('scroll-up'));
23
+ const downSize = this.__getSize(element.getAttribute('scroll-down'));
24
+ const attrName = element.getAttribute('scroll-attribute') || 'class';
25
+ const targetSelector = element.getAttribute('scroll-selector');
26
+ const scrollSelector = element.getAttribute('scroll-element');
27
+ const intersectValue = element.getAttribute('scroll-intersect');
28
+
29
+ let values = element.getAttribute('scroll') || "";
30
+ values = values.split(",").map(x => x.trim());
31
+
32
+ let scrollInfo = {
33
+ attrName: attrName,
34
+ values: values,
35
+ upSize: upSize,
36
+ downSize: downSize,
37
+ scrollTop: element.getAttribute('scroll-top'),
38
+ scrollLimbo: element.getAttribute('scroll-limbo'),
39
+ scrollBottom: element.getAttribute('scroll-bottom'),
40
+ scrolling: element.getAttribute('scrolling')
41
+ };
42
+
43
+ let elements = [element];
44
+ if (targetSelector) {
45
+ elements = document.querySelectorAll(targetSelector);
46
+ }
47
+
48
+ elements.forEach(el => {
49
+ el.scrollStatus = { currentPos: 0 };
50
+ });
51
+
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
+ }
83
+
84
+ 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);
92
+
93
+ });
94
+
95
+ timer = setTimeout(function () {
96
+ elements.forEach((el) => {
97
+ self.__setScrolling(el, scrollInfo, true);
98
+ });
99
+ }, 500);
100
+ },
101
+
102
+ __initIntersectionObserver: function () {
103
+ const self = this;
104
+ this.observer = new IntersectionObserver(entries => {
105
+ entries.forEach(entry => {
106
+ let element = entry.target;
107
+ const attrName = element.getAttribute('scroll-attribute') || 'class';
108
+ const targetSelector = element.getAttribute('scroll-selector');
109
+ const intersectValue = element.getAttribute('scroll-intersect');
110
+
111
+ let targetElements = [element];
112
+ if (targetSelector) {
113
+ targetElements = document.querySelectorAll(targetSelector);
114
+ }
115
+ if (entry.isIntersecting > 0) {
116
+ targetElements.forEach((el) => self.__addAttributeValue(el, attrName, intersectValue));
117
+ }
118
+ else {
119
+ targetElements.forEach((el) => self.__removeAttrbuteValue(el, attrName, intersectValue));
120
+ }
121
+ });
122
+ });
123
+ },
124
+
125
+ __setScrolling: function (element, info, stopped = false) {
126
+ const { scrolling, attrName } = info;
127
+ if (stopped) {
128
+ this.__removeAttrbuteValue(element, attrName, scrolling);
129
+ }
130
+ else {
131
+ this.__addAttributeValue(element, attrName, scrolling);
132
+ }
133
+ },
134
+
135
+ __runScrollEvent: function (element, info, scrollableEl) {
136
+ if (!element.scrollStatus) return
137
+ const currentPos = element.scrollStatus.currentPos;
138
+ let scrollY, scrollHeight, innerHeight;
139
+ if (scrollableEl) {
140
+ scrollY = scrollableEl.scrollTop;
141
+ scrollHeight = scrollableEl.scrollHeight
142
+ innerHeight = scrollableEl.clientHeight
143
+ } else {
144
+ scrollY = window.scrollY;
145
+ scrollHeight = document.body.scrollHeight
146
+ innerHeight = window.innerHeight
147
+ }
148
+ const { upSize, downSize, attrName, values, scrollTop, scrollBottom, scrollLimbo } = info;
149
+
150
+ let newTime = new Date().getTime()
151
+ if (!info.datetime || (newTime - info.datetime) > 200) {
152
+ info['datetime'] = newTime
153
+
154
+ if (upSize <= (currentPos - scrollY)) {
155
+ this.__addAttributeValue(element, attrName, values[0]);
156
+ this.__removeAttrbuteValue(element, attrName, values[1]);
157
+ }
158
+ else if (downSize <= (scrollY - currentPos)) {
159
+ this.__removeAttrbuteValue(element, attrName, values[0]);
160
+ this.__addAttributeValue(element, attrName, values[1]);
161
+ }
162
+ }
163
+ //. scroll top case
164
+ if (scrollY <= this.delta) {
165
+ this.__removeAttrbuteValue(element, attrName, values[0]);
166
+ this.__removeAttrbuteValue(element, attrName, values[1]);
167
+
168
+ this.__addAttributeValue(element, attrName, scrollTop);
169
+ }
170
+ else {
171
+ this.__removeAttrbuteValue(element, attrName, scrollTop);
172
+ }
173
+
174
+ //. scroll bottom case
175
+ // if ((window.innerHeight + scrollY) >= document.body.scrollHeight) {
176
+ if ((innerHeight + scrollY) >= scrollHeight) {
177
+ // this.__removeAttrbuteValue(element, attrName, values[0]);
178
+ // this.__removeAttrbuteValue(element, attrName, values[1]);
179
+
180
+ this.__addAttributeValue(element, attrName, scrollBottom);
181
+ }
182
+ else {
183
+ this.__removeAttrbuteValue(element, attrName, scrollBottom);
184
+ }
185
+
186
+ // if (scrollY != 0 && (scrollY + window.innerHeight) != document.body.scrollHeight){
187
+ if (scrollY != 0 && (scrollY + innerHeight) != scrollHeight) {
188
+ this.__addAttributeValue(element, attrName, scrollLimbo);
189
+ }
190
+ else {
191
+ this.__removeAttrbuteValue(element, attrName, scrollLimbo);
192
+ }
193
+
194
+ element.scrollStatus.currentPos = scrollY;
195
+ },
196
+
197
+ __addAttributeValue: function (element, attrName, value) {
198
+ if (!value) return;
199
+ let check = new RegExp("(\\s|^)" + value + "(\\s|$)");
200
+ let attrValue = element.getAttribute(attrName) || "";
201
+
202
+ if (!check.test(attrValue)) {
203
+ attrValue += " " + value;
204
+ element.setAttribute(attrName, attrValue);
205
+ }
206
+ },
207
+
208
+ __removeAttrbuteValue: function (element, attrName, value) {
209
+ if (!value) return;
210
+ let check = new RegExp("(\\s|^)" + value + "(\\s|$)");
211
+ let attrValue = element.getAttribute(attrName) || "";
212
+
213
+ if (check.test(attrValue)) {
214
+ attrValue = attrValue.replace(check, " ").trim();
215
+ element.setAttribute(attrName, attrValue);
216
+ }
217
+ },
218
+
219
+ __getSize: function (attrValue, isWidth) {
220
+ let size = 0;
221
+ if (!attrValue) {
222
+ return 0;
223
+ }
224
+
225
+ if (attrValue.includes('%')) {
226
+ size = attrValue.replace('%', '').trim();
227
+ size = Number(size) || 0;
228
+
229
+ size = isWidth ? window.innerWidth / size : window.innerHeight / size;
230
+
231
+ }
232
+ else {
233
+ size = attrValue.replace('px', '').trim();
234
+ size = Number(size) || 0;
235
+ }
236
+
237
+ return size;
238
+ }
239
239
 
240
240
  };
241
241
 
242
242
  observer.init({
243
- name: 'CoCreateScrollCreate',
244
- observe: ['addedNodes'],
245
- target: '[scroll]',
246
- callback: function(mutation) {
243
+ name: 'CoCreateScrollCreate',
244
+ observe: ['addedNodes'],
245
+ target: '[scroll]',
246
+ callback: function (mutation) {
247
247
 
248
- CoCreateScroll.initElement(mutation.target);
249
- }
248
+ CoCreateScroll.initElement(mutation.target);
249
+ }
250
250
  });
251
251
 
252
252
  CoCreateScroll.init();
package/webpack.config.js CHANGED
@@ -1,84 +1,90 @@
1
1
  const path = require("path")
2
2
  const TerserPlugin = require("terser-webpack-plugin")
3
3
  const MiniCssExtractPlugin = require("mini-css-extract-plugin")
4
- let isProduction = process.env.NODE_ENV === "production"
5
4
  const { CleanWebpackPlugin } = require("clean-webpack-plugin")
6
5
 
7
- module.exports = {
8
- entry: {
9
- "CoCreate-scroll": "./src/index.js",
10
- },
11
- output: {
12
- path: path.resolve(__dirname, "dist"),
13
- filename: isProduction ? "[name].min.js" : "[name].js",
14
- libraryTarget: "umd",
15
- libraryExport: "default",
16
- library: ["CoCreate", "scroll"],
17
- globalObject: "this",
18
- },
6
+ module.exports = (env, argv) => {
7
+ let isProduction = false
8
+ if (argv.mode === 'production')
9
+ isProduction = true
19
10
 
20
- plugins: [
21
- new CleanWebpackPlugin(),
22
- new MiniCssExtractPlugin({
23
- filename: "[name].css",
24
- }),
25
- ],
26
- // Default mode for Webpack is production.
27
- // Depending on mode Webpack will apply different things
28
- // on final bundle. For now we don't need production's JavaScript
29
- // minifying and other thing so let's set mode to development
30
- mode: isProduction ? "production" : "development",
31
- module: {
32
- rules: [
33
- {
34
- test: /.js$/,
35
- exclude: /(node_modules)/,
36
- use: {
37
- loader: "babel-loader",
38
- options: {
39
- plugins: ["@babel/plugin-transform-modules-commonjs"],
40
- },
11
+ const config = {
12
+ entry: {
13
+ "CoCreate-scroll": "./src/index.js",
41
14
  },
42
- },
43
- {
44
- test: /.css$/i,
45
- use: [
46
- { loader: "style-loader", options: { injectType: "linkTag" } },
47
- "file-loader",
15
+ output: {
16
+ path: path.resolve(__dirname, "dist"),
17
+ filename: isProduction ? "[name].min.js" : "[name].js",
18
+ libraryTarget: "umd",
19
+ libraryExport: "default",
20
+ library: ["CoCreate", "scroll"],
21
+ globalObject: "this",
22
+ },
23
+
24
+ plugins: [
25
+ new CleanWebpackPlugin(),
26
+ new MiniCssExtractPlugin({
27
+ filename: "[name].css",
28
+ }),
48
29
  ],
49
- },
50
- ],
51
- },
30
+ // Default mode for Webpack is production.
31
+ // Depending on mode Webpack will apply different things
32
+ // on final bundle. For now we don't need production's JavaScript
33
+ // minifying and other thing so let's set mode to development
34
+ mode: isProduction ? "production" : "development",
35
+ module: {
36
+ rules: [
37
+ {
38
+ test: /.js$/,
39
+ exclude: /(node_modules)/,
40
+ use: {
41
+ loader: "babel-loader",
42
+ options: {
43
+ plugins: ["@babel/plugin-transform-modules-commonjs"],
44
+ },
45
+ },
46
+ },
47
+ {
48
+ test: /.css$/i,
49
+ use: [
50
+ { loader: "style-loader", options: { injectType: "linkTag" } },
51
+ "file-loader",
52
+ ],
53
+ },
54
+ ],
55
+ },
52
56
 
53
- // add source map
54
- ...(isProduction ? {} : { devtool: "eval-source-map" }),
57
+ // add source map
58
+ ...(isProduction ? {} : { devtool: "eval-source-map" }),
55
59
 
56
- optimization: {
57
- minimize: true,
58
- minimizer: [
59
- new TerserPlugin({
60
- extractComments: true,
61
- // cache: true,
62
- parallel: true,
63
- // sourceMap: true, // Must be set to true if using source-maps in production
64
- terserOptions: {
65
- // https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
66
- // extractComments: 'all',
67
- compress: {
68
- drop_console: true,
69
- },
70
- },
71
- }),
72
- ],
73
- splitChunks: {
74
- chunks: "all",
75
- minSize: 200,
76
- // maxSize: 99999,
77
- //minChunks: 1,
60
+ optimization: {
61
+ minimize: true,
62
+ minimizer: [
63
+ new TerserPlugin({
64
+ extractComments: true,
65
+ // cache: true,
66
+ parallel: true,
67
+ // sourceMap: true, // Must be set to true if using source-maps in production
68
+ terserOptions: {
69
+ // https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
70
+ // extractComments: 'all',
71
+ compress: {
72
+ drop_console: true,
73
+ },
74
+ },
75
+ }),
76
+ ],
77
+ splitChunks: {
78
+ chunks: "all",
79
+ minSize: 200,
80
+ // maxSize: 99999,
81
+ //minChunks: 1,
78
82
 
79
- cacheGroups: {
80
- defaultVendors: false,
81
- },
82
- },
83
- },
84
- }
83
+ cacheGroups: {
84
+ defaultVendors: false,
85
+ },
86
+ },
87
+ },
88
+ }
89
+ return config
90
+ }