-
Notifications
You must be signed in to change notification settings - Fork 1
/
x-frame.html
106 lines (86 loc) · 2.24 KB
/
x-frame.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.html">
<dom-module id="x-frame">
<template>
<style>
:host {
}
#frame {
display: block;
}
</style>
<iframe id="frame"
src$="{{src}}"
frameborder$="{{frameborder}}"
scrolling$="{{scrolling}}"
height$="{{height}}"
width$="{{width}}">
</iframe>
</template>
<script>
/**
* Cross document communication with frame content made easy.
*
* @demo demo/index.html
*/
Polymer({
is: 'x-frame',
properties: {
/**
* `src` attribute of the nested iframe element.
*/
src: {
type: String
},
/**
* `scrolling` attribute of the nested iframe element.
*/
scrolling: {
type: String
},
/**
* `frameborder` attribute of the nested iframe element.
*/
frameborder: {
type: Number
},
/**
* `height` attribute of the nested iframe element.
*/
height: {
type: String
},
/**
* `width` attribute of the nested iframe element.
*/
width: {
type: String
}
},
ready: function () {
window && this.listen(window, 'message', '_onMessage');
},
/**
* when the "x-frame" element receives a post message from the framed window.
*
* @event msg
*/
/**
* Send a post message to the framed window.
* @param {Object} msg Object to be sent as post message.
* @param {String} channel send a message on a specific channel.
*/
send: function (msg, channel) {
channel = channel || 'default';
msg && this.$.frame.contentWindow && this.$.frame.contentWindow.postMessage({ channel: channel, message: msg }, '*');
},
/**
* Called whenever a message from the framed window is received.
* @param {Event} event The post message event.
* @private
*/
_onMessage: function (event) {
event.source === this.$.frame.contentWindow && this.fire('msg', event);
}
});
</script>
</dom-module>