@cocreate/lazy-loader 1.0.10 → 1.1.2
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/docs/index.html +1 -1
- package/package.json +4 -4
- package/src/index.js +29 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## [1.1.2](https://github.com/CoCreate-app/CoCreate-lazy-loader/compare/v1.1.1...v1.1.2) (2022-09-01)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* bump all of [@cocreate](https://github.com/cocreate) dependencies ([c2879ba](https://github.com/CoCreate-app/CoCreate-lazy-loader/commit/c2879bafb1437f2de21480442bf5e38047924f19))
|
|
7
|
+
|
|
8
|
+
## [1.1.1](https://github.com/CoCreate-app/CoCreate-lazy-loader/compare/v1.1.0...v1.1.1) (2022-07-03)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* update pass-fetch and pass-filter attributes ([ef36769](https://github.com/CoCreate-app/CoCreate-lazy-loader/commit/ef36769bc387b51e0f6a7a231db20eb74cfad98f))
|
|
14
|
+
|
|
15
|
+
# [1.1.0](https://github.com/CoCreate-app/CoCreate-lazy-loader/compare/v1.0.10...v1.1.0) (2022-06-23)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* observe attributes if match found lazyload component ([755c88b](https://github.com/CoCreate-app/CoCreate-lazy-loader/commit/755c88b01222ebe85e51aa633be313a762e2d102))
|
|
21
|
+
|
|
1
22
|
## [1.0.10](https://github.com/CoCreate-app/CoCreate-lazy-loader/compare/v1.0.9...v1.0.10) (2022-06-18)
|
|
2
23
|
|
|
3
24
|
|
package/docs/index.html
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/lazy-loader",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "A simple lazy-loader component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lazy-loader",
|
|
@@ -61,8 +61,8 @@
|
|
|
61
61
|
"webpack-log": "^3.0.1"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@cocreate/docs": "^1.3.
|
|
65
|
-
"@cocreate/hosting": "^1.3.
|
|
66
|
-
"@cocreate/observer": "^1.5.
|
|
64
|
+
"@cocreate/docs": "^1.3.5",
|
|
65
|
+
"@cocreate/hosting": "^1.3.4",
|
|
66
|
+
"@cocreate/observer": "^1.5.4"
|
|
67
67
|
}
|
|
68
68
|
}
|
package/src/index.js
CHANGED
|
@@ -11,12 +11,12 @@ export function removeComponent(key) {
|
|
|
11
11
|
function listen(callback, selector) {
|
|
12
12
|
|
|
13
13
|
function observerCallback({ target }) {
|
|
14
|
-
let isInit = target.querySelector(selector)
|
|
15
|
-
if (isInit) {
|
|
14
|
+
// let isInit = target.querySelector(selector)
|
|
15
|
+
// if (isInit) {
|
|
16
16
|
callback()
|
|
17
17
|
// console.log('lazyloaded', selector)
|
|
18
18
|
observer.uninit(observerCallback)
|
|
19
|
-
}
|
|
19
|
+
// }
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
observer.init({
|
|
@@ -26,7 +26,32 @@ function listen(callback, selector) {
|
|
|
26
26
|
callback: observerCallback
|
|
27
27
|
})
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
let selectorAttributes = [];
|
|
30
|
+
let attributes = selector.split(",")
|
|
31
|
+
for (let attribute of attributes){
|
|
32
|
+
let attr = attribute.trim()
|
|
33
|
+
if (attr.startsWith("[")) {
|
|
34
|
+
let pos = attr.indexOf("*")
|
|
35
|
+
if (pos == -1)
|
|
36
|
+
pos = attr.indexOf("=")
|
|
37
|
+
if (pos !== -1) {
|
|
38
|
+
attr = attr.slice(1, pos)
|
|
39
|
+
} else {
|
|
40
|
+
attr = attr.slice(1, -1)
|
|
41
|
+
}
|
|
42
|
+
selectorAttributes.push(attr)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
if (selectorAttributes.length > 0)
|
|
47
|
+
observer.init({
|
|
48
|
+
name: 'lazyloadAttributeObserver',
|
|
49
|
+
observe: ['attributes'],
|
|
50
|
+
attributeName: selectorAttributes,
|
|
51
|
+
target: selector,
|
|
52
|
+
callback: observerCallback
|
|
53
|
+
});
|
|
54
|
+
|
|
30
55
|
}
|
|
31
56
|
|
|
32
57
|
export async function lazyLoad(name, selector, cb) {
|