Merge pull request #3967 from Snuffleupagus/scrollIntoView-horizontal
Add support for horizontal scrolling in 'scrollIntoView' in ui_utils.js
This commit is contained in:
commit
738ae57960
@ -13,10 +13,12 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
/* globals CustomStyle, PDFFindController, scrollIntoView */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/* globals CustomStyle, PDFFindController, scrollIntoView */
|
var FIND_SCROLL_OFFSET_TOP = -50;
|
||||||
|
var FIND_SCROLL_OFFSET_LEFT = -400;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TextLayerBuilder provides text-selection
|
* TextLayerBuilder provides text-selection
|
||||||
@ -310,7 +312,8 @@ var TextLayerBuilder = function textLayerBuilder(options) {
|
|||||||
var isSelected = isSelectedPage && i === selectedMatchIdx;
|
var isSelected = isSelectedPage && i === selectedMatchIdx;
|
||||||
var highlightSuffix = (isSelected ? ' selected' : '');
|
var highlightSuffix = (isSelected ? ' selected' : '');
|
||||||
if (isSelected && !this.isViewerInPresentationMode) {
|
if (isSelected && !this.isViewerInPresentationMode) {
|
||||||
scrollIntoView(textDivs[begin.divIdx], { top: -50 });
|
scrollIntoView(textDivs[begin.divIdx], { top: FIND_SCROLL_OFFSET_TOP,
|
||||||
|
left: FIND_SCROLL_OFFSET_LEFT });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Match inside new div.
|
// Match inside new div.
|
||||||
|
@ -100,7 +100,8 @@ function getOutputScale(ctx) {
|
|||||||
/**
|
/**
|
||||||
* Scrolls specified element into view of its parent.
|
* Scrolls specified element into view of its parent.
|
||||||
* element {Object} The element to be visible.
|
* element {Object} The element to be visible.
|
||||||
* spot {Object} The object with the top property -- offset from the top edge.
|
* spot {Object} An object with optional top and left properties,
|
||||||
|
* specifying the offset from the top left edge.
|
||||||
*/
|
*/
|
||||||
function scrollIntoView(element, spot) {
|
function scrollIntoView(element, spot) {
|
||||||
// Assuming offsetParent is available (it's not available when viewer is in
|
// Assuming offsetParent is available (it's not available when viewer is in
|
||||||
@ -108,21 +109,32 @@ function scrollIntoView(element, spot) {
|
|||||||
// producing the error. See also animationStartedClosure.
|
// producing the error. See also animationStartedClosure.
|
||||||
var parent = element.offsetParent;
|
var parent = element.offsetParent;
|
||||||
var offsetY = element.offsetTop + element.clientTop;
|
var offsetY = element.offsetTop + element.clientTop;
|
||||||
|
var offsetX = element.offsetLeft + element.clientLeft;
|
||||||
if (!parent) {
|
if (!parent) {
|
||||||
console.error('offsetParent is not set -- cannot scroll');
|
console.error('offsetParent is not set -- cannot scroll');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (parent.clientHeight == parent.scrollHeight) {
|
while (parent.clientHeight === parent.scrollHeight) {
|
||||||
if (parent.dataset._scaleY) {
|
if (parent.dataset._scaleY) {
|
||||||
offsetY /= parent.dataset._scaleY;
|
offsetY /= parent.dataset._scaleY;
|
||||||
|
offsetX /= parent.dataset._scaleX;
|
||||||
}
|
}
|
||||||
offsetY += parent.offsetTop;
|
offsetY += parent.offsetTop;
|
||||||
|
offsetX += parent.offsetLeft;
|
||||||
parent = parent.offsetParent;
|
parent = parent.offsetParent;
|
||||||
if (!parent)
|
if (!parent) {
|
||||||
return; // no need to scroll
|
return; // no need to scroll
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (spot) {
|
||||||
|
if (spot.top !== undefined) {
|
||||||
|
offsetY += spot.top;
|
||||||
|
}
|
||||||
|
if (spot.left !== undefined) {
|
||||||
|
offsetX += spot.left;
|
||||||
|
parent.scrollLeft = offsetX;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (spot)
|
|
||||||
offsetY += spot.top;
|
|
||||||
parent.scrollTop = offsetY;
|
parent.scrollTop = offsetY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user