No need for jQuery inside of an iframe

This commit is contained in:
Marcin Kulik 2016-10-01 18:09:32 +00:00
parent 5892b9d2d6
commit baf1c96c7e
3 changed files with 10 additions and 5 deletions

View File

@ -1,2 +1,3 @@
//= require base
//= require es5-shim.min
//= require console-shim-min
//= require asciinema-player

View File

@ -9,6 +9,7 @@ module AsciicastsHelper
def player_tag(asciicast, options, skip_titlebar)
opts = {
id: 'player',
src: asciicast.url,
cols: asciicast.width,
rows: asciicast.height,

View File

@ -4,18 +4,21 @@ p.powered
a href=root_url target="_top" asciinema
javascript:
$(function() {
var player = document.getElementById('player');
player.addEventListener('attached', function() {
var target = parent.postMessage ? parent : (parent.document.postMessage ? parent.document : undefined);
if (typeof target != "undefined" && window !== window.parent) {
var w = $('.asciinema-player').width();
var h = $(document).height();
var w = player.getElementsByClassName('asciinema-player')[0].offsetWidth;
var h = Math.max(document.body.scrollHeight, document.body.offsetHeight);
target.postMessage(['asciicast:size', { width: w, height: h }], '*');
}
function onMessage(e) {
var event = e.data[0];
if (event == 'asciicast:play') {
$('.start-prompt').click();
// player.play(); // TODO
}
}