From baf1c96c7e9d3cdcb7811b503f7bd4f77da26596 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Sat, 1 Oct 2016 18:09:32 +0000 Subject: [PATCH] No need for jQuery inside of an iframe --- app/assets/javascripts/embed.js | 3 ++- app/helpers/asciicasts_helper.rb | 1 + app/views/api/asciicasts/show.html.slim | 11 +++++++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/embed.js b/app/assets/javascripts/embed.js index 69db0eb..00d3f70 100644 --- a/app/assets/javascripts/embed.js +++ b/app/assets/javascripts/embed.js @@ -1,2 +1,3 @@ -//= require base +//= require es5-shim.min +//= require console-shim-min //= require asciinema-player diff --git a/app/helpers/asciicasts_helper.rb b/app/helpers/asciicasts_helper.rb index 70892bf..1c39921 100644 --- a/app/helpers/asciicasts_helper.rb +++ b/app/helpers/asciicasts_helper.rb @@ -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, diff --git a/app/views/api/asciicasts/show.html.slim b/app/views/api/asciicasts/show.html.slim index 0df2e78..8918e04 100644 --- a/app/views/api/asciicasts/show.html.slim +++ b/app/views/api/asciicasts/show.html.slim @@ -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 } }