diff --git a/app/assets/stylesheets/player/player.css.sass b/app/assets/stylesheets/player/player.css.sass index adaa9ce..1d72597 100644 --- a/app/assets/stylesheets/player/player.css.sass +++ b/app/assets/stylesheets/player/player.css.sass @@ -18,6 +18,9 @@ $color5: #edc951 right: 0 bottom: 0 +body.iframe + background-color: transparent + .player // float: left; display: block diff --git a/app/controllers/asciicasts_controller.rb b/app/controllers/asciicasts_controller.rb index a92b81c..e895f8c 100644 --- a/app/controllers/asciicasts_controller.rb +++ b/app/controllers/asciicasts_controller.rb @@ -6,7 +6,7 @@ class AsciicastsController < ApplicationController before_filter :ensure_authenticated!, :only => [:edit, :update, :destroy] before_filter :ensure_owner!, :only => [:edit, :update, :destroy] - respond_to :html, :json + respond_to :html, :json, :js def index @asciicasts = PaginatingDecorator.new( @@ -41,6 +41,10 @@ class AsciicastsController < ApplicationController respond_with AsciicastJSONDecorator.new(@asciicast) end end + + format.js do + respond_with @asciicast + end end end diff --git a/app/views/asciicasts/raw.html.erb b/app/views/asciicasts/raw.html.erb index c2ff8c7..f8ddfa3 100644 --- a/app/views/asciicasts/raw.html.erb +++ b/app/views/asciicasts/raw.html.erb @@ -1 +1,11 @@ <%= player @asciicast %> + diff --git a/app/views/asciicasts/show.js.erb b/app/views/asciicasts/show.js.erb new file mode 100644 index 0000000..9309bb9 --- /dev/null +++ b/app/views/asciicasts/show.js.erb @@ -0,0 +1,21 @@ +// ascii.io - embeddable widget + +(function() { + function receiveSize(e) { + if (e.origin === document.location.protocol + "//<%= request.host %>") { + var event = e.data[0]; + var data = e.data[1]; + if (event == 'asciicast:size' && data.id == <%= @asciicast.id %>) { + var player = document.getElementById("asciicast-player-<%= @asciicast.id %>"); + if (player) { + player.style.width = data.width; + player.style.height = data.height; + } + } + } + } + + window.addEventListener("message", receiveSize, false); + + document.writeln('
'); +})(); diff --git a/app/views/layouts/raw.html.erb b/app/views/layouts/raw.html.erb deleted file mode 100644 index ecad73b..0000000 --- a/app/views/layouts/raw.html.erb +++ /dev/null @@ -1,25 +0,0 @@ - - - - - <%= page_title %> - - - - - <%= stylesheet_link_tag "player", :media => "all" %> - <%= javascript_include_tag "application" %> - <%= javascript_include_tag "player" %> - - - - - - <%= yield %> - - diff --git a/app/views/layouts/raw.html.slim b/app/views/layouts/raw.html.slim new file mode 100644 index 0000000..097b8e4 --- /dev/null +++ b/app/views/layouts/raw.html.slim @@ -0,0 +1,13 @@ +doctype html +html[lang="en"] + head + meta[charset="utf-8"] + title = page_title + = stylesheet_link_tag "player", :media => "all" + = javascript_include_tag "application" + = javascript_include_tag "player" + script + | window.unpackWorkerPath = '#{javascript_path "unpack_worker"}'; + window.mainWorkerPath = '#{javascript_path "main_worker"}'; + body.iframe + = yield