-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathangular-bootstrap-datetimepicker-directive.js
72 lines (59 loc) · 1.66 KB
/
angular-bootstrap-datetimepicker-directive.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use strict';
angular
.module('datetimepicker', [])
.provider('datetimepicker', function () {
var default_options = {};
this.setOptions = function (options) {
default_options = options;
};
this.$get = function () {
return {
getOptions: function () {
return default_options;
}
};
};
})
.directive('datetimepicker', [
'$timeout',
'datetimepicker',
function ($timeout,
datetimepicker) {
var default_options = datetimepicker.getOptions();
return {
require : '?ngModel',
restrict: 'AE',
scope : {
datetimepickerOptions: '@'
},
link : function ($scope, $element, $attrs, ngModelCtrl) {
var passed_in_options = $scope.$eval($attrs.datetimepickerOptions);
var options = jQuery.extend({}, default_options, passed_in_options);
$element
.on('dp.change', function (e) {
if (ngModelCtrl) {
$timeout(function () {
ngModelCtrl.$setViewValue(e.target.value);
});
}
})
.datetimepicker(options);
function setPickerValue() {
var date = options.defaultDate || null;
if (ngModelCtrl && ngModelCtrl.$viewValue) {
date = ngModelCtrl.$viewValue;
}
$element
.data('DateTimePicker')
.date(date);
}
if (ngModelCtrl) {
ngModelCtrl.$render = function () {
setPickerValue();
};
}
setPickerValue();
}
};
}
]);