Skip to content

Instantly share code, notes, and snippets.

@benoror
Created March 30, 2015 18:17
Show Gist options
  • Select an option

  • Save benoror/d07aeed9afb5c56be202 to your computer and use it in GitHub Desktop.

Select an option

Save benoror/d07aeed9afb5c56be202 to your computer and use it in GitHub Desktop.
/**
* Terminal Animation snippet
* taken from:
* http://lotusrb.org/
* http://lotusrb.org/javascripts/application.js
**/
// Typing terminal animation
$(window).load(function(){
var version = $('meta[name=lotusrb-version]').attr('content');
var data = [
{
action: 'type',
strings: ['gem install lotusrb^400'],
output: '<span class="gray">Fetching: lotusrb-'+ version +'.gem (100%)<br>Succesfully installed lotusrb-'+ version +'</span><br>&nbsp;',
postDelay: 1000
},
{
action: 'type',
strings: ['lotus new bookshelf^400'],
output: '<span class="gray">21 files created successfully</span><br>&nbsp;',
postDelay: 1000
},
{
action: 'type',
strings: ['cd bookshelf && bundle^400'],
output: '<span class="gray">Bundle complete! 6 Gemfile dependencies, 25 gems now installed.</span><br>&nbsp;',
postDelay: 1000
},
{
action: 'type',
strings: ['bundle exec lotus server^400'],
output: $('.run-output').html()
},
{
action: 'type',
strings: [
'Start building!',
''
],
postDelay: 2000
}
];
runScripts(data, 0);
});
function runScripts(data, pos) {
var prompt = $('.prompt'), script = data[pos];
if (script.clear === true) {
$('.history').html('');
}
switch (script.action) {
case 'type':
prompt.removeData();
$('.typed-cursor').text('');
prompt.typed({
strings: script.strings,
typeSpeed: 30,
callback: function () {
var history = $('.history').html();
history = history ? [history] : [];
history.push('$ ' + prompt.text());
if (script.output) {
history.push(script.output);
prompt.html('');
$('.history').html(history.join('<br>'));
}
$('section.terminal').scrollTop($('section.terminal').height());
pos++;
if (pos < data.length) {
setTimeout(function () {
runScripts(data, pos);
}, script.postDelay || 1000);
}
}
});
break;
case 'view':
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment