Misc improvements to the doc search JavaScript code
* Stamp "plt-index.js" with the path of its generator. * Fix most of the "use strict" and js2-mode warnings in scribble's JavaScript. * Some code improvements in the generating code too. (With some edits by Eli.)
This commit is contained in:
parent
6a82c8bb7c
commit
a624d8de15
|
@ -96,7 +96,7 @@ function GotoPLTRoot(ver, relative) {
|
||||||
|
|
||||||
// Utilities ------------------------------------------------------------------
|
// Utilities ------------------------------------------------------------------
|
||||||
|
|
||||||
normalize_rxs = [/\/\/+/g, /\/\.(\/|$)/, /\/[^\/]*\/\.\.(\/|$)/];
|
var normalize_rxs = [/\/\/+/g, /\/\.(\/|$)/, /\/[^\/]*\/\.\.(\/|$)/];
|
||||||
function NormalizePath(path) {
|
function NormalizePath(path) {
|
||||||
var tmp, i;
|
var tmp, i;
|
||||||
for (i = 0; i < normalize_rxs.length; i++)
|
for (i = 0; i < normalize_rxs.length; i++)
|
||||||
|
|
|
@ -1,23 +1,24 @@
|
||||||
#reader scribble/reader
|
#lang at-exp racket/base
|
||||||
#lang scheme/base
|
|
||||||
|
|
||||||
(require scribble/decode
|
(require scribble/decode
|
||||||
scribble/decode-struct
|
scribble/decode-struct
|
||||||
scribble/basic
|
scribble/basic
|
||||||
scribble/core
|
scribble/core
|
||||||
scribble/scheme
|
scribble/racket
|
||||||
scribble/html-properties
|
scribble/html-properties
|
||||||
scribble/manual-struct
|
scribble/manual-struct
|
||||||
scheme/list
|
racket/list
|
||||||
scheme/string
|
racket/string
|
||||||
scheme/match
|
racket/match
|
||||||
scheme/path
|
racket/path
|
||||||
net/url
|
net/url
|
||||||
(only-in scheme/class send)
|
(only-in racket/class send)
|
||||||
(only-in xml xexpr->string)
|
(only-in xml xexpr->string)
|
||||||
|
racket/runtime-path
|
||||||
|
syntax/location
|
||||||
|
setup/path-to-relative
|
||||||
(only-in setup/dirs find-doc-dir)
|
(only-in setup/dirs find-doc-dir)
|
||||||
"utils.rkt"
|
"utils.rkt")
|
||||||
scheme/runtime-path)
|
|
||||||
|
|
||||||
(provide make-search)
|
(provide make-search)
|
||||||
|
|
||||||
|
@ -155,15 +156,21 @@
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(for-each
|
(for-each
|
||||||
display
|
display
|
||||||
@`{// the url of the main doc tree, for compact url
|
@`{// Autogenerated by @;
|
||||||
|
@,(path->relative-string/library (quote-module-path))
|
||||||
|
@||
|
||||||
|
// the url of the main doc tree, for compact url
|
||||||
// representation (see also the UncompactUrl function)
|
// representation (see also the UncompactUrl function)
|
||||||
plt_main_url = @,(quote-string main-url);@"\n"
|
var plt_main_url = @,(quote-string main-url);
|
||||||
|
@||
|
||||||
// classes to be used for compact representation of html strings in
|
// classes to be used for compact representation of html strings in
|
||||||
// plt_search_data below (see also the UncompactHtml function)
|
// plt_search_data below (see also the UncompactHtml function)
|
||||||
plt_span_classes = [
|
var plt_span_classes = [
|
||||||
@,@(add-between (map (lambda (x) (quote-string (car x)))
|
@,@(add-between (map (lambda (x) (quote-string (car x)))
|
||||||
(reverse span-classes))
|
(reverse span-classes))
|
||||||
",\n ")];@"\n"
|
",\n ")
|
||||||
|
];
|
||||||
|
@||
|
||||||
// this array has an entry of four items for each index link:
|
// this array has an entry of four items for each index link:
|
||||||
// - text is a string holding the indexed text
|
// - text is a string holding the indexed text
|
||||||
// - url holds the link (">" prefix means relative to plt_main_url)
|
// - url holds the link (">" prefix means relative to plt_main_url)
|
||||||
|
@ -171,10 +178,12 @@
|
||||||
// index into plt_span_classes (note: this is recursive)
|
// index into plt_span_classes (note: this is recursive)
|
||||||
// - from_lib is an array of module names for bound identifiers,
|
// - from_lib is an array of module names for bound identifiers,
|
||||||
// or the string "module" for a module entry
|
// or the string "module" for a module entry
|
||||||
plt_search_data = [
|
var plt_search_data = [
|
||||||
@,@(add-between l ",\n")];@"\n"
|
@,@(add-between l ",\n")
|
||||||
|
];
|
||||||
|
@||
|
||||||
// array of pointers to the previous array, for items that are manuals
|
// array of pointers to the previous array, for items that are manuals
|
||||||
plt_manual_ptrs = {
|
var plt_manual_ptrs = {
|
||||||
@,@(let* ([ms (hash-map manual-refs cons)]
|
@,@(let* ([ms (hash-map manual-refs cons)]
|
||||||
[ms (sort ms < #:key cdr)]
|
[ms (sort ms < #:key cdr)]
|
||||||
[ms (map (lambda (x)
|
[ms (map (lambda (x)
|
||||||
|
|
|
@ -32,7 +32,7 @@ function MakePref(label, input) {
|
||||||
return '<tr><td align="right">' + label + ': </td>'
|
return '<tr><td align="right">' + label + ': </td>'
|
||||||
+'<td>' + input + '</td></tr>';
|
+'<td>' + input + '</td></tr>';
|
||||||
}
|
}
|
||||||
descriptions = new Array();
|
var descriptions = new Array();
|
||||||
function PrefInputArgs(name, desc) {
|
function PrefInputArgs(name, desc) {
|
||||||
// don't plant `desc' directly in the text -- it might have quotes
|
// don't plant `desc' directly in the text -- it might have quotes
|
||||||
descriptions[name] = desc;
|
descriptions[name] = desc;
|
||||||
|
@ -78,14 +78,14 @@ function MakeIcon(label,title,action) {
|
||||||
+' style="text-decoration: none; color: black;'
|
+' style="text-decoration: none; color: black;'
|
||||||
+' font-weight: bold; font-family: monospace;"'
|
+' font-weight: bold; font-family: monospace;"'
|
||||||
+' onclick="'+action+'; return false;"'
|
+' onclick="'+action+'; return false;"'
|
||||||
+'>'+label+'</a>'
|
+'>'+label+'</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
function InitializeSearch() {
|
function InitializeSearch() {
|
||||||
var n;
|
var n;
|
||||||
n = document.getElementById("plt_search_container");
|
n = document.getElementById("plt_search_container");
|
||||||
// hack the dom widgets in
|
// hack the dom widgets in
|
||||||
var panelbgcolor = "background-color: #f0f0f0;"
|
var panelbgcolor = "background-color: #f0f0f0;";
|
||||||
var panelstyle =
|
var panelstyle =
|
||||||
'style="display: none; border: 1px solid #222; border-top: 0px;'
|
'style="display: none; border: 1px solid #222; border-top: 0px;'
|
||||||
+' font-family: arial, sans-serif; margin: 0em 0em 1em 0em;'
|
+' font-family: arial, sans-serif; margin: 0em 0em 1em 0em;'
|
||||||
|
@ -340,7 +340,7 @@ function CompileWordCompare(term) {
|
||||||
// otherwise return C_words1 regardless of whether all of the words in term
|
// otherwise return C_words1 regardless of whether all of the words in term
|
||||||
// matched exactly words in str
|
// matched exactly words in str
|
||||||
else return C_words1;
|
else return C_words1;
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
// Tests:
|
// Tests:
|
||||||
// console.log("testing...");
|
// console.log("testing...");
|
||||||
|
@ -409,26 +409,26 @@ function CompileTerm(term) {
|
||||||
case "N":
|
case "N":
|
||||||
op = CompileTerm(term);
|
op = CompileTerm(term);
|
||||||
// return C_exact if it's not found, so it doesn't disqualify exact matches
|
// return C_exact if it's not found, so it doesn't disqualify exact matches
|
||||||
return function(x) { return (op(x) >= C_match) ? C_fail : C_exact; }
|
return function(x) { return (op(x) >= C_match) ? C_fail : C_exact; };
|
||||||
case "L":
|
case "L":
|
||||||
return function(x) {
|
return function(x) {
|
||||||
if (!x[3]) return C_fail;
|
if (!x[3]) return C_fail;
|
||||||
if (x[3] == "module") // rexact allowed, show partial module matches
|
if (x[3] == "module") // rexact allowed, show partial module matches
|
||||||
return Compare(term,x[0]);
|
return Compare(term,x[0]);
|
||||||
return (MaxCompares(term,x[3]) >= C_exact) ? C_exact : C_fail;
|
return (MaxCompares(term,x[3]) >= C_exact) ? C_exact : C_fail;
|
||||||
}
|
};
|
||||||
case "M":
|
case "M":
|
||||||
return function(x) {
|
return function(x) {
|
||||||
if (!x[3]) return C_fail;
|
if (!x[3]) return C_fail;
|
||||||
if (x[3] == "module") return Compare(term,x[0]); // rexact allowed
|
if (x[3] == "module") return Compare(term,x[0]); // rexact allowed
|
||||||
return (MaxCompares(term,x[3]) >= C_match) ? C_exact : C_fail;
|
return (MaxCompares(term,x[3]) >= C_match) ? C_exact : C_fail;
|
||||||
}
|
};
|
||||||
case "T":
|
case "T":
|
||||||
return function(x) {
|
return function(x) {
|
||||||
if (Compare(term,UrlToManual(x[1])) < C_exact) return C_fail;
|
if (Compare(term,UrlToManual(x[1])) < C_exact) return C_fail;
|
||||||
else if (x[1].search(/\/index\.html$/) > 0) return C_rexact;
|
else if (x[1].search(/\/index\.html$/) > 0) return C_rexact;
|
||||||
else return C_exact;
|
else return C_exact;
|
||||||
}
|
};
|
||||||
/* a case for "Q" is not needed -- same as the default case below */
|
/* a case for "Q" is not needed -- same as the default case below */
|
||||||
default:
|
default:
|
||||||
var compare_words = CompileWordCompare(term);
|
var compare_words = CompileWordCompare(term);
|
||||||
|
@ -438,7 +438,7 @@ function CompileTerm(term) {
|
||||||
if (r >= C_rexact) return (x[3] ? r : C_exact);
|
if (r >= C_rexact) return (x[3] ? r : C_exact);
|
||||||
if (r > C_words3) return r;
|
if (r > C_words3) return r;
|
||||||
else return compare_words(x[0]);
|
else return compare_words(x[0]);
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -484,7 +484,7 @@ function CompileTermsR(terms, nested) {
|
||||||
|
|
||||||
function CompileTerms(terms, nested) {
|
function CompileTerms(terms, nested) {
|
||||||
terms.reverse();
|
terms.reverse();
|
||||||
return CompileTermsR(terms, nested)
|
return CompileTermsR(terms, nested);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Id(x) {
|
function Id(x) {
|
||||||
|
@ -512,19 +512,19 @@ function MakeShowProgress() {
|
||||||
return function(n) {
|
return function(n) {
|
||||||
status_line.innerHTML =
|
status_line.innerHTML =
|
||||||
orig + indicators[Math.round(10*n/search_data.length)];
|
orig + indicators[Math.round(10*n/search_data.length)];
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function Search(data, term, is_pre, K) {
|
function Search(data, term, is_pre, K) {
|
||||||
// `K' is a continuation if this run is supposed to happen in a "thread"
|
// `K' is a continuation if this run is supposed to happen in a "thread"
|
||||||
// false otherwise
|
// false otherwise
|
||||||
var t = false;
|
var t = false;
|
||||||
var killer = function() { if (t) clearTimeout(t); };
|
function Killer() { if (t) clearTimeout(t); };
|
||||||
// term comes with normalized spaces (trimmed, and no double spaces)
|
// term comes with normalized spaces (trimmed, and no double spaces)
|
||||||
var preds = (term=="") ? [] : CompileTerms(term.split(/ /), false);
|
var preds = (term=="") ? [] : CompileTerms(term.split(/ /), false);
|
||||||
if (preds.length == 0) {
|
if (preds.length == 0) {
|
||||||
var ret = is_pre ? [0,data] : [0,[]];
|
var ret = is_pre ? [0,data] : [0,[]];
|
||||||
if (K) { K(ret); return killer; }
|
if (K) { K(ret); return Killer; }
|
||||||
else return ret;
|
else return ret;
|
||||||
}
|
}
|
||||||
var i = 0;
|
var i = 0;
|
||||||
|
@ -533,7 +533,7 @@ function Search(data, term, is_pre, K) {
|
||||||
var chunk_fuel = K ? Math.round(data.length/10) : data.length;
|
var chunk_fuel = K ? Math.round(data.length/10) : data.length;
|
||||||
var progress = K ? MakeShowProgress() : Id;
|
var progress = K ? MakeShowProgress() : Id;
|
||||||
i = 0;
|
i = 0;
|
||||||
var DoChunk = function() {
|
function DoChunk() {
|
||||||
var fuel = Math.min(chunk_fuel, data.length-i);
|
var fuel = Math.min(chunk_fuel, data.length-i);
|
||||||
progress(i+fuel);
|
progress(i+fuel);
|
||||||
while (fuel > 0) {
|
while (fuel > 0) {
|
||||||
|
@ -557,7 +557,7 @@ function Search(data, term, is_pre, K) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (!K) return DoChunk();
|
if (!K) return DoChunk();
|
||||||
else { progress(0); t = setTimeout(DoChunk,5); return killer; }
|
else { progress(0); t = setTimeout(DoChunk,5); return Killer; }
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetContextHTML() {
|
function GetContextHTML() {
|
||||||
|
@ -645,7 +645,7 @@ function UncompactHtml(x) {
|
||||||
if (typeof x == "string") {
|
if (typeof x == "string") {
|
||||||
return x;
|
return x;
|
||||||
} else if (!(x instanceof Array)) {
|
} else if (!(x instanceof Array)) {
|
||||||
alert("Internal error in PLT docs");
|
return alert("Internal error in PLT docs");
|
||||||
} else if ((x.length == 2) && (typeof(x[0]) == "number")) {
|
} else if ((x.length == 2) && (typeof(x[0]) == "number")) {
|
||||||
return '<span class="' + plt_span_classes[x[0]]
|
return '<span class="' + plt_span_classes[x[0]]
|
||||||
+ '">' + UncompactHtml(x[1]) + '</span>';
|
+ '">' + UncompactHtml(x[1]) + '</span>';
|
||||||
|
@ -873,15 +873,6 @@ function HidePrefs(event) {
|
||||||
}
|
}
|
||||||
hide_prefs = HidePrefs;
|
hide_prefs = HidePrefs;
|
||||||
|
|
||||||
function SetShowManuals(inp) {
|
|
||||||
if (inp.selectedIndex != show_manuals) {
|
|
||||||
show_manuals = inp.selectedIndex;
|
|
||||||
SetCookie("PLT_ManualSettings", show_manuals+(show_manual_titles?10:0));
|
|
||||||
UpdateResults();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
set_show_manuals = SetShowManuals;
|
|
||||||
|
|
||||||
function SetContextQuery(inp,label) {
|
function SetContextQuery(inp,label) {
|
||||||
// can be called with the input object, or with a string
|
// can be called with the input object, or with a string
|
||||||
if (typeof inp != "string") inp = inp.value;
|
if (typeof inp != "string") inp = inp.value;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user