@@ -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 ) {
0 commit comments