Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**
66 changes: 53 additions & 13 deletions src/js/tempusdominus-bootstrap-4.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ const TempusDominusBootstrap4 = ($ => { // eslint-disable-line no-unused-vars
_updateMonths() {
const monthsView = this.widget.find('.datepicker-months'),
monthsViewHeader = monthsView.find('th'),
months = monthsView.find('tbody').find('span'), self = this;
months = monthsView.find('tbody').find('span'), self = this,
lastPickedDate = this._getLastPickedDate();

monthsViewHeader.eq(0).find('span').attr('title', this._options.tooltips.prevYear);
monthsViewHeader.eq(1).attr('title', this._options.tooltips.selectYear);
Expand All @@ -359,8 +360,8 @@ const TempusDominusBootstrap4 = ($ => { // eslint-disable-line no-unused-vars
}

months.removeClass('active');
if (this._getLastPickedDate().isSame(this._viewDate, 'y') && !this.unset) {
months.eq(this._getLastPickedDate().month()).addClass('active');
if (lastPickedDate && lastPickedDate.isSame(this._viewDate, 'y') && !this.unset) {
months.eq(lastPickedDate.month()).addClass('active');
}

months.each(function (index) {
Expand Down Expand Up @@ -417,7 +418,8 @@ const TempusDominusBootstrap4 = ($ => { // eslint-disable-line no-unused-vars
decadesViewHeader = decadesView.find('th'),
yearCaps = this._getStartEndYear(100, this._viewDate.year()),
startDecade = this._viewDate.clone().year(yearCaps[0]),
endDecade = this._viewDate.clone().year(yearCaps[1]);
endDecade = this._viewDate.clone().year(yearCaps[1]),
lastPickedDate = this._getLastPickedDate();
let minDateDecade = false,
maxDateDecade = false,
endDecadeYear,
Expand Down Expand Up @@ -448,7 +450,7 @@ const TempusDominusBootstrap4 = ($ => { // eslint-disable-line no-unused-vars
endDecadeYear = startDecade.year() + 11;
minDateDecade = this._options.minDate && this._options.minDate.isAfter(startDecade, 'y') && this._options.minDate.year() <= endDecadeYear;
maxDateDecade = this._options.maxDate && this._options.maxDate.isAfter(startDecade, 'y') && this._options.maxDate.year() <= endDecadeYear;
html += `<span data-action="selectDecade" class="decade${this._getLastPickedDate().isAfter(startDecade) && this._getLastPickedDate().year() <= endDecadeYear ? ' active' : ''}${!this._isValid(startDecade, 'y') && !minDateDecade && !maxDateDecade ? ' disabled' : ''}" data-selection="${startDecade.year() + 6}">${startDecade.year()}</span>`;
html += `<span data-action="selectDecade" class="decade${lastPickedDate && lastPickedDate.isAfter(startDecade) && lastPickedDate.year() <= endDecadeYear ? ' active' : ''}${!this._isValid(startDecade, 'y') && !minDateDecade && !maxDateDecade ? ' disabled' : ''}" data-selection="${startDecade.year() + 6}">${startDecade.year()}</span>`;
startDecade.add(10, 'y');
}
html += `<span data-action="selectDecade" class="decade old" data-selection="${startDecade.year() + 6}">${startDecade.year()}</span>`;
Expand Down Expand Up @@ -590,23 +592,24 @@ const TempusDominusBootstrap4 = ($ => { // eslint-disable-line no-unused-vars

_fillTime() {
let toggle, newDate;
const timeComponents = this.widget.find('.timepicker span[data-time-component]');
const timeComponents = this.widget.find('.timepicker span[data-time-component]'),
lastPickedDate = this._getLastPickedDate();

if (!this.use24Hours) {
toggle = this.widget.find('.timepicker [data-action=togglePeriod]');
newDate = this._getLastPickedDate().clone().add(this._getLastPickedDate().hours() >= 12 ? -12 : 12, 'h');
newDate = lastPickedDate ? lastPickedDate.clone().add(lastPickedDate.hours() >= 12 ? -12 : 12, 'h') : void 0;

toggle.text(this._getLastPickedDate().format('A'));
lastPickedDate && toggle.text(lastPickedDate.format('A'));

if (this._isValid(newDate, 'h')) {
toggle.removeClass('disabled');
} else {
toggle.addClass('disabled');
}
}
timeComponents.filter('[data-time-component=hours]').text(this._getLastPickedDate().format(`${this.use24Hours ? 'HH' : 'hh'}`));
timeComponents.filter('[data-time-component=minutes]').text(this._getLastPickedDate().format('mm'));
timeComponents.filter('[data-time-component=seconds]').text(this._getLastPickedDate().format('ss'));
lastPickedDate && timeComponents.filter('[data-time-component=hours]').text(lastPickedDate.format(`${this.use24Hours ? 'HH' : 'hh'}`));
lastPickedDate && timeComponents.filter('[data-time-component=minutes]').text(lastPickedDate.format('mm'));
lastPickedDate && timeComponents.filter('[data-time-component=seconds]').text(lastPickedDate.format('ss'));

this._fillHours();
this._fillMinutes();
Expand Down Expand Up @@ -716,48 +719,84 @@ const TempusDominusBootstrap4 = ($ => { // eslint-disable-line no-unused-vars
}
case 'incrementHours':
{
if (!lastPicked) {
break;
}
const newDate = lastPicked.clone().add(1, 'h');
if (this._isValid(newDate, 'h')) {
if (this._getLastPickedDateIndex() < 0) {
this.date(newDate);
}
this._setValue(newDate, this._getLastPickedDateIndex());
}
break;
}
case 'incrementMinutes':
{
if (!lastPicked) {
break;
}
const newDate = lastPicked.clone().add(this._options.stepping, 'm');
if (this._isValid(newDate, 'm')) {
if (this._getLastPickedDateIndex() < 0) {
this.date(newDate);
}
this._setValue(newDate, this._getLastPickedDateIndex());
}
break;
}
case 'incrementSeconds':
{
if (!lastPicked) {
break;
}
const newDate = lastPicked.clone().add(1, 's');
if (this._isValid(newDate, 's')) {
if (this._getLastPickedDateIndex() < 0) {
this.date(newDate);
}
this._setValue(newDate, this._getLastPickedDateIndex());
}
break;
}
case 'decrementHours':
{
if (!lastPicked) {
break;
}
const newDate = lastPicked.clone().subtract(1, 'h');
if (this._isValid(newDate, 'h')) {
if (this._getLastPickedDateIndex() < 0) {
this.date(newDate);
}
this._setValue(newDate, this._getLastPickedDateIndex());
}
break;
}
case 'decrementMinutes':
{
if (!lastPicked) {
break;
}
const newDate = lastPicked.clone().subtract(this._options.stepping, 'm');
if (this._isValid(newDate, 'm')) {
if (this._getLastPickedDateIndex() < 0) {
this.date(newDate);
}
this._setValue(newDate, this._getLastPickedDateIndex());
}
break;
}
case 'decrementSeconds':
{
if (!lastPicked) {
break;
}
const newDate = lastPicked.clone().subtract(1, 's');
if (this._isValid(newDate, 's')) {
if (this._getLastPickedDateIndex() < 0) {
this.date(newDate);
}
this._setValue(newDate, this._getLastPickedDateIndex());
}
break;
Expand Down Expand Up @@ -907,16 +946,17 @@ const TempusDominusBootstrap4 = ($ => { // eslint-disable-line no-unused-vars
this.widget.remove();
this.widget = false;

const lastPickedDate = this._getLastPickedDate();
this._notifyEvent({
type: DateTimePicker.Event.HIDE,
date: this._getLastPickedDate().clone()
date: lastPickedDate ? lastPickedDate.clone() : void 0
});

if (this.input !== undefined) {
this.input.blur();
}

this._viewDate = this._getLastPickedDate().clone();
this._viewDate = lastPickedDate ? lastPickedDate.clone() : void 0;
}

show() {
Expand Down