grafana/public/app/core/components/scroll/scroll.ts
Johannes Schill aac1b250af ux: When adding a new panel we should scroll to top until we figure o… (#10417)
* ux: When adding a new panel we should scroll to top until we figure out a better solution #10299

* ux: Use jquery to add smooth scrolling when scrolling up to add a panel, and make sure to pass the scope to the event emitter, #10299

* ux: Add a close button to the "New panel"-box and make sure you scroll to top every time you click "Add panel" #10299
2018-01-09 15:27:53 +01:00

40 lines
834 B
TypeScript

import PerfectScrollbar from 'perfect-scrollbar';
import coreModule from 'app/core/core_module';
import appEvents from 'app/core/app_events';
export function geminiScrollbar() {
return {
restrict: 'A',
link: function(scope, elem, attrs) {
let scrollbar = new PerfectScrollbar(elem[0]);
appEvents.on(
'smooth-scroll-top',
() => {
elem.animate(
{
scrollTop: 0,
},
500
);
},
scope
);
scope.$on('$routeChangeSuccess', () => {
elem[0].scrollTop = 0;
});
scope.$on('$routeUpdate', () => {
elem[0].scrollTop = 0;
});
scope.$on('$destroy', () => {
scrollbar.destroy();
});
},
};
}
coreModule.directive('grafanaScrollbar', geminiScrollbar);