This repository has been archived by the owner on Jul 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
hello-world.html
61 lines (52 loc) · 1.74 KB
/
hello-world.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
<!-- Imports x-tag -->
<script src="../x-tag-core/src/core.js"></script>
<!-- Defines element markup -->
<template>
<p>Hello <strong></strong> :)</p>
</template>
<script>
(function(window, document, undefined) {
// Refers to the "importer", which is index.html
var thatDoc = document;
// Refers to the "importee", which is src/hello-world.html
var thisDoc = document._currentScript.ownerDocument;
// Gets content from <template>
var template = thisDoc.querySelector('template').content;
xtag.register('hello-world', {
lifecycle: {
created: function() {
// Caches <strong> DOM query
this.strong = template.querySelector('strong');
// Creates the shadow root
this.shadowRoot = this.createShadowRoot();
this.uiSetWho();
},
attributeChanged: function() {
this.uiSetWho();
}
},
accessors: {
who: {
attribute: {},
get: function(){
return this.getAttribute('who') || "World"
},
set: function(value){
this.xtag.data.who = value;
}
}
},
methods: {
uiSetWho: function() {
// Sets "who" value into <strong>
this.strong.textContent = this.who;
// Removes shadow root content
this.shadowRoot.innerHTML = '';
// Adds a template clone into shadow root
var clone = thatDoc.importNode(template, true);
this.shadowRoot.appendChild(clone);
}
}
});
})(window, document);
</script>