diff --git a/src/ui/public/directives/__tests__/fixed_scroll.js b/src/ui/public/directives/__tests__/fixed_scroll.js index 7bcf4467ab740..13cddce494fbd 100644 --- a/src/ui/public/directives/__tests__/fixed_scroll.js +++ b/src/ui/public/directives/__tests__/fixed_scroll.js @@ -12,6 +12,11 @@ describe('FixedScroll directive', function () { let trash = []; beforeEach(ngMock.module('kibana')); + beforeEach(ngMock.module(function ($provide) { + $provide.service('debounce', () => { + return targetFunction => targetFunction; + }); + })); beforeEach(ngMock.inject(function ($compile, $rootScope) { compile = function (ratioY, ratioX) { diff --git a/src/ui/public/doc_viewer/doc_viewer.js b/src/ui/public/doc_viewer/doc_viewer.js index 009a6f8ef5bbe..daf4f9a988160 100644 --- a/src/ui/public/doc_viewer/doc_viewer.js +++ b/src/ui/public/doc_viewer/doc_viewer.js @@ -30,7 +30,7 @@ uiModules.get('kibana') `); $tabs.append($tab); const $viewAttrs = 'hit="hit" index-pattern="indexPattern" filter="filter" columns="columns"'; - const $ext = $(` + const $ext = $(` `); $ext.html(view.directive.template); $content.append($ext); diff --git a/src/ui/public/fixed_scroll.js b/src/ui/public/fixed_scroll.js index 786645af80ad4..09963b82870c0 100644 --- a/src/ui/public/fixed_scroll.js +++ b/src/ui/public/fixed_scroll.js @@ -4,9 +4,14 @@ import uiModules from 'ui/modules'; const SCROLLER_HEIGHT = 20; +/** + * This directive adds a fixed horizontal scrollbar to the bottom of the window that proxies its scroll events + * to the target element's real scrollbar. This is useful when the target element's horizontal scrollbar + * might be waaaay down the page, like the doc table on Discover. + */ uiModules .get('kibana') -.directive('fixedScroll', function ($timeout) { +.directive('fixedScroll', function (debounce) { return { restrict: 'A', link: function ($scope, $el) { @@ -98,11 +103,21 @@ uiModules listen(); } - // reset when the width or scrollWidth of the $el changes - $scope.$watchMulti([ - function () { return $el.prop('scrollWidth'); }, - function () { return $el.width(); } - ], setup); + let width; + let scrollWidth; + function checkWidth() { + const newScrollWidth = $el.prop('scrollWidth'); + const newWidth = $el.width(); + + if (scrollWidth !== newScrollWidth || width !== newWidth) { + setup(); + + scrollWidth = newScrollWidth; + width = newWidth; + } + } + + $scope.$watch(debounce(checkWidth, 100)); // cleanup when the scope is destroyed $scope.$on('$destroy', function () {