-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparent.js
91 lines (86 loc) · 2.23 KB
/
parent.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
89
90
91
(function() {
var el, iframe, i, script, messageHandler, element, container, options, xdomain,
resize = window.IframeResize = {};
id = 'iframe-4ee0adbddd0ca',
props = {
src : '',
width : '100%',
style : 'padding: 0; margin: 0; border: none; display: block; height: 0; overflow: hidden;',
scrolling : 'no',
frameBorder : 0,
id : id
},
ie = navigator.userAgent.toLowerCase().indexOf('msie') > -1,
// Sets the height of the iframe
setHeight = function (height) {
document.getElementById(id).style.height = height + 'px';
},
// Handler when window.postMessage is available
messageHandler = function (e) {
var height, r,
regex = new RegExp(xdomain + '$'),
matches = e.origin.match(regex);
if(matches.length == 1){
strD = e.data + "";
r = strD.match(/^(\d+)(s?)$/);
if(r && r.length == 3){
height = parseInt(r[1]);
if (!isNaN(height)) {
try {
setHeight(height);
} catch (ex) {}
}
if(r[2] == "s"){
scroll(0,0);
}
}
}
},
// Sets the default values then overrides
setProps = function (options) {
for (i in props) {
try {
var prop = (props[i] == options[i] || typeof(options[i]) == "undefined")? props[i] : options[i];
if (i !== 'style') {
iframe[i] = prop;
} else {
iframe[i].cssText = prop;
}
} catch (ex) {}
}
},
setup = function(options) {
options = options || {};
xdomain = options.domain || '*';
element = options.element || 'iframe-embed';
container = document.getElementById(element);
el = !ie ? 'iframe' : '<iframe name="' + element + '"></iframe>';
iframe = document.createElement(el);
setProps(options);
};
resize.load = function (options){
setup(options);
if(!container) return;
try {
container.appendChild(iframe);
if (window.postMessage) {
if (window.addEventListener) {
window.addEventListener('message', messageHandler, false);
} else if (window.attachEvent) {
window.attachEvent('onmessage', messageHandler);
}
} else {
setInterval(function () {
var hash = window.location.hash,
matches = hash.match(/^#h(\d+)(s?)$/);
if (matches) {
setHeight(matches[1]);
if(matches[2] == 's'){
scroll(0,0);
}
}
}, 150);
}
} catch (ey) {}
}
})();