-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsky-element.js
80 lines (65 loc) · 1.77 KB
/
sky-element.js
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
/*
<!--
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-->
<import src="TemplateBinding.sky" />
<script>
*/
var templates = new Map();
function createPrototype(proto, definition) {
var result = Object.create(proto);
var names = Object.getOwnPropertyNames(definition);
for (var i = 0; i < names.length; ++i) {
var descriptor = Object.getOwnPropertyDescriptor(definition, names[i]);
Object.defineProperty(result, names[i], descriptor);
}
return result;
}
var BasePrototype = createPrototype(HTMLElement.prototype, {
createdCallback: function() {
this.created();
},
created: function() {
// override
},
attachedCallback: function() {
if (!this.shadowRoot) {
var template = templates.get(this.localName);
if (template) {
var shadow = this.createShadowRoot();
shadow.appendChild(template.createInstance(this));
}
}
this.attached();
},
attached: function() {
// override
},
dettachedCallback: function() {
this.dettached();
},
dettached: function() {
// override
},
attributeChangedCallback: function(attrName, oldValue, newValue) {
// reserved for canonical behavior
this.attributeChanged(attrName, oldValue, newValue);
},
attributeChanged: function(attrName, oldValue, newValue) {
// override
}
});
function SkyElement(prototype) {
var template = document.currentScript.previousElementSibling;
if (template && template.localName === 'template')
templates.set(prototype.name, template);
document.registerElement(prototype.name, {
prototype: createPrototype(BasePrototype, prototype),
});
};
/*
module.exports = SkyElement;
</script>
*/