forked from patternfly/angular-patternfly
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap-select.directive.js
More file actions
47 lines (37 loc) · 1.33 KB
/
Copy pathbootstrap-select.directive.js
File metadata and controls
47 lines (37 loc) · 1.33 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
angular.module('patternfly.select').directive('pfBootstrapSelect', function () {
'use strict';
return {
restrict: 'A',
require: '?ngModel',
scope: {
selectPickerOptions: '=pfBootstrapSelect'
},
link: function (scope, element, attrs, ngModel) {
var optionCollectionList, optionCollectionExpr, optionCollection, $render = ngModel.$render;
var selectpickerRefresh = function (argument) {
scope.$applyAsync(function () {
element.selectpicker('refresh');
});
};
var selectpickerDestroy = function () {
element.selectpicker('destroy');
};
element.selectpicker(scope.selectPickerOptions);
ngModel.$render = function () {
$render.apply(this, arguments);
selectpickerRefresh();
};
if (attrs.ngOptions) {
optionCollectionList = attrs.ngOptions.split('in ');
optionCollectionExpr = optionCollectionList[optionCollectionList.length - 1].split(/track by|\|/);
optionCollection = optionCollectionExpr[0];
scope.$parent.$watchCollection(optionCollection, selectpickerRefresh);
}
if (attrs.ngModel) {
scope.$parent.$watch(attrs.ngModel, selectpickerRefresh);
}
attrs.$observe('disabled', selectpickerRefresh);
scope.$on('$destroy', selectpickerDestroy);
}
};
});