From 466a21a7e8b53c815022a1f77c68decd7605665c Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Fri, 20 Nov 2015 10:00:41 +0000 Subject: [PATCH] Fix the size of the embed widget when embedding public recording via private URL --- app/assets/javascripts/widget.js | 6 ++++-- app/presenters/bare_asciicast_page_presenter.rb | 4 ---- app/views/api/asciicasts/show.html.slim | 2 +- app/views/asciicasts/example.html.slim | 2 +- spec/presenters/bare_asciicast_page_presenter_spec.rb | 9 --------- 5 files changed, 6 insertions(+), 17 deletions(-) diff --git a/app/assets/javascripts/widget.js b/app/assets/javascripts/widget.js index 4c916fc..93db347 100644 --- a/app/assets/javascripts/widget.js +++ b/app/assets/javascripts/widget.js @@ -70,9 +70,11 @@ function receiveSize(e) { if (e.origin === apiHost) { - var event = e.data[0]; + var name = e.data[0]; var data = e.data[1]; - if (event == 'asciicast:size' && data.id == asciicastId) { + var iframeWindow = iframe.contentWindow || iframe; + + if (e.source == iframeWindow && name == 'asciicast:size') { iframe.style.width = '' + data.width + 'px'; iframe.style.height = '' + data.height + 'px'; } diff --git a/app/presenters/bare_asciicast_page_presenter.rb b/app/presenters/bare_asciicast_page_presenter.rb index 0cc313a..d53e425 100644 --- a/app/presenters/bare_asciicast_page_presenter.rb +++ b/app/presenters/bare_asciicast_page_presenter.rb @@ -17,8 +17,4 @@ class BareAsciicastPagePresenter @playback_options = playback_options end - def asciicast_id - asciicast.to_param - end - end diff --git a/app/views/api/asciicasts/show.html.slim b/app/views/api/asciicasts/show.html.slim index 1cff2e9..0df2e78 100644 --- a/app/views/api/asciicasts/show.html.slim +++ b/app/views/api/asciicasts/show.html.slim @@ -9,7 +9,7 @@ javascript: if (typeof target != "undefined" && window !== window.parent) { var w = $('.asciinema-player').width(); var h = $(document).height(); - target.postMessage(['asciicast:size', { id: '#{page.asciicast_id}', width: w, height: h }], '*'); + target.postMessage(['asciicast:size', { width: w, height: h }], '*'); } function onMessage(e) { diff --git a/app/views/asciicasts/example.html.slim b/app/views/asciicasts/example.html.slim index 34fd9a1..3b5a789 100644 --- a/app/views/asciicasts/example.html.slim +++ b/app/views/asciicasts/example.html.slim @@ -10,7 +10,7 @@ p p ' And now again. There should be an embedded player below this paragraph. -= embed_script(@asciicast).html_safe += embed_script(Asciicast.where('id <> ?', @asciicast.id).first || @asciicast).html_safe p ' This is at the bottom of the page, below all players. diff --git a/spec/presenters/bare_asciicast_page_presenter_spec.rb b/spec/presenters/bare_asciicast_page_presenter_spec.rb index b487726..e53d6b9 100644 --- a/spec/presenters/bare_asciicast_page_presenter_spec.rb +++ b/spec/presenters/bare_asciicast_page_presenter_spec.rb @@ -19,13 +19,4 @@ describe BareAsciicastPagePresenter do end end - let(:presenter) { described_class.new(asciicast, nil) } - let(:asciicast) { stub_model(Asciicast, id: 123) } - - describe '#asciicast_id' do - subject { presenter.asciicast_id } - - it { should eq('123') } - end - end