-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathx-cat.html
63 lines (43 loc) · 1.27 KB
/
x-cat.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
<template>
<style>
img {
display: inline-block;
border-radius: 50%;
border: 5px solid #eee;
box-shadow: 1px 1px 1px #333;
}
</style>
<img src="http://placekitten.com/g/200/200" alt="">
</template>
<script>
(function(){
var owner = (document.currentScript || {}).ownerDocument || document,
tmpl = owner.querySelector('template'),
tmplBody = document.importNode(tmpl.content, true),
// Shadow DOM
shadow,
xCatProto = Object.create( HTMLElement.prototype, {
// API
createdCallback: {
value: function () {
var width = this.getAttribute('width') || 200,
height = this.getAttribute('height') || width;
shadow = this.createShadowRoot();
// Виджет не будет наследовать стили документа, в который
// встроен.
shadow.resetStyleInheritance = true;
shadow.appendChild(tmplBody);
this.setSizes( width, height );
}
},
setSizes: {
value: function ( width, height ) {
height = height || width;
shadow.querySelector('img').setAttribute('src', 'http://placekitten.com/g/' + width + '/' + height );
}
}
});
// register in DOM
document.registerElement('x-cat', { prototype: xCatProto });
})();
</script>