diff options
Diffstat (limited to 'polygerrit-ui/app/elements/shared/gr-cursor-manager/gr-cursor-manager.js')
-rw-r--r-- | polygerrit-ui/app/elements/shared/gr-cursor-manager/gr-cursor-manager.js | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/polygerrit-ui/app/elements/shared/gr-cursor-manager/gr-cursor-manager.js b/polygerrit-ui/app/elements/shared/gr-cursor-manager/gr-cursor-manager.js index c0ea5a8d67..f750cd268c 100644 --- a/polygerrit-ui/app/elements/shared/gr-cursor-manager/gr-cursor-manager.js +++ b/polygerrit-ui/app/elements/shared/gr-cursor-manager/gr-cursor-manager.js @@ -1,16 +1,19 @@ -// Copyright (C) 2016 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/** + * @license + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ (function() { 'use strict'; @@ -262,13 +265,15 @@ * @return {boolean} */ _targetIsVisible(top) { + const dims = this._getWindowDims(); return this.scrollBehavior === ScrollBehavior.KEEP_VISIBLE && - top > window.pageYOffset && - top < window.pageYOffset + window.innerHeight; + top > dims.pageYOffset && + top < dims.pageYOffset + dims.innerHeight; }, _calculateScrollToValue(top, target) { - return top - (window.innerHeight / 3) + (target.offsetHeight / 2); + const dims = this._getWindowDims(); + return top - (dims.innerHeight / 3) + (target.offsetHeight / 2); }, _scrollToTarget() { @@ -276,6 +281,7 @@ return; } + const dims = this._getWindowDims(); const top = this._getTop(this.target); const bottomIsVisible = this._targetHeight ? this._targetIsVisible(top + this._targetHeight) : true; @@ -286,7 +292,7 @@ // would get scrolled to is higher up than the current position. this // woulld cause less of the target content to be displayed than is // already. - if (bottomIsVisible || scrollToValue < window.scrollY) { + if (bottomIsVisible || scrollToValue < dims.scrollY) { return; } } @@ -295,7 +301,16 @@ // instead of half the inner height feels a bit better otherwise the // element appears to be below the center of the window even when it // isn't. - window.scrollTo(0, scrollToValue); + window.scrollTo(dims.scrollX, scrollToValue); + }, + + _getWindowDims() { + return { + scrollX: window.scrollX, + scrollY: window.scrollY, + innerHeight: window.innerHeight, + pageYOffset: window.pageYOffset, + }; }, }); })(); |