@@ -11,12 +11,12 @@ export function removeComponent(key) {
1111function listen ( callback , selector ) {
1212
1313 function observerCallback ( { target } ) {
14- let isInit = target . querySelector ( selector )
15- if ( isInit ) {
14+ // let isInit = target.querySelector(selector)
15+ // if (isInit) {
1616 callback ( )
1717 // console.log('lazyloaded', selector)
1818 observer . uninit ( observerCallback )
19- }
19+ // }
2020 }
2121
2222 observer . init ( {
@@ -26,7 +26,32 @@ function listen(callback, selector) {
2626 callback : observerCallback
2727 } )
2828
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+
3055}
3156
3257export async function lazyLoad ( name , selector , cb ) {
0 commit comments