Skip to content

Commit 57866c5

Browse files
committed
Merge pull request mozilla#2023 from yurydelendik/scrollIntoView
Replaces scrollIntoView
2 parents d77bafa + 72bb0f5 commit 57866c5

File tree

2 files changed

+21
-27
lines changed

2 files changed

+21
-27
lines changed

web/viewer.css

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,28 @@ select {
2929

3030
#viewerContainer:-webkit-full-screen {
3131
top: 0px;
32-
padding-top: 6px;
33-
padding-bottom: 24px;
32+
border-top: 5px solid transparent;
3433
background-color: #404040;
3534
background-image: url(images/texture.png);
3635
width: 100%;
3736
height: 100%;
38-
overflow: auto;
39-
}
40-
41-
:-webkit-full-screen #viewer {
42-
margin: 0pt;
43-
padding: 0pt;
44-
height: 100%;
45-
width: 100%;
4637
overflow: hidden;
4738
}
4839

49-
:-webkit-full-screen .page {
50-
margin: 0px auto;
51-
margin-bottom: 10px;
52-
}
53-
5440
#viewerContainer:-moz-full-screen {
41+
top: 0px;
42+
border-top: 5px solid transparent;
5543
background-color: #404040;
5644
background-image: url(images/texture.png);
5745
width: 100%;
5846
height: 100%;
5947
overflow: hidden;
6048
}
6149

50+
:-webkit-full-screen .page:last-child {
51+
margin-bottom: 40px;
52+
}
53+
6254
:-moz-full-screen .page:last-child {
6355
margin-bottom: 40px;
6456
}

web/viewer.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ function getFileName(url) {
3333
return url.substring(url.lastIndexOf('/', end) + 1, end);
3434
}
3535

36+
function scrollIntoView(element, spot) {
37+
var parent = element.offsetParent, offsetY = element.offsetTop;
38+
while (parent.clientHeight == parent.scrollHeight) {
39+
offsetY += parent.offsetTop;
40+
parent = parent.offsetParent;
41+
}
42+
if (spot)
43+
offsetY += spot.top;
44+
parent.scrollTop = offsetY;
45+
}
46+
3647
var Cache = function cacheCache(size) {
3748
var data = [];
3849
this.push = function cachePush(view) {
@@ -1315,7 +1326,7 @@ var PageView = function pageView(container, pdfPage, id, scale,
13151326

13161327
this.scrollIntoView = function pageViewScrollIntoView(dest) {
13171328
if (!dest) {
1318-
div.scrollIntoView(true);
1329+
scrollIntoView(div);
13191330
return;
13201331
}
13211332

@@ -1374,16 +1385,7 @@ var PageView = function pageView(container, pdfPage, id, scale,
13741385
var width = Math.abs(boundingRect[0][0] - boundingRect[1][0]);
13751386
var height = Math.abs(boundingRect[0][1] - boundingRect[1][1]);
13761387

1377-
// using temporary div to scroll it into view
1378-
var tempDiv = document.createElement('div');
1379-
tempDiv.style.position = 'absolute';
1380-
tempDiv.style.left = Math.floor(x) + 'px';
1381-
tempDiv.style.top = Math.floor(y) + 'px';
1382-
tempDiv.style.width = Math.ceil(width) + 'px';
1383-
tempDiv.style.height = Math.ceil(height) + 'px';
1384-
div.appendChild(tempDiv);
1385-
tempDiv.scrollIntoView(true);
1386-
div.removeChild(tempDiv);
1388+
scrollIntoView(div, {left: x, top: y, width: width, height: height});
13871389
}, 0);
13881390
};
13891391

@@ -2084,7 +2086,7 @@ window.addEventListener('pagechange', function pagechange(evt) {
20842086
var last = numVisibleThumbs > 1 ?
20852087
visibleThumbs.last.id : first;
20862088
if (page <= first || page >= last)
2087-
thumbnail.scrollIntoView();
2089+
scrollIntoView(thumbnail);
20882090
}
20892091

20902092
}

0 commit comments

Comments
 (0)