$.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'); } }); var $module_container = $('.module_container'); var _tracer = new Tracer(); var initEditor = function (id) { var editor = ace.edit(id); 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 lastDir = null; dataEditor.on('change', function () { var data = dataEditor.getValue(); if (lastDir) cachedFile[lastDir].data = data; try { eval(data); lastModule = tracer && tracer.module; _tracer = tracer; } catch (err) { } _tracer.reset(); }); codeEditor.on('change', function () { var code = codeEditor.getValue(); if (lastDir) cachedFile[lastDir].code = code; }); var cachedFile = {}; var loadFile = function (category, algorithm, file, explanation) { lastData = null; $('#explanation').html(explanation); var dir = lastDir = './algorithm/' + 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 { dataEditor.setValue(''); codeEditor.setValue(''); $.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); }); }).fail(function (jqXHR, textStatus, errorThrown) { alert("AJAX call failed: " + textStatus + ", " + errorThrown); }); } }; var loadAlgorithm = function (category, algorithm) { $('#list > button').removeClass('active'); $('[data-category="' + category + '"][data-algorithm="' + algorithm + '"]').addClass('active'); $('#btn_desc').click(); $('#category').text(list[category].name); $('#algorithm, #desc_title').text(list[category].list[algorithm]); $('#tab_desc > .wrapper').empty(); $('.files_bar').empty(); $('#explanation').html(''); lastDir = null; dataEditor.setValue(''); codeEditor.setValue(''); var dir = './algorithm/' + category + '/' + algorithm + '/'; $.getJSON(dir + 'desc.json', function (data) { var files = data.files; delete data.files; var $container = $('#tab_desc > .wrapper'); $container.empty(); for (var key in data) { if (key) $container.append($('
').html(value)); } else if (Array.isArray(value)) { var $ul = $('