This repository has been archived by the owner on Feb 22, 2019. It is now read-only.
forked from stevermeister/angular-flipclock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-flipclock.js
83 lines (76 loc) · 3.75 KB
/
angular-flipclock.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
73
74
75
76
77
78
79
80
81
82
83
angular.module('angular-flipclock', [])
.directive('flipClock', ['$parse', function($parse) {
return {
replace: true,
template: '<div></div>',
restrict: 'E',
link: function(scope, element, attr) {
var optionKeys = [
'autostart', //(boolean) If this is set to false, the clock will not auto start. The default value is true.
'countdown', //(boolean) If this is set to true, the clock will count down instead of up. The default value is false.
'callbacks', //(object) An object of callback functions that are triggered at various times. For more information, view the callback documentation.
'classes', //(object) This is an object of CSS classes to use to append to DOM objects
'clockFace', // (string) This is the name of the clock that is used to build the clock display. The default value is HourlyCounter.
'defaultclockface', //(string) This is the default clock face to use if the defined clock face does not exist. The default value is HourlyCounter.
'showSeconds', //(boolean) If this is set to true, the clock will include seconds. The default value is true.
'defaultlanguage' //(string) This is the default langauge to use. The default value is english.
], options = {
callbacks: {}
},
clock,
methods = [
'start', //This method will start the clock just call the .start() method on an FlipClock object.
'stop', // This method will stop the clock just call the .stop() method on an FlipClock object.
'setTime', //This method will set the clock time after it has been instantiated just call the .setTime() method on an FlipClock object.
'setCountdown', //This method will change the clock from counting up or down.
'getTime' //To get the clock time after it has been instantiated just call the .getTime() method on an FlipClock object.
],
callbacks = [
'destroy', //This callback is triggered when the timer is destroyed
'create', // This callback is triggered when the clock face is created
'init', //This callback is triggered when the FlipClock object is initialized
'interval', //This callback is triggered with each interval of the timer
'start', //This callback is triggered when the clock is started
'stop', //This callback is triggered when the clock is stopped
'reset' // This callback is triggered when the timer has been reset
];
//set options from attributes
optionKeys.forEach(function(key) {
if(attr[key]){
switch(key.toLowerCase()){
case 'autostart':
case 'showseconds':
options[key] = attr[key] === 'false' ? false : true;
break;
case 'defaultclockface':
options['defaultClockFace'] = attr[key];
break;
case 'defaultlanguage':
options['defaultLanguage'] = attr[key];
break;
default:
options[key] = attr[key];
break;
}
}
});
//init callbacks
callbacks.forEach(function(callback) {
if(attr[callback]){
options.callbacks[callback] = function(){
$parse(attr[callback])(scope);
}
}
});
//generate clock object
//clock = new FlipClock(element, options);
clock = element.FlipClock(options);
//bind methods to the scope
methods.forEach(function(method) {
scope[method] = function(){
clock[method].apply(clock, arguments);
}
});
}
}
}]);