/* GF RGL Browser John J. Camilleri, 2012 */ $(document).ready(function() { // ===== State information ===== state = { index: undefined, lookup: {}, loadCount: 0, language: undefined, // lang of drop-down current: { // current file language: undefined, module: undefined, set: function(lang, module) { state.current.language = lang; state.current.module = module; }, equals: function(a, b) { if (!b) return (a == state.current.module); else return (a == state.current.language) && (b == state.current.module); } }, title: "RGL Source Browser", urlPrefix: "/", defaultLangs: ['abstract','api','common','prelude'] } ; var lookupModuleLanguage = function(module) { var l = state.lookup[module]; if (l==undefined || l.length==0) return null; else if (l.length==1) return l[0]; else { for (i in l) { if ($.inArray(l[i], state.defaultLangs)) return l[i]; } return l[0]; // no preferred default, just return first... } } var lookupAllModuleLanguages = function(module) { return state.lookup[module]; } // ===== Utility/UI functions ===== var showLoading = function(){ state.loadCount++; $("#loading").show(); } var hideLoading = function(){ state.loadCount = Math.max(state.loadCount-1, 0); if (state.loadCount == 0) $("#loading").hide(); } var scrollToTop = function() { $("html, body").animate({ scrollTop: 0 }, "slow"); } var scrollToCodeLine = function(lineNo) { showPanel("#code", function() { // Find exact line, using the classes generated by google prettify var obj = $("#code pre li.L"+(lineNo%10)+":eq("+Math.floor(lineNo/10)+")").prev(); var y = Math.max(obj.offset().top - obj.parent().offset().top - 75, 0); $("#code pre").animate({ scrollTop: y }, "slow", function(){ highlight(obj); }); }); } var highlight = function(obj) { obj.css('background-color', "yellow"); setTimeout(function(){ obj.css('background-color', ""); }, 1500); } var clearScope = function(msg) { $('#scope_list').empty(); updateScopeCount(); if (msg) { $('#scope_list').html(""+msg+""); } } var setScope = function(code) { $('#scope_list').html(code); } var clearCode = function(msg) { $('#code pre').empty(); if (msg) { $('#codes pre').html(""+msg+""); } } var setCode = function(code) { $('#code pre').text(code); prettyPrint(); } var updateScopeCount = function(){ $('#scope_count').text( $("#scope_list tr:visible").length ); } var setLanguage = function(lang){ state.language = lang; $("#languages select").val(lang); initModules(lang); } // obj can be just a plain selector or a jQuery object var showPanel = function(obj, callback){ showLoading(); setTimeout(function(){ $(".panel:visible").hide(); $(obj).show(0, callback); recalculateHeights(); updateScopeCount(); hideLoading(); }, 500); // this ensures the loading displays } var getPanel = function() { return $('.panel:visible').first(); } var setTitle = function(s){ $('#module_name').html(s); $('title').html(state.title + ": " + s); } // ===== Initialization ===== // Load the index file and populate language & module lists $.ajax({ url: "index.json", dataType: "json", type: "GET", success: function(data) { state.index = data; if (data['urlprefix']) state.urlPrefix = data['urlprefix']; // Build language lookup index for (var lang in data['languages']) { for (var i in data['languages'][lang]) { var module = data['languages'][lang][i]; if (!module) continue; if (!state.lookup[module]) state.lookup[module] = []; state.lookup[module].push(lang); } } // Initialize the language list var lang_select = $("