scroll.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // @ts-ignore
  2. import baron from 'baron';
  3. import $ from 'jquery';
  4. import coreModule from 'app/angular/core_module';
  5. const scrollBarHTML = `
  6. <div class="baron__track">
  7. <div class="baron__bar"></div>
  8. </div>
  9. `;
  10. const scrollRootClass = 'baron baron__root';
  11. const scrollerClass = 'baron__scroller';
  12. export function geminiScrollbar() {
  13. return {
  14. restrict: 'A',
  15. link: (scope: any, elem: any, attrs: any) => {
  16. let scrollRoot = elem.parent();
  17. const scroller = elem;
  18. if (attrs.grafanaScrollbar && attrs.grafanaScrollbar === 'scrollonroot') {
  19. scrollRoot = scroller;
  20. }
  21. scrollRoot.addClass(scrollRootClass);
  22. $(scrollBarHTML).appendTo(scrollRoot);
  23. elem.addClass(scrollerClass);
  24. const scrollParams = {
  25. root: scrollRoot[0],
  26. scroller: scroller[0],
  27. bar: '.baron__bar',
  28. barOnCls: '_scrollbar',
  29. scrollingCls: '_scrolling',
  30. track: '.baron__track',
  31. direction: 'v',
  32. };
  33. const scrollbar = baron(scrollParams);
  34. scope.$on('$destroy', () => {
  35. scrollbar.dispose();
  36. });
  37. },
  38. };
  39. }
  40. coreModule.directive('grafanaScrollbar', geminiScrollbar);