Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 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 | 35x 1x 35x 35x 35x 30x 5x 5x 5x 35x 70x 35x 1x | const attr = ( el, attr )=> el.getAttribute( attr );
export class ModuleUrl extends HTMLElement
{
static observedAttributes=
[ 'slice'
, 'src' // module path, relative or absolute URL
];
sliceInit()
{ let path = attr(this,'src');
try
{ const url = '.' === path.charAt(0)
? new URL(path, this.closest('[base]')?.getAttribute('base') || location.href).href
: import.meta.resolve(path);
this.setAttribute('value',this.value = url );
}catch( er )
{ this.setAttribute('error', er.message);
this.setAttribute('value', path);
console.error(er.message ?? er, path);
}
this.dispatchEvent( new Event('change') );
}
attributeChangedCallback( name, oldValue, newValue )
{
if( 'src'=== name )
this.sliceInit();
}
}
window.customElements.define( 'module-url', ModuleUrl );
export default ModuleUrl;
|