diff --git a/app/helpers/asciicasts_helper.rb b/app/helpers/asciicasts_helper.rb index 9300274..0fd5d6d 100644 --- a/app/helpers/asciicasts_helper.rb +++ b/app/helpers/asciicasts_helper.rb @@ -1,15 +1,10 @@ module AsciicastsHelper - def player_script_tag(asciicast, options = {}) - speed = (options[:speed] || 1).to_f - benchmark = !!params[:bm] - auto_play = options.key?(:auto_play) ? !!options[:auto_play] : false - hud = options.key?(:hud) ? !!options[:hud] : true - + def player(asciicast, options = {}) if params[:fallback] - klass = "AsciiIo.FallbackPlayer" + player_class = "AsciiIo.FallbackPlayer" else - klass = "window.Worker && $.browser.webkit ? " \ + player_class = "window.Worker && $.browser.webkit ? " \ "AsciiIo.Player : AsciiIo.FallbackPlayer" end @@ -19,24 +14,17 @@ module AsciicastsHelper renderer_class = "AsciiIo.Renderer.Pre" end - return < - $(function() { - var playerClass = #{klass}; - window.player = new playerClass({ - el: $('.player'), - cols: #{asciicast.terminal_columns}, - lines: #{asciicast.terminal_lines}, - speed: #{speed}, - benchmark: #{benchmark}, - model: new AsciiIo.Asciicast({ id: #{asciicast.id} }), - rendererClass: #{renderer_class}, - autoPlay: #{auto_play}, - hud: #{hud}, - snapshot: "#{j asciicast.snapshot.to_s}" - }); - }); - -EOS + render :partial => 'asciicasts/player', :locals => { + player_class: player_class, + cols: asciicast.terminal_columns, + lines: asciicast.terminal_lines, + speed: (options[:speed] || params[:speed] || 1).to_f, + benchmark: !!params[:bm], + asciicast_id: asciicast.id, + renderer_class: renderer_class, + auto_play: options.key?(:auto_play) ? !!options[:auto_play] : false, + hud: options.key?(:hud) ? !!options[:hud] : true, + snapshot: asciicast.snapshot + } end end diff --git a/app/views/asciicasts/_player.html.erb b/app/views/asciicasts/_player.html.erb index 9c02a4e..4bad1ff 100644 --- a/app/views/asciicasts/_player.html.erb +++ b/app/views/asciicasts/_player.html.erb @@ -1,5 +1,18 @@
-<%= player_script_tag(asciicast, - :speed => local_assigns[:speed], - :hud => local_assigns[:hud] -) %> + diff --git a/app/views/asciicasts/show.html.erb b/app/views/asciicasts/show.html.erb index 7b34250..f270842 100644 --- a/app/views/asciicasts/show.html.erb +++ b/app/views/asciicasts/show.html.erb @@ -1,11 +1,6 @@
- <%= render :partial => 'asciicasts/player', :locals => { - :asciicast => @asciicast, - :speed => params[:speed], - :hud => true - } %> - + <%= player @asciicast %>
diff --git a/app/views/home/show.html.erb b/app/views/home/show.html.erb index b97899f..53a5675 100644 --- a/app/views/home/show.html.erb +++ b/app/views/home/show.html.erb @@ -18,11 +18,7 @@
<% if @asciicast -%> - <%= render :partial => 'asciicasts/player', :locals => { - :asciicast => @asciicast, - :speed => 2.0, - :hud => false - } %> + <%= player @asciicast, :speed => 2.0, :hud => false %> <% end -%>