commit f164cbb789a862dc8654b0eface7e916ad89df59
parent d1fb3165976ceef63f200c27c61c49b70127e4a0
Author: Eli Barzilay <eli@racket-lang.org>
Date: Tue, 24 Nov 2009 06:45:26 +0000
url parameter utilities
svn: r17026
original commit: cdf940fedd38a817f6a4ee02a245058942599b60
Diffstat:
1 file changed, 36 insertions(+), 0 deletions(-)
diff --git a/collects/scribble/scribble-common.js b/collects/scribble/scribble-common.js
@@ -1,5 +1,7 @@
// Common functionality for PLT documentation pages
+// Cookies --------------------------------------------------------------------
+
function GetCookie(key, def) {
if (document.cookie.length <= 0) return def;
var i, cookiestrs = document.cookie.split(/; */);
@@ -36,6 +38,38 @@ function GotoPLTRoot(ver, relative) {
return false;
}
+// URL Parameters -------------------------------------------------------------
+
+// In the following functions, the `name' argument is assumed to be simple in
+// that it doesn't contain anything that isn't plain text in a regexp. (This
+// is because I don't know if there's a JS `regexp-quote' thing). Also, the
+// output value from the Get functions and the input value to the Set functions
+// is not decoded/encoded. Note that `SetArgInURL' mutates the string.
+
+function GetArgFromString(str, name) {
+ var rx = new RegExp("(?:^|[;&])"+name+"=([^&;]*)(?:[;&]|$)");
+ return rx.test(str) && RegExp.$1;
+}
+
+function SetArgInString(str, name, val) {
+ if (str.length == 0) return name + "=" + val;
+ var rx = new RegExp("^((?:|.*[;&])"+name+"=)(?:[^&;]*)([;&].*|)$");
+ if (rx.test(str)) return RegExp.$1 + val + RegExp.$2;
+ else return name + "=" + val + "&" + str;
+}
+
+function GetArgFromURL(url, name) {
+ if (!url.href.search(/\?([^#]*)(?:#|$)/)) return false;
+ return GetArgFromString(RegExp.$1, name);
+}
+
+function SetArgInURL(url, name, val) { // note: mutates the string
+ url.href.search(/^([^?#]*)(?:\?([^#]*))?(#.*)?$/);
+ url.href = RegExp.$1 + "?" + SetArgInString(RegExp.$2,name,val) + RegExp.$3;
+}
+
+// Utilities ------------------------------------------------------------------
+
normalize_rxs = [/\/\/+/g, /\/\.(\/|$)/, /\/[^\/]*\/\.\.(\/|$)/];
function NormalizePath(path) {
var tmp, i;
@@ -44,6 +78,8 @@ function NormalizePath(path) {
return path;
}
+// Interactions ---------------------------------------------------------------
+
function DoSearchKey(event, field, ver, top_path) {
var val = field.value;
if (event && event.keyCode == 13) {