-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvertiCal.js
96 lines (83 loc) · 3.07 KB
/
vertiCal.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
84
85
86
87
88
89
90
91
92
93
94
95
96
VertiCal = {};
Meteor.startup(function(){
Session.set('vertiCalStartDate', moment().format('MM/DD/YYYY') );
Session.set('vertiCalSelectedDate', moment().format('MM/DD/YYYY') );
});
Template.vertiCal.rendered = function(){
$('#vertiCalScrollable').bind('mousewheel',function(event){
if (event.originalEvent.wheelDelta >= 0) {
Session.set('vertiCalStartDate',
moment(Session.get("vertiCalStartDate")).add(-1, 'days').format('MM/DD/YYYY')
);
}
else {
Session.set('vertiCalStartDate',
moment(Session.get("vertiCalStartDate")).add(1, 'days').format('MM/DD/YYYY')
);
}
event.preventDefault();
});
}
Template.vertiCal.dates = function(){
var num = this.numDays ? this.numDays : 7;
var indexs = [];
for( i = 0; i < num; i++ ){
indexs.push(i);
}
return indexs;
}
Template.vertiCalDefaultHeader.text = function(){
return moment(Session.get("vertiCalStartDate")).format('MMMM YYYY');
}
Template.vertiCalDefaultDateContent.active = function(){
var current = moment(Session.get("vertiCalStartDate")).add(parseInt(this), 'days');
var selected = Session.get("vertiCalSelectedDate");
return current.isSame(selected,"day") ? "active" : "";
}
Template.vertiCalDefaultDateContent.customBtnContents = function(){
return VertiCal.dateBtnContentsTemplate;
}
Template.vertiCalDefaultDateContent.text = function(){
var current = moment(Session.get("vertiCalStartDate")).add(parseInt(this), 'days');
var start = moment(Session.get("vertiCalStartDate"));
return current.isSame(start,"month") ? current.format("Do") : current.format("MMM Do");
}
Template.vertiCalDefaultDateContent.events({
'click': function(event){
Session.set("vertiCalSelectedDate",
moment(Session.get("vertiCalStartDate")).add(parseInt(this),'days').format("MM/DD/YYYY")
);
}
});
Template.vertiCalDefaultUpArrow.events({
'click': function(event){
var newDate = moment(Session.get('vertiCalStartDate')).add(-1,'days');
Session.set('vertiCalStartDate', newDate.format('MM/DD/YYYY'));
}
});
Template.vertiCalDefaultDownArrow.events({
'click': function(event){
var newDate = moment(Session.get('vertiCalStartDate')).add(1,'days');
Session.set('vertiCalStartDate', newDate.format('MM/DD/YYYY') );
}
});
Template.vertiCalJumpToToday.events({
'click #vertiCalJumpToToday': function(event){
Session.set('vertiCalStartDate', moment().format('MM/DD/YYYY') );
Session.set("vertiCalSelectedDate", moment().format('MM/DD/YYYY') );
}
});
Template.vertiCalJumpToDate.value = function(){
return Session.get('vertiCalStartDate');
}
Template.vertiCalJumpToDate.events({
'click #jumpToDateSubmit': function(event ){
if( moment($('#jumpToDateInput').val()).isValid() ){
Session.set('vertiCalStartDate', moment($('#jumpToDateInput').val()).format('MM/DD/YYYY') );
Session.set("vertiCalSelectedDate", moment($('#jumpToDateInput').val()).format('MM/DD/YYYY') );
}else{
Session.set('vertiCalStartDate', moment().format('MM/DD/YYYY') );
Session.set("vertiCalSelectedDate", moment().format('MM/DD/YYYY') );
}
}
});