Skip to content

Commit dfb6b64

Browse files
committed
Make today highlight optional
1 parent 5e06f4d commit dfb6b64

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ Boolean, "linked". Default: false
146146

147147
If true or "linked", displays a "Today" button at the bottom of the datepicker to select the current date. If true, the "Today" button will only move the current date into view; if "linked", the current date will also be selected.
148148

149+
### todayHighlight
150+
151+
Boolean. Default: false
152+
153+
If true, highlights the current date.
154+
149155
### keyboardNavigation
150156

151157
Boolean. Default: true

js/bootstrap-datepicker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
}
108108

109109
this.todayBtn = (options.todayBtn||this.element.data('date-today-btn')||false);
110+
this.todayHighlight = (options.todayHighlight||this.element.data('date-today-highlight')||false);
110111

111112
this.weekStart = ((options.weekStart||this.element.data('date-weekstart')||dates[this.language].weekStart||0) % 7);
112113
this.weekEnd = ((this.weekStart + 6) % 7);
@@ -267,7 +268,7 @@
267268
} else if (prevMonth.getUTCFullYear() > year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() > month)) {
268269
clsName += ' new';
269270
}
270-
if (prevMonth.valueOf() == today) {
271+
if (prevMonth.valueOf() == today && this.todayHighlight) {
271272
clsName += ' today';
272273
}
273274
if (prevMonth.valueOf() == currentDate) {

tests/suites/options.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ 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){
216+
test('Today Highlight: today\'s date is not highlighted by default', patch_date(function(Date){
217217
Date.now = UTCDate(2012, 2, 15);
218218
var input = $('<input />')
219219
.appendTo('#qunit-fixture')
@@ -229,6 +229,31 @@ test('Today: today\'s date is highlighted when not active', patch_date(function(
229229
ok(picker.find('.datepicker-days').is(':visible'), 'Days view visible');
230230
equal(picker.find('.datepicker-days thead .switch').text(), 'March 2012', 'Title is "March 2012"');
231231

232+
target = picker.find('.datepicker-days tbody td:contains(15)');
233+
ok(!target.hasClass('today'), 'Today is not 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+
240+
test('Today Highlight: today\'s date is highlighted when not active', patch_date(function(Date){
241+
Date.now = UTCDate(2012, 2, 15);
242+
var input = $('<input />')
243+
.appendTo('#qunit-fixture')
244+
.val('2012-03-05')
245+
.datepicker({
246+
format: 'yyyy-mm-dd',
247+
todayHighlight: true
248+
}),
249+
dp = input.data('datepicker'),
250+
picker = dp.picker,
251+
target;
252+
253+
input.focus();
254+
ok(picker.find('.datepicker-days').is(':visible'), 'Days view visible');
255+
equal(picker.find('.datepicker-days thead .switch').text(), 'March 2012', 'Title is "March 2012"');
256+
232257
target = picker.find('.datepicker-days tbody td:contains(15)');
233258
ok(target.hasClass('today'), 'Today is marked with "today" class');
234259
target = picker.find('.datepicker-days tbody td:contains(14)');

0 commit comments

Comments
 (0)