-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpnsk-structured-editor-javascript.html
More file actions
56 lines (41 loc) · 1.68 KB
/
pnsk-structured-editor-javascript.html
File metadata and controls
56 lines (41 loc) · 1.68 KB
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
<link rel="import" href="../polymer/polymer-micro.html">
<template id="pnsk-structured-editor-javascript" noshadowroot>
<textarea rows="3" cols="30" class="scriptbox"></textarea>
<content></content>
</template>
<script>
Polymer({
is: 'pnsk-structured-editor-javascript',
behaviors: [MinimalComponent],
template: currentImport.querySelector('#pnsk-structured-editor-javascript'),
dataType: "javascript",
getState: function () {
return this.root.querySelector(".scriptbox").value;
},
setState: function (state) {
this.root.querySelector(".scriptbox").value = state;
},
_onChange: function () {
var event = new Event('pnsk-component-stateChanged');
this.dispatchEvent(event);
this.updateHeight();
},
updateHeight: function () {
var textBox = this.qs("textarea");
if (textBox.clientHeight == textBox.scrollHeight) {
textBox.style.height = "auto";
}
textBox.style.height = textBox.scrollHeight + 'px'
},
// Element Lifecycle
created: function () {
this.root.querySelector(".scriptbox").addEventListener("change", this._onChange.bind(this));
this.root.querySelector(".scriptbox").addEventListener("keyup", this._onChange.bind(this));
this.root.querySelector(".scriptbox").addEventListener("paste", this._onChange.bind(this));
this.root.querySelector(".scriptbox").addEventListener("cut", this._onChange.bind(this));
},
attached: function () {
this.updateHeight();
}
});
</script>