2013-09-22 12:07:42 +00:00
|
|
|
// asciinema.org - embeddable player
|
2013-06-12 19:33:30 +00:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
function receiveSize(e) {
|
2013-10-12 13:48:57 +00:00
|
|
|
if (e.origin === document.location.protocol + "//<%= request.host_with_port %>") {
|
2013-06-12 19:33:30 +00:00
|
|
|
var event = e.data[0];
|
|
|
|
var data = e.data[1];
|
|
|
|
if (event == 'asciicast:size' && data.id == <%= @asciicast.id %>) {
|
2013-06-12 20:47:39 +00:00
|
|
|
var player = document.getElementById("asciicast-iframe-<%= @asciicast.id %>");
|
2013-06-12 19:33:30 +00:00
|
|
|
if (player) {
|
|
|
|
player.style.width = data.width;
|
|
|
|
player.style.height = data.height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-12 20:47:39 +00:00
|
|
|
function insertAfter(referenceNode, newNode) {
|
|
|
|
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
|
|
|
|
}
|
|
|
|
|
|
|
|
var scriptTag = document.getElementById("asciicast-<%= @asciicast.id %>");
|
2013-06-12 21:50:31 +00:00
|
|
|
|
2013-06-12 20:47:39 +00:00
|
|
|
if (scriptTag) {
|
2013-06-12 21:50:31 +00:00
|
|
|
window.addEventListener("message", receiveSize, false);
|
2013-06-12 20:47:39 +00:00
|
|
|
var container = document.createElement('div');
|
|
|
|
container.className = 'asciicast';
|
|
|
|
container.style.display = 'block';
|
|
|
|
container.style.float = 'none';
|
|
|
|
container.style.overflow = 'hidden';
|
2013-06-12 21:50:31 +00:00
|
|
|
container.style.padding = '0';
|
2013-06-12 20:47:39 +00:00
|
|
|
insertAfter(scriptTag, container);
|
2013-10-12 13:48:51 +00:00
|
|
|
var params = 'container_width=' + container.offsetWidth;
|
|
|
|
var size = scriptTag.getAttribute('data-size');
|
|
|
|
if (size) {
|
|
|
|
params += '&size=' + size;
|
|
|
|
}
|
|
|
|
container.innerHTML = '<iframe src="http://<%= request.host_with_port %>/a/<%= @asciicast.id %>/raw?' + params + '" name="asciicast-iframe-<%= @asciicast.id %>" id="asciicast-iframe-<%= @asciicast.id %>" width="300" height="300" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" style="display: block; float: none; visibility: hidden;" onload="this.style.visibility=\'visible\';"></iframe>';
|
2013-06-12 20:47:39 +00:00
|
|
|
}
|
2013-06-12 19:33:30 +00:00
|
|
|
})();
|