-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpnsk-structured-editor-iframe.html
More file actions
90 lines (76 loc) · 2.65 KB
/
pnsk-structured-editor-iframe.html
File metadata and controls
90 lines (76 loc) · 2.65 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
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
89
90
<link rel="import" href="../polymer/polymer-micro.html">
<style>
pnsk-structured-editor-iframe .preview {
background-color: white;
margin-bottom: 12px;
padding: 8px;
display: none;
}
</style>
<template id="pnsk-structured-editor-iframe" noshadowroot>
<div class="preview"></div>
<span class="inputswrapper">
<label>
URL
<input class="url" type="url">
</label>
<label>
Height
<input class="height" type="text">
</label>
</span>
<content></content>
</template>
<script>
Polymer({
is: 'pnsk-structured-editor-iframe',
behaviors: [MinimalComponent],
template: currentImport.querySelector('#pnsk-structured-editor-iframe'),
dataType: "iframe",
getState: function () {
return {
'url': this.qs(".url").value,
'height': this.qs(".height").value,
};
},
setState: function (state) {
this.qs(".url").value = state.url;
this.qs(".height").value = state.height;
this._updatePreview();
},
_onChange: function () {
var event = new Event('pnsk-component-stateChanged');
this.dispatchEvent(event);
this._updatePreview();
},
_updatePreview: function () {
var iframe;
var plc = this.qs(".preview");
var src = this.qs(".url").value;
var height = this.qs(".height").value
if (iframe = plc.querySelector("iframe")) {
// Don't flash iframe changes all the time
if (iframe.src != src) {
iframe.src = src;
}
} else {
iframe = document.createElement("iframe");
iframe.src = src;
iframe.style.width = "100%";
iframe.frameBorder = 0;
iframe.marginWidth = 0;
iframe.marginHeight = 0;
plc.appendChild(iframe);
plc.style.display = "block";
}
iframe.style.height = height + "px";
},
// Element Lifecycle
created: function () {
this.qs(".inputswrapper").addEventListener("change", this._onChange.bind(this));
this.qs(".inputswrapper").addEventListener("keyup", this._onChange.bind(this));
this.qs(".inputswrapper").addEventListener("paste", this._onChange.bind(this));
this.qs(".inputswrapper").addEventListener("cut", this._onChange.bind(this));
},
});
</script>