Skip to content

Commit

Permalink
Merge branch 'nsidc-option-default-view-date'
Browse files Browse the repository at this point in the history
  • Loading branch information
acrobat committed Jan 10, 2015
2 parents 41e06de + f5dd01b commit b88dc71
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
15 changes: 15 additions & 0 deletions docs/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,21 @@ String, Array. Default: []

Array of date strings or a single date string formatted in the given date format

.. _defaultviewdate:


defaultViewDate
---------------

Object with keys ``year``, ``month``, and ``day``. Default: today

Date to view when initially opening the calendar. The internal value of the date remains today as default, but when the datepicker is first opened the calendar will open to ``defaultViewDate`` rather than today. If this option is not used, "today" remains the default view date. If the given object is missing any of the required keys, their defaults are:

* ``year``: the current year
* ``month``: 1
* ``day``: 1


.. _enddate:

endDate
Expand Down
14 changes: 11 additions & 3 deletions js/bootstrap-datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@
// Picker object

var Datepicker = function(element, options){
this._process_options(options);

this.dates = new DateArray();
this.viewDate = UTCToday();
this.viewDate = this.o.defaultViewDate;
this.focusDate = null;

this._process_options(options);

this.element = $(element);
this.isInline = false;
this.isInput = this.element.is('input');
Expand Down Expand Up @@ -276,6 +276,14 @@
});
o.orientation.y = _plc[0] || 'auto';
}
if (o.defaultViewDate) {
var year = o.defaultViewDate.year || new Date().getFullYear();
var month = o.defaultViewDate.month || 0;
var day = o.defaultViewDate.day || 1;
o.defaultViewDate = UTCDate(year, month, day);
} else {
o.defaultViewDate = UTCToday();
}
o.showOnFocus = o.showOnFocus !== undefined ? o.showOnFocus : true;
},
_events: [],
Expand Down
16 changes: 16 additions & 0 deletions tests/suites/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -742,3 +742,19 @@ test('Container', function(){
input.focus();
equal(target.parent()[0], testContainer[0], 'Container is not the testContainer that was specificed');
});

test('Default View Date', function(){
var input = $('<input />')
.appendTo('#qunit-fixture')
.datepicker({
format: 'yyyy-mm-dd',
defaultViewDate: { year: 1977, month: 04, day: 25 }
}),
dp = input.data('datepicker'),
picker = dp.picker,
target;

input.focus();

equal(picker.find('.datepicker-days thead .datepicker-switch').text(), 'May 1977');
});

0 comments on commit b88dc71

Please sign in to comment.