up links in all documents, and they go to the user docs using cookies

svn: r9992
This commit is contained in:
Eli Barzilay 2008-05-28 00:02:25 +00:00
parent 6ca9703fcc
commit 9127cdaaf8
4 changed files with 64 additions and 41 deletions

View File

@ -219,6 +219,9 @@
quiet-table-of-contents) quiet-table-of-contents)
(init-field [css-path #f] (init-field [css-path #f]
;; up-path is either a link "up", or #t which uses
;; goes to start page (using cookies to get to the
;; user start page)
[up-path #f] [up-path #f]
[style-file #f] [style-file #f]
[script-path #f] [script-path #f]
@ -620,14 +623,26 @@
prev-content) prev-content)
sep-element sep-element
(make-element (make-element
(if (or parent up-path) (cond
;; up-path = #t => go up to the start page, using
;; cookies to get to the user's version of it (see
;; scribblings/main/private/utils for the code
;; that creates these cookies.)
[(and (eq? #t up-path) (not parent))
(make-target-url
"../index.html"
(make-with-attributes
#f `([onclick
. ,(format "return GotoPLTRoot(\"~a\");"
(version))])))]
[(or parent up-path)
(make-target-url (make-target-url
(cond [(not parent) up-path] (cond [(not parent) up-path]
[(and (toc-part? parent) (part-parent parent ri)) [(and (toc-part? parent) (part-parent parent ri))
(derive-filename parent)] (derive-filename parent)]
[else "index.html"]) [else "index.html"])
#f) #f)]
"nonavigation") [else "nonavigation"])
up-content) up-content)
sep-element sep-element
(make-element (make-element
@ -815,8 +830,8 @@
(if (path? addr) (if (path? addr)
(from-root addr (get-dest-directory)) (from-root addr (get-dest-directory))
addr))] addr))]
;; The target-url chains to another style. Allow ;; The target-url chains to another style,
;; `with-attributes' inside as well as outside: ;; flatten-style above takes care of it though.
,@(let ([style (target-url-style style)]) ,@(let ([style (target-url-style style)])
(if (string? style) (if (string? style)
`([class ,style]) `([class ,style])

View File

@ -19,19 +19,21 @@ function SetCookie(key, val) {
key + "=" + escape(val) + "; expires="+ d.toGMTString() + "; path=/"; key + "=" + escape(val) + "; expires="+ d.toGMTString() + "; path=/";
} }
function GotoPLTRoot(ver) { // note that this always stores a directory name, ending with a "/"
var u = GetCookie("PLT_Root."+ver);
if (u == null) return true; // no cookie: use plain up link
location = u;
return false;
}
function SetPLTRoot(ver, relative) { function SetPLTRoot(ver, relative) {
var root = location.protocol + "//" + location.host var root = location.protocol + "//" + location.host
+ NormalizePath(location.pathname.replace(/[^\/]*$/, relative)); + NormalizePath(location.pathname.replace(/[^\/]*$/, relative));
SetCookie("PLT_Root."+ver, root); SetCookie("PLT_Root."+ver, root);
} }
// adding index.html works because of the above
function GotoPLTRoot(ver) {
var u = GetCookie("PLT_Root."+ver);
if (u == null) return true; // no cookie: use plain up link
location = u + "index.html";
return false;
}
normalize_rxs = [/\/\/+/g, /\/\.(\/|$)/, /\/[^\/]*\/\.\.(\/|$)/]; normalize_rxs = [/\/\/+/g, /\/\.(\/|$)/, /\/[^\/]*\/\.\.(\/|$)/];
function NormalizePath(path) { function NormalizePath(path) {
var tmp, i; var tmp, i;

View File

@ -224,9 +224,12 @@
(if latex-dest (if latex-dest
(new (latex:render-mixin render%) (new (latex:render-mixin render%)
[dest-dir latex-dest]) [dest-dir latex-dest])
(let ([multi? (memq 'multi-page (doc-flags doc))] (let* ([flags (doc-flags doc)]
[multi? (memq 'multi-page flags)]
[main? (doc-under-main? doc)] [main? (doc-under-main? doc)]
[ddir (doc-dest-dir doc)]) [ddir (doc-dest-dir doc)]
[root? (or (memq 'main-doc-root flags)
(memq 'user-doc-root flags))])
(new ((if multi? html:render-multi-mixin values) (new ((if multi? html:render-multi-mixin values)
(html:render-mixin render%)) (html:render-mixin render%))
[dest-dir (if multi? [dest-dir (if multi?
@ -234,7 +237,10 @@
ddir)] ddir)]
[css-path (and main? "../scribble.css")] [css-path (and main? "../scribble.css")]
[script-path (and main? "../scribble-common.js")] [script-path (and main? "../scribble-common.js")]
[up-path (and main? "../index.html")])))) ;; up-path is #t, which makes it go to the (user's) start page
;; (using cookies) -- except when it is the start page itself
;; (one of the two)
[up-path (not root?)]))))
(define (pick-dest latex-dest doc) (define (pick-dest latex-dest doc)
(cond [latex-dest (cond [latex-dest