Я попытался создать свой собственный веб-компонент с помощью полифилла из https://github.com/webcomponents/webcomponentsjs.
Вот мой код:
им-список.html
<template id="im-list-temp">
<style>
:host {
list-style-type: none;
margin: 0;
padding: 0;
}
</style>
<content> </content>
</template>
<script>
var currentScript = document._currentScript || document.currentScript;
var proto = Object.create(HTMLUListElement.prototype, {
createdCallback: {
value: function() {
var doc = currentScript.ownerDocument;
var t = doc.querySelector("#im-list-temp");
var clone = doc.importNode(t.content, true);
var root = this.createShadowRoot();
root.appendChild(clone);
}
}
});
document.registerElement('im-list', {
prototype: proto,
extends: 'ul'
});
</script>
index.html
<!DOCTYPE html>
<html>
<head>
<script src="bower_components/webcomponentsjs/webcomponents.js"></script>
<link rel="import" href="./components/im-list.html" />
<title>List Test</title>
</head>
<body>
<ul is="im-list">
<li>Blubb</li>
<li>Blubb Blubb</li>
</ul>
</body>
</html>
Этот код отлично работает в Chrome (43.0.2357.81), но не работает в Firefox (38.0.1 и 40.0a2) и Safari (8.0.6). В FF и Safari <style>
просто добавляется к обычному DOM.