$.ajaxSetup({cache: false, dataType: "text"}); $(document).on('click', 'a', function (e) { e.preventDefault(); if (!window.open($(this).attr('href'), '_blank')) { alert('Please allow popups for this site'); } }); $('.btn input').click(function (e) { e.stopPropagation(); }); var tm = new TracerManager(); $('#interval').on('change', function () { tm.interval = Number.parseFloat($(this).val() * 1000); showInfoToast('Tracing interval has been set to ' + tm.interval / 1000 + ' second(s).'); }); var $module_container = $('.module_container'); ace.require("ace/ext/language_tools"); var initEditor = function (id) { var editor = ace.edit(id); editor.setOptions({ enableBasicAutocompletion: true, enableSnippets: true, enableLiveAutocompletion: true }); editor.setTheme("ace/theme/tomorrow_night_eighties"); editor.session.setMode("ace/mode/javascript"); editor.$blockScrolling = Infinity; return editor; }; var dataEditor = initEditor('data'); var codeEditor = initEditor('code'); var lastFile = null; dataEditor.on('change', function () { var data = dataEditor.getValue(); if (lastFile) cachedFile[lastFile].data = data; try { tm.deallocateAll(); eval(data); tm.visualize(); } catch (err) { } finally { tm.removeUnallocated(); } }); codeEditor.on('change', function () { var code = codeEditor.getValue(); if (lastFile) cachedFile[lastFile].code = code; }); var cachedFile = {}; var loading = false; var isScratchPaper = function (category, algorithm) { return category == null && algorithm == 'scratch_paper'; }; var getAlgorithmDir = function (category, algorithm) { if (isScratchPaper(category, algorithm)) return './algorithm/scratch_paper/'; return './algorithm/' + category + '/' + algorithm + '/'; }; var getFileDir = function (category, algorithm, file) { if (isScratchPaper(category, algorithm)) return './algorithm/scratch_paper/'; return './algorithm/' + category + '/' + algorithm + '/' + file + '/'; }; var loadFile = function (category, algorithm, file, explanation) { if (checkLoading()) return; $('#explanation').html(explanation); var dir = lastFile = getFileDir(category, algorithm, file); if (cachedFile[dir] && cachedFile[dir].data !== undefined && cachedFile[dir].code !== undefined) { dataEditor.setValue(cachedFile[dir].data, -1); codeEditor.setValue(cachedFile[dir].code, -1); } else { loading = true; cachedFile[dir] = {}; dataEditor.setValue(''); codeEditor.setValue(''); var onFail = function (jqXHR, textStatus, errorThrown) { loading = false; alert("AJAX call failed: " + textStatus + ", " + errorThrown); }; $.get(dir + 'data.js', function (data) { cachedFile[dir].data = data; dataEditor.setValue(data, -1); $.get(dir + 'code.js', function (code) { cachedFile[dir].code = code; codeEditor.setValue(code, -1); loading = false; }).fail(onFail); }).fail(onFail); } }; var checkLoading = function () { if (loading) { showErrorToast('Wait until it completes loading of previous file.'); return true; } return false; }; var showDescription = function (data) { var $container = $('#tab_desc > .wrapper'); $container.empty(); for (var key in data) { if (key) $container.append($('

').html(key)); var value = data[key]; if (typeof value === "string") { $container.append($('

').html(value)); } else if (Array.isArray(value)) { var $ul = $('