Skip to content

Commit 5e06f4d

Browse files
committed
Mark current date with orange-ish background
1 parent 3c84820 commit 5e06f4d

File tree

5 files changed

+95
-4
lines changed

5 files changed

+95
-4
lines changed

build/build.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
@white: #fff;
1313
@linkColor: #08c;
1414
@btnPrimaryBackground: @linkColor;
15+
@orange: #f89406;
1516

1617
// Mixins
1718

css/datepicker.css

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,55 @@
7979
color: #999999;
8080
cursor: default;
8181
}
82+
.datepicker td.today,
83+
.datepicker td.today:hover,
84+
.datepicker td.today.disabled,
85+
.datepicker td.today.disabled:hover {
86+
background-color: #fde19a;
87+
background-image: -moz-linear-gradient(top, #fdd49a, #fdf59a);
88+
background-image: -ms-linear-gradient(top, #fdd49a, #fdf59a);
89+
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#fdd49a), to(#fdf59a));
90+
background-image: -webkit-linear-gradient(top, #fdd49a, #fdf59a);
91+
background-image: -o-linear-gradient(top, #fdd49a, #fdf59a);
92+
background-image: linear-gradient(top, #fdd49a, #fdf59a);
93+
background-repeat: repeat-x;
94+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fdd49a', endColorstr='#fdf59a', GradientType=0);
95+
border-color: #fdf59a #fdf59a #fbed50;
96+
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
97+
filter: progid:dximagetransform.microsoft.gradient(enabled=false);
98+
}
99+
.datepicker td.today:hover,
100+
.datepicker td.today:hover:hover,
101+
.datepicker td.today.disabled:hover,
102+
.datepicker td.today.disabled:hover:hover,
103+
.datepicker td.today:active,
104+
.datepicker td.today:hover:active,
105+
.datepicker td.today.disabled:active,
106+
.datepicker td.today.disabled:hover:active,
107+
.datepicker td.today.active,
108+
.datepicker td.today:hover.active,
109+
.datepicker td.today.disabled.active,
110+
.datepicker td.today.disabled:hover.active,
111+
.datepicker td.today.disabled,
112+
.datepicker td.today:hover.disabled,
113+
.datepicker td.today.disabled.disabled,
114+
.datepicker td.today.disabled:hover.disabled,
115+
.datepicker td.today[disabled],
116+
.datepicker td.today:hover[disabled],
117+
.datepicker td.today.disabled[disabled],
118+
.datepicker td.today.disabled:hover[disabled] {
119+
background-color: #fdf59a;
120+
}
121+
.datepicker td.today:active,
122+
.datepicker td.today:hover:active,
123+
.datepicker td.today.disabled:active,
124+
.datepicker td.today.disabled:hover:active,
125+
.datepicker td.today.active,
126+
.datepicker td.today:hover.active,
127+
.datepicker td.today.disabled.active,
128+
.datepicker td.today.disabled:hover.active {
129+
background-color: #fbf069 \9;
130+
}
82131
.datepicker td.active,
83132
.datepicker td.active:hover,
84133
.datepicker td.active.disabled,
@@ -208,10 +257,12 @@
208257
.datepicker th.switch {
209258
width: 145px;
210259
}
211-
.datepicker thead tr:first-child th {
260+
.datepicker thead tr:first-child th,
261+
.datepicker tfoot tr:first-child th {
212262
cursor: pointer;
213263
}
214-
.datepicker thead tr:first-child th:hover {
264+
.datepicker thead tr:first-child th:hover,
265+
.datepicker tfoot tr:first-child th:hover {
215266
background: #eeeeee;
216267
}
217268
.input-append.date .add-on i,

js/bootstrap-datepicker.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
function UTCDate(){
2424
return new Date(Date.UTC.apply(Date, arguments));
2525
}
26+
function UTCToday(){
27+
var today = new Date();
28+
return UTCDate(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate());
29+
}
2630

2731
// Picker object
2832

@@ -235,12 +239,13 @@
235239
startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() : -Infinity,
236240
endYear = this.endDate !== Infinity ? this.endDate.getUTCFullYear() : Infinity,
237241
endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() : Infinity,
238-
currentDate = this.date.valueOf();
242+
currentDate = this.date.valueOf(),
243+
today = UTCToday().valueOf();
239244
this.picker.find('.datepicker-days thead th:eq(1)')
240245
.text(dates[this.language].months[month]+' '+year);
241246
this.picker.find('tfoot th.today')
242247
.text(dates[this.language].today)
243-
.toggle(!!this.todayBtn);
248+
.toggle(this.todayBtn);
244249
this.updateNavArrows();
245250
this.fillMonths();
246251
var prevMonth = UTCDate(year, month-1, 28,0,0,0,0),
@@ -262,6 +267,9 @@
262267
} else if (prevMonth.getUTCFullYear() > year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() > month)) {
263268
clsName += ' new';
264269
}
270+
if (prevMonth.valueOf() == today) {
271+
clsName += ' today';
272+
}
265273
if (prevMonth.valueOf() == currentDate) {
266274
clsName += ' active';
267275
}

less/datepicker.less

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@
7272
color: @grayLight;
7373
cursor: default;
7474
}
75+
&.today,
76+
&.today:hover,
77+
&.today.disabled,
78+
&.today.disabled:hover {
79+
@todayBackground: lighten(@orange, 30%);
80+
.buttonBackground(@todayBackground, spin(@todayBackground, 20));
81+
}
7582
&.active,
7683
&.active:hover,
7784
&.active.disabled,

tests/suites/options.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,27 @@ test('Today Button: "linked" selects today\'s date', function(){
213213
datesEqual(dp.date, today);
214214
});
215215

216+
test('Today: today\'s date is highlighted when not active', patch_date(function(Date){
217+
Date.now = UTCDate(2012, 2, 15);
218+
var input = $('<input />')
219+
.appendTo('#qunit-fixture')
220+
.val('2012-03-05')
221+
.datepicker({
222+
format: 'yyyy-mm-dd'
223+
}),
224+
dp = input.data('datepicker'),
225+
picker = dp.picker,
226+
target;
227+
228+
input.focus();
229+
ok(picker.find('.datepicker-days').is(':visible'), 'Days view visible');
230+
equal(picker.find('.datepicker-days thead .switch').text(), 'March 2012', 'Title is "March 2012"');
231+
232+
target = picker.find('.datepicker-days tbody td:contains(15)');
233+
ok(target.hasClass('today'), 'Today is marked with "today" class');
234+
target = picker.find('.datepicker-days tbody td:contains(14)');
235+
ok(!target.hasClass('today'), 'Yesterday is not marked with "today" class');
236+
target = picker.find('.datepicker-days tbody td:contains(16)');
237+
ok(!target.hasClass('today'), 'Tomorrow is not marked with "today" class');
238+
}));
239+

0 commit comments

Comments
 (0)