-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathscript.js
75 lines (63 loc) · 1.9 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
$(function() {
$("#expand-nav").click(function() {
$(".expandable").toggleClass("shown");
});
$(window).scroll(function() {
var nav = $("nav.floating");
if ($(window).scrollTop() > 84) {
nav.addClass("pinned");
} else {
nav.removeClass("pinned");
}
});
$(window).resize(refreshAsides);
// Since we may not have the height correct for the images, adjust the asides
// too when an image is loaded.
$("img").on("load", function() {
refreshAsides();
});
// On the off chance the browser supports the new font loader API, use it.
if (document.fontloader) {
document.fontloader.notifyWhenFontsReady(function() {
refreshAsides();
});
}
// Lame. Just do another refresh after a second when the font is *probably*
// loaded to hack around the fact that the metrics changed a bit.
window.setTimeout(refreshAsides, 200);
refreshAsides();
});
function refreshAsides() {
$("aside").each(function() {
var aside = $(this);
// If the asides are inline, clear their position.
if ($(document).width() <= 48 * 20) {
aside.css('top', 'auto');
return;
}
// Find the span the aside should be anchored next to.
var name = aside.attr("name");
if (name == null) {
window.console.log("No name for aside:");
window.console.log(aside.context);
return;
}
var span = $("span[name='" + name + "']");
if (span == null) {
window.console.log("Could not find span for '" + name + "'");
return;
}
// Vertically position the aside next to the span it annotates.
var pos = span.position();
if (pos == null) {
window.console.log("Could not find position for '" + name + "'");
console.log(span);
return;
}
if (aside.hasClass("bottom")) {
aside.offset({top: pos.top + 23 - aside.height()});
} else {
aside.offset({top: pos.top - 6});
}
});
}