html5-template

Template html and template string in web components

我是研究僧i 提交于 2019-12-08 01:03:54
问题 Is it better to use html template (and then html import) to create web components or to use template string? What are pros and cons of these methods? 回答1: Using html template files is better for reuse: the same file can be used in different web components. Also they are better displayed in most IDEs as they are recognized as full HTML code. Using template strings is faster (inline). They don't rely on HTML Imports which is not adopted by every browser vendors. Also you can use template

Custom html tags on page render skip HTML parsing for some reason

允我心安 提交于 2019-12-04 04:29:54
问题 I don't know, why it's happening, but looks like custom html tags cannot parse it's content properly on page load if there's really a lot of such elements. document.registerElement('x-tag', { prototype: Object.create(HTMLElement.prototype, { attachedCallback: { value: function() { console.log(this.innerHTML, this.childNodes); // wrong innerHTML and childNodes once in n-occurrences } }}) } ); Here's an example My hypothesis is that there's some kind of stack, and sometimes this stack just

How to stamp out template in self contained custom elements with vanilla js?

你说的曾经没有我的故事 提交于 2019-12-01 20:23:45
I have a custom component that just shows a tarot card. Before the custom element I have defined a template. In my wc's connectedCallback I attached the template itself to the shadowroot and then stamped it out by cloning it there in the shadowroot as well. I did this for 2 reasons: I want my wc component to be a self contained module; therefore I want to define my template in the same place as my custom element. It seems to be the only way to stamp out my template to make it usable without sticking it in an owner document. var tmpl = ` <template id="tmpl"> <h1 class="tarot-title"><slot name=

Template tag polyfill for IE 11 - not working with table tr and td

ぐ巨炮叔叔 提交于 2019-12-01 06:32:28
I work with polyfill js that allows to process tags for browsers that does not support it. Source code of polyfill on jsfiddle Source question But I've noticed that in IE 11 this polyfill fails to work with templates that include <tr> and <td> tags My sample on jsfiddle The problem is that when we try to get childNodes from template tag node elPlate.childNodes it returns everything but <tr> and <td> children as if there were no such tags inside <template> . Am I missing something? Is there any workarounds for this issue? P.S I was not able to add a comment to source issue due to lack of

HTML Templates JavaScript polyfills

99封情书 提交于 2019-11-30 13:44:28
问题 I'm looking for the most standards-compliant / future-proof method for front-end HTML templating. There exists a relatively new W3C draft specification for HTML Templates, e.g.: <template id="mytemplate"> <img src="" alt="great image"> <div class="comment"></div> </template> Does anyone know if any good JavaScript polyfills already exist to make <template> element usable in a cross-browser way? Preferably complying with this standard. Difficulties According the the HTML5Rocks guide these

HTML Templates JavaScript polyfills

↘锁芯ラ 提交于 2019-11-30 08:24:48
I'm looking for the most standards-compliant / future-proof method for front-end HTML templating. There exists a relatively new W3C draft specification for HTML Templates , e.g.: <template id="mytemplate"> <img src="" alt="great image"> <div class="comment"></div> </template> Does anyone know if any good JavaScript polyfills already exist to make <template> element usable in a cross-browser way? Preferably complying with this standard. Difficulties According the the HTML5Rocks guide these templates have the following properties: "Its content is effectively inert until activated" "Script doesn

How can I create a web component that acts like a form element?

时光总嘲笑我的痴心妄想 提交于 2019-11-28 13:35:38
I am trying to create a web component that is usable in a form element specifically, that has a name , and a value . I recognize that I can create a web component that extends an HTMLInputElement : <input is="very-extended"> but I am trying to create an entirely new element. When creating a regular web component, you can create it from the prototype of a regular HTMLElement ( HTMLElement.prototype ). Which leads me to assume that I can create a different element with the prototype of an HTMLInputElement ( HTMLInputElement.prototype ). You actually use that prototype when extending the API of

Vanilla web-component structure

我的梦境 提交于 2019-11-28 00:27:04
I am looking into structuring vanilla web-components. I have previously used Polymer and like the fact that you can have the template, styles and JavaScript in one file for your component. I want to achieve this with 'vanilla' web components if possible but can't work out how. I've taken the code from here and added it to a file which I am using as follows: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Component test</title> <link rel="import" href="x-foo-from-template.html"> </head> <body> <x-foo-from

Share style across web components “of the same type”

拜拜、爱过 提交于 2019-11-27 15:20:52
If I understand it correctly, creating an instance of a web component can be summed up as creating a shadow root and copying the markup, e.g. from a template into it: var Template = document.querySelector('#myTemplate'); var TemplateClone = document.importNode(Template.content,true); TargetElement.appendChild(TemplateClone); Of course, if the template contains css rules in a style-tag, those will be copied as well. Thus we can have scoped styles which belong to the internal markup of a web component. Questions: Does it have any performance implications when I create tons of instances of the

Use of Template with HTML Custom Elements

大城市里の小女人 提交于 2019-11-27 09:44:53
I just started learning about the HTML custom elements, and through reading a series of intros, tutorials, and documentation, I think I have a good handle on how it works, but I have a philosophical question on the proper way to use or not use the <template> tag. Custom elements give you the ability to encapsulate new functionality, simplifying the structure of your HTML document, and allowing you to simply insert a <my-custom-element>...</my-custom-element> tag instead of <div class="my-custom-element"><span class="part1">...</span><span class="part2">...</span></div> . The class definition