-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
114 lines (101 loc) · 3.58 KB
/
index.html
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<head>
<meta charset="utf-8">
<title><slot-all></title>
<link rel="stylesheet" href="http://juicy.github.io/github-markdown-css/github-markdown.css">
<!-- Imports polyfill -->
<script src="../webcomponentsjs/webcomponents-lite.js"></script>
<!-- Imports ace editor for nicer demo -->
<link rel="import" href="../juicy-ace-editor/juicy-ace-editor.html">
<!-- Imports custom element -->
<link rel="import" href="slot-all.html">
<style type="text/css">
html,
body {
height: 100%;
}
juicy-ace-editor{
margin: 15px;
width: calc(50% - 15px);
min-height: 10em;
}
div[shadow-host]{
width: calc(50% - 15px);
}
.markdown-body {
margin: 1em auto;
width: 70%;
}
.code-comparison {
display: flex;
justify-content: space-around;
}
iframe {
float: right;
}
</style>
</head>
<body class="markdown-body">
<iframe src="http://ghbtns.com/github-btn.html?user=juicy&repo=slot-all&type=fork&count=true&size=medium" allowtransparency="true" frameborder="0" scrolling="0" width="90" height="30"></iframe>
<iframe src="http://ghbtns.com/github-btn.html?user=juicy&repo=slot-all&type=watch&count=true&size=medium" allowtransparency="true" frameborder="0" scrolling="0" width="90" height="30"></iframe>
<h1><slot-all></h1>
<blockquote>
<p>
Custom element to distribute all elements regardless of their slot name
</p>
</blockquote>
<div class="code-comparison">
<juicy-ace-editor
theme="ace/theme/monokai"
mode="ace/mode/html"><a slot="named">link</a>
<div slot="named">div</div>
<span slot="baz">span</span>
<p>default</p>
<template is="shadow-root">
<h3>
Distribute all elements for named slots without knowing their names
</h3>
<slot-all></slot-all>
<slot></slot>
</template></juicy-ace-editor>
<div shadow-host>
<a slot="named">link</a>
<div slot="named">div</div>
<span slot="baz">span</span>
<p>default</p>
<template is="shadow-root">
<h3>
Distribute all elements for named slots without knowing their names
</h3>
<slot-all></slot-all>
<slot></slot>
</template>
</div>
</div>
<h4>Looking for more specs? Check out the <a href="test/">test suite</a>.</h4>
</body>
<script>
(function(){
// apply declarative shadow roots
function applyDSD(){
document.querySelectorAll('template[is="shadow-root"], template[is="declarative-shadow-dom"]').forEach((templ) => {
const host = templ.parentNode;
if(!host.shadowRoot){
host.attachShadow({
mode: 'open'
});
} else {
host.shadowRoot.innerHTML = '';
}
host.shadowRoot.appendChild(document.importNode(templ.content, true));
});
}
// bound editor to the example
document.querySelector('juicy-ace-editor').addEventListener('change', (ev)=>{
document.querySelector('[shadow-host]').innerHTML = ev.target.value;
// trick Ace editor to adapt to the new content
window.dispatchEvent(new Event('resize'));
applyDSD();
});
applyDSD();
}());
</script>