diff --git a/static/js/teleport.js b/static/js/teleport.js new file mode 100644 index 0000000..3a13810 --- /dev/null +++ b/static/js/teleport.js @@ -0,0 +1,55 @@ +(function($) { + + $(document).ready(function(){ + $('.js-teleport').click(function(e) { + $('.js-bobs-code').html('') + e.preventDefault(); + $this = $(this); + $this.hide() + $pb = $this.siblings('.progress'); + $pb.show(); + + $.post({ + url : '/api/teleportsend', + data: {'sendit' : 1 }, + success: function(response) { + load_progressbar(response); + }, + dataType: 'json' + }); + }) + }); + + function load_results(response) { + $('.js-bobs-code').html(response.program); + $('.js-bobs-wvf').html(response.wvf); + $('.js-teleport').show() + $('.progress').hide() + } + + function load_progressbar(response) { + var progressBar = $('.js-teleport-progress-bar'), + + width = 0; + progressBar.width(width); + var interval = setInterval(function() { + width += 10; + progressBar.css('width', width + '%'); + if (width >= 100) { + clearInterval(interval); + load_results(response); + } + }, 500); + + } + + function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + async function demo() { + console.log('Taking a break...'); + await sleep(2000); + console.log('Two second later'); + } +})(jQuery);