-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhiClockDirective.js
46 lines (40 loc) · 1.2 KB
/
hiClockDirective.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
function HiClockDirective(){
return {
restrict: 'E',
templateUrl: 'templates/hi-clock.html', //set the template URL
scope: {
'ngTime' : '=',
'ngDate' : '='
},
link: function (scope, element) {
[].forEach.call(element,function(el){
var clock = new HiClock(el);
var itsApplying = false;
scope.$watch("ngTime", function( newValue, oldValue){
if(itsApplying) return;
clock.inputElement.value = newValue || "";
});
scope.$watch("ngDate", function(newValue, oldValue){
if(itsApplying) return;
var date = newValue;
if( date && date instanceof Date ){
clock
.setHour(date.getHours(), true)
.setMin(date.getMinutes(), true);
}else{
clock.inputElement.value = "";
}
});
setTimeout(function(){
clock.on("change" , function(){
scope.ngTime = clock.getTime();
scope.ngDate = clock.getDate();
itsApplying = true;
scope.$apply();
itsApplying = false;
});
},100);
});
}
};
}