-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (43 loc) · 1.22 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
var Ps = require('perfect-scrollbar');
var angular = require('angular');
require('./app.css');
// Export globally at user request
global.PerfectScrollbar = Ps;
module.exports = 'angular-perfect-scrollbar-2';
angular.module(module.exports, [])
.directive('perfectScrollbar', ['$parse', function ($parse) {
return {
restrict: 'EA',
transclude: true,
template: '<div><div ng-transclude></div></div>',
replace: true,
link: function (scope, elem, attr) {
var scroll_opts = $parse(attr['opts'])(scope);
var el = elem[0];
Ps.initialize(el, scroll_opts);
obs_opts = {
childList: true,
subtree: true,
characterData: true,
};
if(typeof MutationObserver === "function") {
obs = new MutationObserver(function () {
Ps.update(el);
});
obs.observe(el, obs_opts);
} else {
console.warn(module.exports + ': Your browser does not support MutationObserver.')
}
scope.$watch('update', function (n, o) {
if (n) {
Ps.update(el);
scope.update = false;
}
});
scope.$on('$destroy', function () {
obs.disconnect();
Ps.destroy(el);
});
}
};
}]);