-
Notifications
You must be signed in to change notification settings - Fork 3
/
iphone-x-view.html
105 lines (97 loc) · 3.37 KB
/
iphone-x-view.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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<link rel="import" href="../polymer/polymer-element.html">
<link rel="import" href="./device-styles.html">
<dom-module id="iphone-x-view">
<template>
<style include="device-styles">
:host {
display: block;
}
</style>
<div class$="marvel-device iphone-x {{orientation}}" hidden$="{{visible}}">
<div class="notch">
<div class="camera"></div>
<div class="speaker"></div>
</div>
<div class="top-bar"></div>
<div class="sleep"></div>
<div class="bottom-bar"></div>
<div class="volume"></div>
<div class="overflow">
<div class="shadow shadow--tr"></div>
<div class="shadow shadow--tl"></div>
<div class="shadow shadow--br"></div>
<div class="shadow shadow--bl"></div>
</div>
<div class="inner-shadow"></div>
<div class="screen" id="ixcontainer">
<!-- Content goes here -->
</div>
</div>
</template>
<script>
/**
* `iphone-x-view`
* iphone-x-view element enables you to create a responsive view inside an iframe and applying skins of different devices inculding smartphones, tablets and desktop
*
* @customElement
* @polymer
* @demo demo/index.html
*/
class IphoneXView extends Polymer.Element {
constructor() {
super();
}
static get is() {
return 'iphone-x-view';
}
static get properties() {
return {
device: {
type: String
},
visible: {
type: Boolean,
value: true
},
orientation: {
type: String,
observer: "_orChange"
},
data: {
type: Object
}
};
}
loadView(d) {
this._openScreen();
this.orientation = d.orientation
this.$.ixcontainer.innerHTML = "";
var i = document.createElement('iframe');
if (d.isUrl) {
i.src = d.url;
} else {
i.srcdoc = d.content;
}
i.width = 375;
i.height = 812;
this.$.ixcontainer.appendChild(i);
this.data = d;
}
_openScreen() {
this.visible = false;
}
_orChange(o) {
if (this.shadowRoot.querySelector('iframe') !== null) {
if (o === "portrait") {
this.shadowRoot.querySelector('iframe').width = 375;
this.shadowRoot.querySelector('iframe').height = 812;
} else {
this.shadowRoot.querySelector('iframe').width = 812;
this.shadowRoot.querySelector('iframe').height = 375;
}
}
}
}
window.customElements.define(IphoneXView.is, IphoneXView);
</script>
</dom-module>