-
Notifications
You must be signed in to change notification settings - Fork 0
/
tangy-code.js
88 lines (81 loc) · 1.84 KB
/
tangy-code.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
81
82
83
84
85
86
87
88
import { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
/**
* `tangy-code`
*
*
* @customElement
* @polymer
* @demo demo/index.html
*/
export class TangyCode extends PolymerElement {
static get template () {
return html`
<div id="container"></div>
`
}
static get is () {
return 'tangy-code'
}
static get properties () {
return {
name: {
type: String,
value: '',
reflectToAttribute: true
},
required: {
type: Boolean,
value: false,
reflectToAttribute: true
},
hidden: {
type: Boolean,
value: false,
observer: 'render',
reflectToAttribute: true
},
value: {
type: String,
value: ''
},
invalid: {
type: Boolean,
value: false,
reflectToAttribute: true
},
mode: {
type: String,
value: '',
observer: 'render',
reflectToAttribute: true
},
height: {
type: Number,
value: 600,
observer: 'render',
reflectToAttribute: true
}
}
}
render() {
this.$.container.innerHTML = `
<juicy-ace-editor mode="${this.mode}" style="height: ${this.height}px;">
</juicy-ace-editor>
`
this.shadowRoot.querySelector('juicy-ace-editor').value = this.innerHTML
this.value = this.innerHTML
this.shadowRoot.querySelector('juicy-ace-editor').addEventListener('change', (event) => {
this.value = event.target.value
})
}
validate() {
if (this.shadowRoot.querySelector('juicy-ace-editor').shadowRoot.querySelector('.ace_error')) {
this.invalid = true
return false
} else {
this.invalid = false
return true
}
}
}
window.customElements.define(TangyCode.is, TangyCode)