Move JS code to .js file

element
Marcin Kulik 9 years ago
parent 49cfe584ba
commit c070430135

@ -8,6 +8,7 @@
//= require jquery_ujs
//= require jquery.timeago
//= require bootstrap
//= require asciicasts
$(function() {
$('abbr.timeago').timeago();

@ -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);
}
}

@ -13,40 +13,16 @@
<script>
$(function() {
var asciicast = <%= asciicast.to_json.gsub('</', '<\/').html_safe %>;
function createPlayer() {
asciinema.CreatePlayer(
$('.player')[0],
asciicast.width, asciicast.height,
asciicast.stdout_frames_url,
asciicast.duration,
{
snapshot: asciicast.snapshot,
speed: <%= options.speed %>,
autoPlay: <%= options.autoplay %>,
loop: <%= options.loop %>,
fontSize: '<%= options.size %>',
theme: '<%= h options.theme %>'
}
);
}
function tryCreatePlayer() {
if (asciicast.stdout_frames_url) {
$('.processing-info').remove();
createPlayer();
} else {
$('.processing-info').show();
setTimeout(function() {
$.get('/api/asciicasts/' + asciicast.id + '.json', function(data) {
asciicast = data;
tryCreatePlayer();
});
}, 2000);
tryCreatePlayer(
$('.player')[0],
<%= asciicast.to_json.gsub('</', '<\/').html_safe %>,
{
speed: <%= options.speed %>,
autoPlay: <%= options.autoplay %>,
loop: <%= options.loop %>,
fontSize: '<%= options.size %>',
theme: '<%= h options.theme %>'
}
}
tryCreatePlayer();
);
});
</script>

Loading…
Cancel
Save