forked from ziscloud/angular-slimscroll
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-slimscroll.js
More file actions
50 lines (40 loc) · 1.3 KB
/
angular-slimscroll.js
File metadata and controls
50 lines (40 loc) · 1.3 KB
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
angular.module('ui.slimscroll', []).directive('slimscroll', function () {
'use strict';
return {
restrict: 'A',
link: function ($scope, $elem, $attr) {
var off = [];
var option = {};
var refresh = function () {
if (angular.isDefined($attr.slimscroll)) {
option = $scope.$eval($attr.slimscroll) || {};
} else if ($attr.slimscrollOption) {
option = $scope.$eval($attr.slimscrollOption) || {};
}
var el = angular.element($elem);
el.slimScroll({destroy: true});
el.slimScroll(option);
};
var registerWatch = function () {
if (angular.isDefined($attr.slimscroll) && !option.noWatch) {
off.push($scope.$watchCollection($attr.slimscroll, refresh));
}
if ($attr.slimscrollWatch) {
off.push($scope.$watchCollection($attr.slimscrollWatch, refresh));
}
if ($attr.slimscrolllistento) {
off.push($scope.$on($attr.slimscrolllistento, refresh));
}
};
var destructor = function () {
angular.element($elem).slimScroll({destroy: true});
off.forEach(function (unbind) {
unbind();
});
off = null;
};
off.push($scope.$on('$destroy', destructor));
registerWatch();
}
};
});