From 1d132c7b2b3d8ea95ec081bb3b1183376ed1a5fe Mon Sep 17 00:00:00 2001 From: Viktar Donich Date: Mon, 21 May 2018 12:13:39 -0700 Subject: [PATCH] Improve page scrolling performance part 1 Remove unnecessary scroll event listener for tooltip-enabled elements, which should only be set only when tooltip is shown. Given the number of such elements, this resulted if noticeable performance boost when removed. Bug: Issue 8825 Change-Id: Id627d727702bb9ea29efdd99906909b59f42cbde --- .../gr-tooltip-behavior/gr-tooltip-behavior.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/polygerrit-ui/app/behaviors/gr-tooltip-behavior/gr-tooltip-behavior.js b/polygerrit-ui/app/behaviors/gr-tooltip-behavior/gr-tooltip-behavior.js index 4d536312ab..04d8b6e62b 100644 --- a/polygerrit-ui/app/behaviors/gr-tooltip-behavior/gr-tooltip-behavior.js +++ b/polygerrit-ui/app/behaviors/gr-tooltip-behavior/gr-tooltip-behavior.js @@ -51,7 +51,6 @@ detached() { this._handleHideTooltip(); - this.unlisten(window, 'scroll', '_handleWindowScroll'); }, _setupTooltipListeners() { @@ -59,9 +58,6 @@ this._hasSetupTooltipListeners = true; this.addEventListener('mouseenter', this._handleShowTooltip.bind(this)); - this.addEventListener('mouseleave', this._handleHideTooltip.bind(this)); - this.addEventListener('tap', this._handleHideTooltip.bind(this)); - this.listen(window, 'scroll', '_handleWindowScroll'); }, _handleShowTooltip(e) { @@ -91,6 +87,9 @@ tooltip.style.visibility = null; this._tooltip = tooltip; + this.listen(window, 'scroll', '_handleWindowScroll'); + this.listen(this, 'mouseleave', '_handleHideTooltip'); + this.listen(this, 'tap', '_handleHideTooltip'); }, _handleHideTooltip(e) { @@ -100,6 +99,9 @@ return; } + this.unlisten(window, 'scroll', '_handleWindowScroll'); + this.unlisten(this, 'mouseleave', '_handleHideTooltip'); + this.unlisten(this, 'tap', '_handleHideTooltip'); this.setAttribute('title', this._titleText); if (this._tooltip && this._tooltip.parentNode) { this._tooltip.parentNode.removeChild(this._tooltip);