@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 +21 -0
- package/CoCreate.config.js +2 -2
- package/demo/index.html +1 -1
- package/docs/index.html +28 -28
- package/package.json +3 -4
- package/src/index.js +241 -241
- package/webpack.config.js +79 -73
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
|
|
package/CoCreate.config.js
CHANGED
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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-
|
|
54
|
+
resize-selector="[content_id='content']"
|
|
55
55
|
resize-property="margin-left"
|
|
56
56
|
resize-value="width">
|
|
57
57
|
<menu
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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
|
-
|
|
353
|
-
|
|
354
|
-
|
|
352
|
+
array="demos"
|
|
353
|
+
object=""
|
|
354
|
+
key="demo"
|
|
355
355
|
save="false"
|
|
356
356
|
id="demo"
|
|
357
|
-
input-
|
|
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-
|
|
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-
|
|
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-
|
|
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.
|
|
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": "
|
|
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/
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
243
|
+
name: 'CoCreateScrollCreate',
|
|
244
|
+
observe: ['addedNodes'],
|
|
245
|
+
target: '[scroll]',
|
|
246
|
+
callback: function (mutation) {
|
|
247
247
|
|
|
248
|
-
|
|
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
|
-
|
|
9
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
54
|
-
|
|
57
|
+
// add source map
|
|
58
|
+
...(isProduction ? {} : { devtool: "eval-source-map" }),
|
|
55
59
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
83
|
+
cacheGroups: {
|
|
84
|
+
defaultVendors: false,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
}
|
|
89
|
+
return config
|
|
90
|
+
}
|