Repository navigation
Expand file tree
/
Copy pathdirectives.js
More file actions
152 lines (129 loc) · 3.96 KB
/
Copy pathdirectives.js
File metadata and controls
152 lines (129 loc) · 3.96 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// mostly taken from http://www.codinginsight.com/angularjs-and-pickadate/
/*jshint unused: false*/
angular.module('angular-datepicker', [])
.directive('pickADate', [ '$document', function($document) {
return {
restrict: "A",
scope: {
pickADate: '=',
pickADateOptions: '='
},
link: function(scope, element, attrs) {
var options = scope.pickADateOptions || {};
var userOnSet = options.onSet;
function onSet(e) {
if (typeof userOnSet === 'function') {
userOnSet.apply(this, arguments);
}
// we are coming from $watch or link setup
if (scope.$$phase || scope.$root.$$phase) {
return;
}
var select = element.pickadate('picker').get('select'); // selected date
if (select) {
scope.$apply(function() {
if (e.hasOwnProperty('clear')) {
scope.pickADate = null;
return;
}
if (!scope.pickADate || typeof scope.pickADate === 'string') {
scope.pickADate = new Date(0);
}
scope.pickADate.setYear(select.obj.getFullYear());
scope.pickADate.setDate(select.obj.getDate());
scope.pickADate.setMonth(select.obj.getMonth());
});
}
}
var userOnOpen = options.onOpen;
function onOpen(e) {
if (typeof userOnOpen === 'function') {
userOnOpen.apply(this, arguments);
}
}
var userOnClose = options.onClose;
function onClose(e) {
if (typeof userOnClose === 'function') {
userOnClose.apply(this, arguments);
}
}
element.bind('click', function(event) {
event.stopPropagation();
});
$document.bind('click', function(){
element.pickadate('picker').close();
});
element.pickadate(angular.extend(options, {
onOpen: onOpen,
onSet: onSet,
onClose: onClose,
container: $document.body
}));
setTimeout(function() {
if (scope.pickADate) {
element.pickadate('picker').set('select', scope.pickADate);
}
}, 1000);
}
};
}])
.directive('pickATime', ['$document', function($document) {
return {
restrict: "A",
scope: {
pickATime: '=',
pickATimeOptions: '='
},
link: function(scope, element, attrs) {
var options = scope.pickATimeOptions || {};
var userOnSet = options.onSet;
function onSet(e) {
if (typeof userOnSet === 'function') {
userOnSet.apply(this, arguments);
}
// we are coming from $watch or link setup
if (scope.$$phase || scope.$root.$$phase) {
return;
}
var select = element.pickatime('picker').get('select'); // selected date
if (select) {
scope.$apply(function() {
if (e.hasOwnProperty('clear')) {
scope.pickATime = null;
return;
}
if (!scope.pickATime || typeof scope.pickATime === 'string') {
scope.pickATime = new Date();
}
scope.pickATime.setHours(select.hour);
scope.pickATime.setMinutes(select.mins);
scope.pickATime.setSeconds(0);
scope.pickATime.setMilliseconds(0);
});
}
}
var userOnClose = options.onClose;
function onClose(e) {
if (typeof userOnClose === 'function') {
userOnClose.apply(this, arguments);
}
}
element.bind('click', function(event) {
event.stopPropagation();
});
$document.bind('click', function(){
element.pickatime('picker').close();
});
element.pickatime(angular.extend(options, {
onSet: onSet,
onClose: onClose,
container: $document.body
}));
setTimeout(function() {
if (scope.pickATime) {
element.pickatime('picker').set('select', scope.pickATime);
}
}, 1000);
}
};
}]);