diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index f94967c..1abe5c7 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -8,6 +8,7 @@ //= require jquery_ujs //= require jquery.timeago //= require bootstrap +//= require asciicasts $(function() { $('abbr.timeago').timeago(); diff --git a/app/assets/javascripts/asciicasts.js b/app/assets/javascripts/asciicasts.js new file mode 100644 index 0000000..3ac41d9 --- /dev/null +++ b/app/assets/javascripts/asciicasts.js @@ -0,0 +1,30 @@ +function createPlayer(parentNode, asciicast, options) { + asciinema.CreatePlayer( + parentNode, + asciicast.width, asciicast.height, + asciicast.stdout_frames_url, + asciicast.duration, + { + snapshot: asciicast.snapshot, + speed: options.speed, + autoPlay: options.autoPlay, + loop: options.loop, + fontSize: options.fontSize, + theme: options.theme + } + ); +} + +function tryCreatePlayer(parentNode, asciicast, options) { + if (asciicast.stdout_frames_url) { + $('.processing-info').remove(); + createPlayer(parentNode, asciicast, options); + } else { + $('.processing-info').show(); + setTimeout(function() { + $.get('/api/asciicasts/' + asciicast.id + '.json', function(data) { + tryCreatePlayer(parentNode, data, options); + }); + }, 2000); + } +} diff --git a/app/views/asciicasts/_player.html.erb b/app/views/asciicasts/_player.html.erb index 8e938b8..bd368ca 100644 --- a/app/views/asciicasts/_player.html.erb +++ b/app/views/asciicasts/_player.html.erb @@ -13,40 +13,16 @@