This repository has been archived by the owner on Jul 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gist_embed.html
76 lines (71 loc) · 3.24 KB
/
gist_embed.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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Modular GitHub Gist Embeds</title>
</head>
<body>
<div id="gist_embed"></div>
<script data-cfasync="false">
/* @source http://purl.eligrey.com/github/async-document-write/blob/master/async-document-write.js*/
(function(){try{0()}catch(u){var f=u}var q="fileName",j="stack",s=j+"trace";if(q in f||s in f||j in f){var v=document,k=v.createElement("a"),l=!1,h=!l,g=[],i=v.write,b=function(e){return v.getElementsByTagName(e)},d=b("head")[0],t,m=function(){if(h){h=l;var w=t.to,x=0,e=g.length;for(;x<e;x++){t.to=g[x++];t(g[x]);delete t.to}g=null;t.to=w}},o=function(e){var x,w=function(y,z){x=z};if(q in e){x=e[q]}else{if(s in e){e[s].replace(/Line \d+ of .+ script (.*)/gm,w)}else{if(j in e){e[j].replace(/at (.*)/gm,w);x=x.replace(/:\d+:\d+$/,"")}}}return x},p=Array.prototype.slice,a=Object.prototype.toString,n,r,c;if(v.addEventListener&&v.removeEventListener){n=v.addEventListener;r=v.removeEventListener;c=function(e){r.call(v,e.type,c,l);m()};n.call(v,"DOMContentLoaded",c,l);n.call(v,"load",c,l)}else{if(v.attachEvent&&v.detachEvent){n=v.attachEvent;r=v.detachEvent;c=function(){r.call(v,"onload",c)};n.call(v,"onload",c)}}t=v.write=function(){var D=p.call(arguments).join(""),z=b("body")[0],E=t.to;if(!z){g.push(E,D);return}if(E){k.href=o(E);var e=k.href,x=b("script"),w=v.createElement("span");w.innerHTML=D;for(var B=0,A=x.length;B<A;B++){k.href=x.item(B).src;if(k.href===e){var y=x.item(B),C=y;while(C=C.parentNode){if(C===d){z.insertBefore(w,z.firstChild);return}}y.parentNode.insertBefore(w,y);return}}}else{i.apply(v,arguments)}};v.writeln=function(){t.apply(this,p.call(arguments).concat("\n"))};t.START="try{0()}catch(e){document.write.to=e}";t.END="delete document.write.to"}}());
</script>
<script>
function receiveMessage(event){
if (event.data) {
var msg;
try {
msg = JSON.parse(event.data);
} catch (err) {
// Do nothing
}
if (!msg)
return false;
if (msg.name === 'resize') {
window.parent.postMessage({
sentinel: 'amp',
type: 'embed-size',
height: document.body.scrollHeight
}, '*');
}
}
}
window.addEventListener('message', receiveMessage, false);
</script>
<script data-cfasync="false">
eval(document.write.START);
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split('&');
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){
return pair[1];
}
}
return(false);
}
(function() {
var d = document, s = d.createElement('script');
var id = getQueryVariable("id");
var fName = getQueryVariable("fileName");
var mySrc = 'https://gist.github.com/' + id + '.js';
if( fName != '' ){
mySrc += '?file=' + fName;
}
s.src = mySrc;
s.type = 'text/javascript';
document.getElementById('gist_embed').appendChild(s);
window.setTimeout(function(){
var val = document.body.scrollHeight;
console.log('should reset iframe height to ' + val);
window.parent.postMessage({
sentinel: 'amp',
type: 'embed-size',
height: val
}, '*');
}, 500);
})();
</script>
</body>
</html>