scriblib/figure: make figure hyperlinks show start of figure
... instead of putting the figure's caption at the top of the browser window. I can't decide whether I like the technique here, which is to use JavaScript to move a figure caption's <a name=...> when the page is loaded. On the one hand, fixing up HTML via load-time JavaScript code seems ugly compared to generating the right HTML in the first place. On the other hand, it simplifies the generatation of a backend-independent Scribble document (i.e., don't try to generate different target locations for HTML and Latex), and HTML-specific behavior seems properly handled at the HTML/JavaScript level. original commit: 2b33b8d9668988b67f6b68b9eb012eb6d8f417d5
This commit is contained in:
parent
7e8ff47b5b
commit
0909ced11b
pkgs/scribble-pkgs/scribble-lib/scriblib
27
pkgs/scribble-pkgs/scribble-lib/scriblib/figure.js
Normal file
27
pkgs/scribble-pkgs/scribble-lib/scriblib/figure.js
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
|
||||||
|
AddOnLoad(function () {
|
||||||
|
/* Lift figure targets to the start of the figure's blockquote,
|
||||||
|
so that clicking on a target reference shows the figure
|
||||||
|
content, instead of scrolling the figure caption to the
|
||||||
|
top of the page. */
|
||||||
|
var targets = document.getElementsByTagName("a");
|
||||||
|
for (var i = 0; i < targets.length; i++) {
|
||||||
|
var a = targets[i];
|
||||||
|
var n = a.attributes["x-target-lift"];
|
||||||
|
if (n) {
|
||||||
|
var s = n.value;
|
||||||
|
var p = a.parentNode;
|
||||||
|
while (p && (p.className != s)) {
|
||||||
|
p = p.parentNode;
|
||||||
|
}
|
||||||
|
if (p) {
|
||||||
|
var cs = p.children;
|
||||||
|
a.parentNode.removeChild(a);
|
||||||
|
if (cs.length > 0)
|
||||||
|
p.insertBefore(a, cs[0]);
|
||||||
|
else
|
||||||
|
p.appendChild(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
|
@ -47,6 +47,15 @@
|
||||||
|
|
||||||
(define centertext-style (make-style "Centertext" figure-style-extras))
|
(define centertext-style (make-style "Centertext" figure-style-extras))
|
||||||
|
|
||||||
|
;; See "figure.js":
|
||||||
|
(define figure-target-style
|
||||||
|
(make-style #f
|
||||||
|
(list
|
||||||
|
(make-attributes '((x-target-lift . "Figure")))
|
||||||
|
(make-js-addition
|
||||||
|
(path->main-collects-relative
|
||||||
|
(collection-file-path "figure.js" "scriblib"))))))
|
||||||
|
|
||||||
(define (make-figure-ref c s)
|
(define (make-figure-ref c s)
|
||||||
(element (style "FigureRef" (list* (command-extras (list s))
|
(element (style "FigureRef" (list* (command-extras (list s))
|
||||||
figure-style-extras))
|
figure-style-extras))
|
||||||
|
@ -100,6 +109,7 @@
|
||||||
(counter-target figures tag
|
(counter-target figures tag
|
||||||
"Figure"
|
"Figure"
|
||||||
(if continue? " (continued): " ": ")
|
(if continue? " (continued): " ": ")
|
||||||
|
#:target-style figure-target-style
|
||||||
#:continue? continue?))
|
#:continue? continue?))
|
||||||
|
|
||||||
(define (ref-proc initial)
|
(define (ref-proc initial)
|
||||||
|
|
|
@ -20,12 +20,13 @@
|
||||||
`(counter (,(counter-name counter) ,tag ,@kind))))
|
`(counter (,(counter-name counter) ,tag ,@kind))))
|
||||||
|
|
||||||
(define (counter-target counter tag label
|
(define (counter-target counter tag label
|
||||||
|
#:target-style [target-style #f]
|
||||||
#:continue? [continue? #f]
|
#:continue? [continue? #f]
|
||||||
. content)
|
. content)
|
||||||
(let ([content (decode-content content)])
|
(let ([content (decode-content content)])
|
||||||
(define c
|
(define c
|
||||||
(make-target-element
|
(make-target-element
|
||||||
#f
|
target-style
|
||||||
(list
|
(list
|
||||||
(make-collect-element
|
(make-collect-element
|
||||||
#f
|
#f
|
||||||
|
|
Loading…
Reference in New Issue
Block a user