diff --git a/custom-element.js b/custom-element.js index bdea4d9..8f1cb7c 100644 --- a/custom-element.js +++ b/custom-element.js @@ -9,12 +9,22 @@ const attr = (el, attr)=> el.getAttribute?.(attr) , isText = e => e.nodeType === 3 , isString = s => typeof s === 'string' , isNode = e => e && typeof e.nodeType === 'number' -, create = ( tag, t = '', d=document ) => ( e => ((t && e.append(createText(d.ownerDocument||d, t))),e) )((d.ownerDocument || d ).createElement( tag )) , createText = ( d, t) => (d.ownerDocument || d ).createTextNode( t ) , removeChildren = n => { while(n.firstChild) n.firstChild.remove(); return n; } , emptyNode = n => { n.getAttributeNames().map( a => n.removeAttribute(a) ); return removeChildren(n); } , xslNs = x => ( x?.setAttribute('xmlns:xsl', XSL_NS_URL ), x ) , xslHtmlNs = x => ( x?.setAttribute('xmlns:xhtml', HTML_NS_URL ), xslNs(x) ) +, isValidTagName = tag=> ( /^[_a-zA-Z][-_:a-zA-Z0-9]*$/ .test(tag) ) +, create = ( tag, t = '', d=document ) => +{ + const create = tag => ( e => ((t && e.append(createText(d.ownerDocument||d, t))),e) )((d.ownerDocument || d ).createElement( tag )) + + if( isValidTagName(tag) ) + return create(tag) + const e = create('dce-object'); + e.setAttribute('dce-object-name',tag) + return e; +} , cloneAs = (p,tag) => { const px = p.ownerDocument.createElementNS(p.namespaceURI,tag); for( let a of p.attributes) @@ -86,7 +96,7 @@ obj2node( o, tag, doc ) if( isNode(o[k]) || typeof o[k] ==='function' || o[k] instanceof Window ) continue else - if( typeof o[k] !== "object" ) + if( typeof o[k] !== "object" && isValidTagName(k) ) ret.setAttribute(k, o[k] ); else ret.append(obj2node(o[k], k, doc)) @@ -594,7 +604,9 @@ CustomElement extends HTMLElement e.append( createText( x, t )) return e; })(x.ownerDocument.createElement( tag )) - injectData( x, 'payload' , payload , assureSlot ); + const payloadNode = injectData( x, 'payload' , payload , assureSlot ); + xslNs(payloadNode); + xslHtmlNs(payloadNode); this.innerHTML=''; const attrsRoot = injectData( x, 'attributes' , this.attributes, e => createXmlNode( e.nodeName, e.value ) ); injectData( x, 'dataset', Object.keys( this.dataset ), k => createXmlNode( k, this.dataset[ k ] ) ); @@ -654,7 +666,7 @@ CustomElement extends HTMLElement { if( !el.dceInitialized ) { el.dceInitialized = 1; let evs = attr(el,'slice-event'); - if( attr(el,'custom-validity') ) + if( el.hasAttribute('custom-validity') ) evs += ' change submit'; [...new Set((evs || 'change') .split(' '))] diff --git a/demo/location-element.html b/demo/location-element.html index c0ccc97..134629f 100644 --- a/demo/location-element.html +++ b/demo/location-element.html @@ -22,7 +22,19 @@ - +
+

How to get the page URL by location-element?

+ Answer: by defining following attributes: +
    +
  1. slice to one of values provided bellow
  2. +
  3. src optionally with URL, If omitted, it would match the window.location.href
  4. +
+ URL properties would be a part of slice data. +

Set page URL demo

+
+