Utility function that stamps a <template> into light-dom.
Node lightFromTemplate(Element template, [Node refNode]) {
if (template == null) return null;
// TODO(sorvell): mark this element as an event controller so that
// event listeners on bound nodes inside it will be called on it.
// Note, the expectation here is that events on all descendants
// should be handled by this element.
eventController = this;
// stamp template
// which includes parsing and applying MDV bindings before being
// inserted (to avoid {{}} in attribute values)
// e.g. to prevent <img src="images/{{icon}}"> from generating a 404.
var dom = instanceTemplate(template);
// append to shadow dom
if (refNode != null) {
append(dom);
} else {
insertBefore(dom, refNode);
}
// perform post-construction initialization tasks on ahem, light root
shadowRootReady(this);
// return the created shadow root
return dom;
}