-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhiClockDirective.ionic.js
65 lines (49 loc) · 1.47 KB
/
hiClockDirective.ionic.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
function HiClockDirective($ionicPlatform) {
function RegisterBackButton(clock) {
var desregister = $ionicPlatform.registerBackButtonAction(function(e) {
desregister();
clock.hide();
e.preventDefault();
return false;
}, 999);
}
return {
restrict: 'E',
templateUrl: 'templates/hi-clock.html',
scope: {
ngTime: '=',
ngDate: '='
},
link: function(scope, element) {
[].forEach.call(element, function(el) {
var clock = new HiClock(el);
clock.on("show", RegisterBackButton.bind(null, clock));
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);
});
}
};
}