Skip to content

Commit 2332dc7

Browse files
committed
Deal with undefined offset (scala#10255)
In the scaladoc viewer javascript. scala/bug#10255
1 parent d9c3bd5 commit 2332dc7

File tree

1 file changed

+16
-10
lines changed
  • src/scaladoc/scala/tools/nsc/doc/html/resource/lib

1 file changed

+16
-10
lines changed

src/scaladoc/scala/tools/nsc/doc/html/resource/lib/index.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,26 @@ function handleKeyNavigation() {
113113
scroller.container = $container;
114114

115115
scroller.scrollDown = function($elem) {
116-
var yPos = $elem.offset().top; // offset relative to viewport
117-
if ($container.height() < yPos || (yPos - $("#search").height()) < 0) {
118-
$container.animate({
119-
scrollTop: $container.scrollTop() + yPos - $("#search").height() - 10
120-
}, 200);
116+
var offset = $elem.offset(); // offset relative to viewport
117+
if (offset !== undefined) {
118+
var yPos = offset.top;
119+
if ($container.height() < yPos || (yPos - $("#search").height()) < 0) {
120+
$container.animate({
121+
scrollTop: $container.scrollTop() + yPos - $("#search").height() - 10
122+
}, 200);
123+
}
121124
}
122125
};
123126

124127
scroller.scrollUp = function ($elem) {
125-
var yPos = $elem.offset().top; // offset relative to viewport
126-
if (yPos < $("#search").height()) {
127-
$container.animate({
128-
scrollTop: $container.scrollTop() + yPos - $("#search").height() - 10
129-
}, 200);
128+
var offset = $elem.offset(); // offset relative to viewport
129+
if (offset !== undefined) {
130+
var yPos = offset.top;
131+
if (yPos < $("#search").height()) {
132+
$container.animate({
133+
scrollTop: $container.scrollTop() + yPos - $("#search").height() - 10
134+
}, 200);
135+
}
130136
}
131137
};
132138

0 commit comments

Comments
 (0)