mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 03:32:51 -06:00
RGL Browser: fix issue with jumping to code locations
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
GF RGL Browser
|
GF RGL Browser
|
||||||
John J. Camilleri, 2012
|
John J. Camilleri, 2013
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var thing = null;
|
var thing = null;
|
||||||
@@ -22,11 +22,11 @@ $(document).ready(function(){
|
|||||||
|
|
||||||
if (thing.state.current.equals(lang, module)) {
|
if (thing.state.current.equals(lang, module)) {
|
||||||
if (parseLineNo) {
|
if (parseLineNo) {
|
||||||
scrollToCodeLine(parseInt(parseLineNo[1]));
|
thing.scrollToCodeLine(parseInt(parseLineNo[1]));
|
||||||
}
|
}
|
||||||
// else there's nothing to do!
|
// else there's nothing to do!
|
||||||
} else {
|
} else {
|
||||||
if (parseLineNo != null)
|
if (parseLineNo != undefined)
|
||||||
thing.loadFile(lang, module, parseInt(parseLineNo[1]));
|
thing.loadFile(lang, module, parseInt(parseLineNo[1]));
|
||||||
else
|
else
|
||||||
thing.loadFile(lang, module);
|
thing.loadFile(lang, module);
|
||||||
@@ -63,7 +63,7 @@ function Thing() {
|
|||||||
defaultLangs: ['abstract','api','common','prelude']
|
defaultLangs: ['abstract','api','common','prelude']
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
var lookupModuleLanguage = function(module) {
|
this.lookupModuleLanguage = function(module) {
|
||||||
var l = t.state.lookup[module];
|
var l = t.state.lookup[module];
|
||||||
if (l==undefined || l.length==0)
|
if (l==undefined || l.length==0)
|
||||||
return null;
|
return null;
|
||||||
@@ -77,90 +77,92 @@ function Thing() {
|
|||||||
return l[0]; // no preferred default, just return first...
|
return l[0]; // no preferred default, just return first...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var lookupAllModuleLanguages = function(module) {
|
this.lookupAllModuleLanguages = function(module) {
|
||||||
return t.state.lookup[module];
|
return t.state.lookup[module];
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== Utility/UI functions =====
|
// ===== Utility/UI functions =====
|
||||||
|
|
||||||
var showLoading = function(){
|
this.showLoading = function(){
|
||||||
t.state.loadCount++;
|
t.state.loadCount++;
|
||||||
$("#loading").show();
|
$("#loading").show();
|
||||||
}
|
}
|
||||||
var hideLoading = function(){
|
this.hideLoading = function(){
|
||||||
t.state.loadCount = Math.max(t.state.loadCount-1, 0);
|
t.state.loadCount = Math.max(t.state.loadCount-1, 0);
|
||||||
if (t.state.loadCount == 0)
|
if (t.state.loadCount == 0)
|
||||||
$("#loading").hide();
|
$("#loading").hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
var scrollToTop = function() {
|
this.scrollToTop = function() {
|
||||||
$("html, body").animate({ scrollTop: 0 }, "slow");
|
$("html, body").animate({ scrollTop: 0 }, "slow");
|
||||||
}
|
}
|
||||||
var scrollToCodeLine = function(lineNo) {
|
this.scrollToCodeLine = function(lineNo) {
|
||||||
showPanel("#code", function() {
|
t.showPanel("#code", function() {
|
||||||
// Find exact line, using the classes generated by google prettify
|
// Find exact line, using the classes generated by google prettify
|
||||||
var obj = $("#code pre li.L"+(lineNo%10)+":eq("+Math.floor(lineNo/10)+")").prev();
|
try {
|
||||||
var y = Math.max(obj.offset().top - obj.parent().offset().top - 75, 0);
|
var obj = $("#code pre li.L"+(lineNo%10)+":eq("+Math.floor(lineNo/10)+")").prev();
|
||||||
$("#code pre").animate({ scrollTop: y }, "slow", function(){
|
var y = Math.max(obj.offset().top - obj.parent().offset().top - 75, 0);
|
||||||
highlight(obj);
|
$("#code pre").animate({ scrollTop: y }, "slow", function(){
|
||||||
});
|
t.highlight(obj);
|
||||||
|
});
|
||||||
|
} catch (e) {}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
var highlight = function(obj) {
|
this.highlight = function(obj) {
|
||||||
obj.css('background-color', "yellow");
|
obj.css('background-color', "yellow");
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
obj.css('background-color', "");
|
obj.css('background-color', "");
|
||||||
}, 1500);
|
}, 1500);
|
||||||
}
|
}
|
||||||
|
|
||||||
var clearScope = function(msg) {
|
this.clearScope = function(msg) {
|
||||||
$('#scope #results').empty();
|
$('#scope #results').empty();
|
||||||
updateScopeCount();
|
t.updateScopeCount();
|
||||||
if (msg) {
|
if (msg) {
|
||||||
$('#scope #results').html("<em>"+msg+"</em>");
|
$('#scope #results').html("<em>"+msg+"</em>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var setScope = function(code) {
|
this.setScope = function(code) {
|
||||||
$('#scope #results').html(code);
|
$('#scope #results').html(code);
|
||||||
}
|
}
|
||||||
var clearCode = function(msg) {
|
this.clearCode = function(msg) {
|
||||||
$('#code pre').empty();
|
$('#code pre').empty();
|
||||||
if (msg) {
|
if (msg) {
|
||||||
$('#codes pre').html("<em>"+msg+"</em>");
|
$('#codes pre').html("<em>"+msg+"</em>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var setCode = function(code) {
|
this.setCode = function(code) {
|
||||||
$('#code pre').text(code);
|
$('#code pre').text(code);
|
||||||
prettyPrint();
|
prettyPrint();
|
||||||
}
|
}
|
||||||
var updateScopeCount = function(){
|
this.updateScopeCount = function(){
|
||||||
$('#scope #count').text( $("#scope #results tr:visible").length );
|
$('#scope #count').text( $("#scope #results tr:visible").length );
|
||||||
}
|
}
|
||||||
var updateAPICount = function(){
|
this.updateAPICount = function(){
|
||||||
$('#api #count').text( $("#api #results tr:visible").length );
|
$('#api #count').text( $("#api #results tr:visible").length );
|
||||||
}
|
}
|
||||||
|
|
||||||
var setLanguage = function(lang){
|
this.setLanguage = function(lang){
|
||||||
t.state.language = lang;
|
t.state.language = lang;
|
||||||
$("#languages select").val(lang);
|
$("#languages select").val(lang);
|
||||||
initModules(lang);
|
t.initModules(lang);
|
||||||
}
|
}
|
||||||
|
|
||||||
// obj can be just a plain selector or a jQuery object
|
// obj can be just a plain selector or a jQuery object
|
||||||
this.showPanel = function(obj, callback){
|
this.showPanel = function(obj, callback){
|
||||||
showLoading();
|
t.showLoading();
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
$(".panel:visible").hide();
|
$(".panel:visible").hide();
|
||||||
$(obj).show(0, callback);
|
$(obj).show(0, callback);
|
||||||
updateScopeCount();
|
t.updateScopeCount();
|
||||||
hideLoading();
|
t.hideLoading();
|
||||||
}, 500); // this ensures the loading displays
|
}, 500); // this ensures the loading displays
|
||||||
}
|
}
|
||||||
var getPanel = function() {
|
this.getPanel = function() {
|
||||||
return $('.panel:visible').first();
|
return $('.panel:visible').first();
|
||||||
}
|
}
|
||||||
|
|
||||||
var setTitle = function(s){
|
this.setTitle = function(s){
|
||||||
$('#module_name').html(s);
|
$('#module_name').html(s);
|
||||||
$('title').html(t.state.title + ": " + s);
|
$('title').html(t.state.title + ": " + s);
|
||||||
}
|
}
|
||||||
@@ -199,7 +201,7 @@ function Thing() {
|
|||||||
var lang_select = $("<select>")
|
var lang_select = $("<select>")
|
||||||
.attr('id', 'language_select')
|
.attr('id', 'language_select')
|
||||||
.change(function(){
|
.change(function(){
|
||||||
setLanguage($(this).val());
|
t.setLanguage($(this).val());
|
||||||
})
|
})
|
||||||
.appendTo("#languages")
|
.appendTo("#languages")
|
||||||
var language_list = data['languages'];
|
var language_list = data['languages'];
|
||||||
@@ -210,16 +212,16 @@ function Thing() {
|
|||||||
.html(lang)
|
.html(lang)
|
||||||
.appendTo(lang_select);
|
.appendTo(lang_select);
|
||||||
}
|
}
|
||||||
setLanguage("english");
|
t.setLanguage("english");
|
||||||
|
|
||||||
// Initialize API results
|
// Initialize API results
|
||||||
initAPI();
|
t.initAPI();
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
hideLoading();
|
t.hideLoading();
|
||||||
},
|
},
|
||||||
error: function(){
|
error: function(){
|
||||||
hideLoading();
|
t.hideLoading();
|
||||||
alert("Error getting index. Try reloading page, or just give up.");
|
alert("Error getting index. Try reloading page, or just give up.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -228,7 +230,7 @@ function Thing() {
|
|||||||
// ===== Loading functionality =====
|
// ===== Loading functionality =====
|
||||||
|
|
||||||
// Initialize the module list
|
// Initialize the module list
|
||||||
var initModules = function(lang){
|
this.initModules = function(lang){
|
||||||
t.state.index['languages'][lang] = t.state.index['languages'][lang].sort();
|
t.state.index['languages'][lang] = t.state.index['languages'][lang].sort();
|
||||||
$("#modules").empty();
|
$("#modules").empty();
|
||||||
for (var i in t.state.index['languages'][lang]) {
|
for (var i in t.state.index['languages'][lang]) {
|
||||||
@@ -243,16 +245,16 @@ function Thing() {
|
|||||||
|
|
||||||
// Load both scope & source for a file
|
// Load both scope & source for a file
|
||||||
this.loadFile = function(lang, module, lineNo){
|
this.loadFile = function(lang, module, lineNo){
|
||||||
setTitle(lang+"/"+module);
|
t.setTitle(lang+"/"+module);
|
||||||
t.state.current.set(lang, module);
|
t.state.current.set(lang, module);
|
||||||
loadTagsFile(module);
|
t.loadTagsFile(module);
|
||||||
loadSourceFile(lang, module, lineNo);
|
t.loadSourceFile(lang, module, lineNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load a tags file
|
// Load a tags file
|
||||||
var loadTagsFile = function(module) {
|
this.loadTagsFile = function(module) {
|
||||||
clearScope();
|
t.clearScope();
|
||||||
showLoading();
|
t.showLoading();
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "tags/"+module+".gf-tags",
|
url: "tags/"+module+".gf-tags",
|
||||||
type: "GET",
|
type: "GET",
|
||||||
@@ -262,7 +264,7 @@ function Thing() {
|
|||||||
var s = d.split("\t");
|
var s = d.split("\t");
|
||||||
if (c == "indir") {
|
if (c == "indir") {
|
||||||
var module = s[2].substring(s[2].lastIndexOf('/')+1, s[2].lastIndexOf('.'));
|
var module = s[2].substring(s[2].lastIndexOf('/')+1, s[2].lastIndexOf('.'));
|
||||||
var lang = lookupModuleLanguage(module);
|
var lang = t.lookupModuleLanguage(module);
|
||||||
var name = lang+"/"+module;
|
var name = lang+"/"+module;
|
||||||
var url = "#"+lang+"/"+module;
|
var url = "#"+lang+"/"+module;
|
||||||
var anchor = '<a href="'+url+'">'+name+'</a>';
|
var anchor = '<a href="'+url+'">'+name+'</a>';
|
||||||
@@ -275,41 +277,41 @@ function Thing() {
|
|||||||
return '<tr class="local" name="'+b+'"><th>'+b+'</th><td>'+c+'</td><td></td><td></td><td>'+anchor+'</td><td>'+s[1]+'</td></tr>'
|
return '<tr class="local" name="'+b+'"><th>'+b+'</th><td>'+c+'</td><td></td><td></td><td>'+anchor+'</td><td>'+s[1]+'</td></tr>'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
setScope(data);
|
t.setScope(data);
|
||||||
runFilter();
|
t.runFilter();
|
||||||
hideLoading();
|
t.hideLoading();
|
||||||
},
|
},
|
||||||
error: function(data){
|
error: function(data){
|
||||||
clearScope("No scope available");
|
t.clearScope("No scope available");
|
||||||
hideLoading();
|
t.hideLoading();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load a source module
|
// Load a source module
|
||||||
var loadSourceFile = function(lang, module, lineNo) {
|
this.loadSourceFile = function(lang, module, lineNo) {
|
||||||
clearCode();
|
t.clearCode();
|
||||||
showLoading();
|
t.showLoading();
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: t.state.urlPrefix + "lib/src/"+lang+"/"+module+".gf",
|
url: t.state.urlPrefix + "lib/src/"+lang+"/"+module+".gf",
|
||||||
type: "GET",
|
type: "GET",
|
||||||
dataType: "text",
|
dataType: "text",
|
||||||
success: function(data, status, xhr){
|
success: function(data, status, xhr){
|
||||||
setCode(data);
|
t.setCode(data);
|
||||||
hideLoading();
|
t.hideLoading();
|
||||||
if (lineNo) {
|
if (lineNo) {
|
||||||
scrollToCodeLine(lineNo);
|
t.scrollToCodeLine(lineNo);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function(data){
|
error: function(data){
|
||||||
clearCode("No code available");
|
t.clearCode("No code available");
|
||||||
hideLoading();
|
t.hideLoading();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Which modules do we include for API?
|
// Which modules do we include for API?
|
||||||
var apiModules = [
|
this.apiModules = [
|
||||||
// api
|
// api
|
||||||
"Constructors",
|
"Constructors",
|
||||||
// abstract
|
// abstract
|
||||||
@@ -339,11 +341,11 @@ function Thing() {
|
|||||||
"Transfer",
|
"Transfer",
|
||||||
"Verb",
|
"Verb",
|
||||||
];
|
];
|
||||||
var initAPI = function() {
|
this.initAPI = function() {
|
||||||
showLoading();
|
t.showLoading();
|
||||||
$('#api #results').empty();
|
$('#api #results').empty();
|
||||||
for (var i in apiModules) {
|
for (var i in t.apiModules) {
|
||||||
var module = apiModules[i];
|
var module = t.apiModules[i];
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "tags/"+module+".gf-tags",
|
url: "tags/"+module+".gf-tags",
|
||||||
type: "GET",
|
type: "GET",
|
||||||
@@ -367,13 +369,14 @@ function Thing() {
|
|||||||
$('#api #results').append($(data));
|
$('#api #results').append($(data));
|
||||||
$("#api #results tr").removeClass('odd');
|
$("#api #results tr").removeClass('odd');
|
||||||
$("#api #results tr:odd").addClass('odd');
|
$("#api #results tr:odd").addClass('odd');
|
||||||
|
$('#api #count').text( $("#api #results tr").length );
|
||||||
},
|
},
|
||||||
error: function(data){
|
error: function(data){
|
||||||
console.log("Error loading tags file: " + module);
|
console.log("Error loading tags file: " + module);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
hideLoading();
|
t.hideLoading();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -392,8 +395,8 @@ function Thing() {
|
|||||||
return haystack.toLowerCase().indexOf(needle.toLowerCase())>=0;
|
return haystack.toLowerCase().indexOf(needle.toLowerCase())>=0;
|
||||||
};
|
};
|
||||||
|
|
||||||
var runFilter = function() {
|
this.runFilter = function() {
|
||||||
showLoading();
|
t.showLoading();
|
||||||
$("#scope #results tr").removeClass('odd');
|
$("#scope #results tr").removeClass('odd');
|
||||||
var s = $("#scope #search").val();
|
var s = $("#scope #search").val();
|
||||||
try {
|
try {
|
||||||
@@ -409,17 +412,17 @@ function Thing() {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(error.message);
|
alert(error.message);
|
||||||
}
|
}
|
||||||
updateScopeCount();
|
t.updateScopeCount();
|
||||||
$("#scope #results tr:visible:odd").addClass('odd');
|
$("#scope #results tr:visible:odd").addClass('odd');
|
||||||
hideLoading();
|
t.hideLoading();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Instant results
|
// Instant results
|
||||||
var prevSearch = $("#scope #search").val();
|
this.prevSearch = $("#scope #search").val();
|
||||||
$("#scope #search").keyup(function(){
|
$("#scope #search").keyup(function(){
|
||||||
var s = $("#scope #search").val();
|
var s = $("#scope #search").val();
|
||||||
if (s!=prevSearch) {
|
if (s!=prevSearch) {
|
||||||
runFilter();
|
t.runFilter();
|
||||||
prevSearch = s;
|
prevSearch = s;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -427,18 +430,18 @@ function Thing() {
|
|||||||
$("#scope #search").keypress(function(e){
|
$("#scope #search").keypress(function(e){
|
||||||
var code = (e.keyCode ? e.keyCode : e.which);
|
var code = (e.keyCode ? e.keyCode : e.which);
|
||||||
if(code == 13) { // Enter
|
if(code == 13) { // Enter
|
||||||
runFilter();
|
t.runFilter();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$("#scope #clear").click(function(){
|
$("#scope #clear").click(function(){
|
||||||
$("#scope #search")
|
$("#scope #search")
|
||||||
.val('')
|
.val('')
|
||||||
.focus()
|
.focus()
|
||||||
runFilter();
|
t.runFilter();
|
||||||
});
|
});
|
||||||
$("#scope #case_sensitive").change(runFilter);
|
$("#scope #case_sensitive").change(t.runFilter);
|
||||||
$("#scope #show_all").change(runFilter);
|
$("#scope #show_all").change(t.runFilter);
|
||||||
$("#scope #show_local").change(runFilter);
|
$("#scope #show_local").change(t.runFilter);
|
||||||
|
|
||||||
// ===== API search =====
|
// ===== API search =====
|
||||||
|
|
||||||
@@ -456,8 +459,8 @@ function Thing() {
|
|||||||
return match_ident || match_type ;
|
return match_ident || match_type ;
|
||||||
};
|
};
|
||||||
|
|
||||||
var runFilterAPI = function() {
|
this.runFilterAPI = function() {
|
||||||
showLoading();
|
t.showLoading();
|
||||||
$("#api #results tr").removeClass('odd');
|
$("#api #results tr").removeClass('odd');
|
||||||
var s = $("#api #search").val();
|
var s = $("#api #search").val();
|
||||||
try {
|
try {
|
||||||
@@ -470,17 +473,17 @@ function Thing() {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(error.message);
|
alert(error.message);
|
||||||
}
|
}
|
||||||
updateAPICount();
|
t.updateAPICount();
|
||||||
$("#api #results tr:visible:odd").addClass('odd');
|
$("#api #results tr:visible:odd").addClass('odd');
|
||||||
hideLoading();
|
t.hideLoading();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Instant results
|
// Instant results
|
||||||
var prevAPISearch = $("#api #search").val();
|
this.prevAPISearch = $("#api #search").val();
|
||||||
$("#api #search").keyup(function(){
|
$("#api #search").keyup(function(){
|
||||||
var s = $("#api #search").val();
|
var s = $("#api #search").val();
|
||||||
if (s!=prevAPISearch) {
|
if (s!=prevAPISearch) {
|
||||||
runFilterAPI();
|
t.runFilterAPI();
|
||||||
prevAPISearch = s;
|
prevAPISearch = s;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -488,13 +491,13 @@ function Thing() {
|
|||||||
$("#api #search").keypress(function(e){
|
$("#api #search").keypress(function(e){
|
||||||
var code = (e.keyCode ? e.keyCode : e.which);
|
var code = (e.keyCode ? e.keyCode : e.which);
|
||||||
if(code == 13) { // Enter
|
if(code == 13) { // Enter
|
||||||
runFilterAPI();
|
t.runFilterAPI();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$("#api #clear").click(function(){
|
$("#api #clear").click(function(){
|
||||||
$("#api #search")
|
$("#api #search")
|
||||||
.val('')
|
.val('')
|
||||||
.focus()
|
.focus();
|
||||||
runFilterAPI();
|
t.runFilterAPI();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -125,9 +125,6 @@ input#search {
|
|||||||
margin-top:1em;
|
margin-top:1em;
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
}
|
}
|
||||||
#results tr:hover {
|
|
||||||
background:#f9f9f9;
|
|
||||||
}
|
|
||||||
/* this is set in code */
|
/* this is set in code */
|
||||||
#results tr.odd {
|
#results tr.odd {
|
||||||
background:ghostwhite;
|
background:ghostwhite;
|
||||||
|
|||||||
Reference in New Issue
Block a user