@cocreate/lazy-loader 1.0.8 → 1.1.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.1.0](https://github.com/CoCreate-app/CoCreate-lazy-loader/compare/v1.0.10...v1.1.0) (2022-06-23)
2
+
3
+
4
+ ### Features
5
+
6
+ * observe attributes if match found lazyload component ([755c88b](https://github.com/CoCreate-app/CoCreate-lazy-loader/commit/755c88b01222ebe85e51aa633be313a762e2d102))
7
+
8
+ ## [1.0.10](https://github.com/CoCreate-app/CoCreate-lazy-loader/compare/v1.0.9...v1.0.10) (2022-06-18)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * bump dependencies ([8631da5](https://github.com/CoCreate-app/CoCreate-lazy-loader/commit/8631da5a9fa27aec4121899b9c913a70b1dfeb31))
14
+
15
+ ## [1.0.9](https://github.com/CoCreate-app/CoCreate-lazy-loader/compare/v1.0.8...v1.0.9) (2022-06-12)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * update dependencies ([d7e5038](https://github.com/CoCreate-app/CoCreate-lazy-loader/commit/d7e5038b36b3ca45625ca36fbd769337f2261531))
21
+
1
22
  ## [1.0.8](https://github.com/CoCreate-app/CoCreate-lazy-loader/compare/v1.0.7...v1.0.8) (2022-05-23)
2
23
 
3
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/lazy-loader",
3
- "version": "1.0.8",
3
+ "version": "1.1.0",
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.1",
65
- "@cocreate/hosting": "^1.3.1",
66
- "@cocreate/observer": "^1.5.1"
64
+ "@cocreate/docs": "^1.3.3",
65
+ "@cocreate/hosting": "^1.3.3",
66
+ "@cocreate/observer": "^1.5.3"
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
- // todo: observer add attributes
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) {