-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTargetDate.js
More file actions
executable file
·83 lines (68 loc) · 2.75 KB
/
TargetDate.js
File metadata and controls
executable file
·83 lines (68 loc) · 2.75 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
/*
The Countdown Package is a set of widgets for a user-configurable JavaScript Timer
Copyright (C) 2011 Samuel B. Johnson
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
dojo.provide("net.samuelbjohnson.jsdev.countdown.TargetDate");
dojo.require("dijit.form.DateTextBox");
dojo.require("dijit.form.TimeTextBox");
dojo.declare("net.samuelbjohnson.jsdev.countdown.TargetDate", null, {
constructor: function(/*node*/containerNode) {
var date = new Date(2011, 1, 18);
this.containerNode = containerNode;
this.getDate = function() {
return date;
};
this.setDate = function(/*date*/ newDate) {
date = newDate;
this.dateNode.innerHTML = newDate;
};
this.buildHtml();
this.setupConnections();
},
buildHtml: function() {
dojo.addClass(this.containerNode, "timerTargetDateContainer");
this.labelNode = dojo.create("div", {class: "timerTargetDateLabel"}, this.containerNode);
this.labelNode.innerHTML = "Counting Down To:";
this.formNode = dojo.create("div", {class: "timerTargetDateForm"}, this.containerNode);
this.dateField = new dijit.form.DateTextBox({
}, dojo.create("div", {}, this.formNode));
this.timeField = new dijit.form.TimeTextBox({
}, dojo.create("div", {}, this.formNode));
this.dateNode = dojo.create("div", {class: "timerTargetDateDate"}, this.containerNode);
this.dateNode.innerHTML = this.getDate();
},
setupConnections: function() {
dojo.connect(this.dateField, "onChange", this, this.onChange);
dojo.connect(this.timeField, "onChange", this, this.onChange);
},
onChange: function() {
var day, time, tempDate;
console.log('change registered');
day = this.dateField.value;
time = this.timeField.value;
tempDate = this.getDate();
if (day) {
tempDate = new Date(day);
}
if (time) {
tempDate.setHours(time.getHours());
tempDate.setMinutes(time.getMinutes());
tempDate.setSeconds(time.getSeconds());
} else {
tempDate.setHours(this.getDate().getHours());
tempDate.setMinutes(this.getDate().getMinutes());
tempDate.setSeconds(this.getDate().getSeconds());
}
this.setDate(tempDate);
}
});