PageSourceSearch

https://songtr.ee/app/libs/angular-perfect-scrollbar.js

js songtr.ee collected 2026-10-01 12:22:41 UTC 2,354 bytes, 73 lines download raw bytes

1angular.module('perfect_scrollbar', []).directive('perfectScrollbar',
2  ['$parse', '$window', function($parse, $window) {
3  var psOptions = [
4    'wheelSpeed', 'wheelPropagation', 'minScrollbarLength', 'useBothWheelAxes',
5    'useKeyboard', 'suppressScrollX', 'suppressScrollY', 'scrollXMarginOffset',
6    'scrollYMarginOffset', 'includePadding'//, 'onScroll', 'scrollDown'
7  ];
8
9  return {
10    restrict: 'EA',
11    transclude: true,
12    template: '<div><div ng-transclude></div></div>',
13    replace: true,
14    link: function($scope, $elem, $attr) {
15      var jqWindow = angular.element($window);
16      var options = {};
17
18      for (var i=0, l=psOptions.length; i<l; i++) {
19        var opt = psOptions[i];
20        if ($attr[opt] !== undefined) {
21          options[opt] = $parse($attr[opt])();
22        }
23      }
24
25      $scope.$evalAsync(function() {
26        $elem.perfectScrollbar(options);
27        var onScrollHandler = $parse($attr.onScroll)
28        $elem.scroll(function(){
29          var scrollTop = $elem.scrollTop()
30          var scrollHeight = $elem.prop('scrollHeight') - $elem.height()
31          $scope.$apply(function() {
32            onScrollHandler($scope, {
33              scrollTop: scrollTop,
34              scrollHeight: scrollHeight
35            })
36          })
37        });
38      });
39
40      function update(event) {
41        $scope.$evalAsync(function() {
42          if ($attr.scrollDown == 'true' && event != 'mouseenter') {
43            setTimeout(function () {
44              $($elem).scrollTop($($elem).prop("scrollHeight"));
45            }, 100);
46          }
47          $elem.perfectScrollbar('update');
48        });
49      }
50
51      // This is necessary when you don't watch anything with the scrollbar
52      $elem.bind('mouseenter', update('mouseenter'));
53
54      // Possible future improvement - check the type here and use the appropriate watch for non-arrays
55      if ($attr.refreshOnChange) {
56        $scope.$watchCollection($attr.refreshOnChange, function() {
57          update();
58        });
59      }
60
61      // this is from a pull request - I am not totally sure what the original issue is but seems harmless
62      if ($attr.refreshOnResize) {
63        jqWindow.on('resize', update);
64      }
65
66      $elem.bind('$destroy', function() {
67        jqWindow.off('resize', update);
68        $elem.perfectScrollbar('destroy');
69      });
70
71    }
72  };
73}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.