add current day style

This commit is contained in:
t1m0n 2015-10-19 12:03:28 +03:00
parent ca94663d4a
commit f8b762c481
7 changed files with 40 additions and 3 deletions

View File

@ -8,7 +8,8 @@
width: 224px; } width: 224px; }
.datepicker--body { .datepicker--body {
display: none; } display: none;
margin: -1px; }
.datepicker--body.active { .datepicker--body.active {
display: block; } display: block; }
@ -61,14 +62,22 @@
.datepicker--cell { .datepicker--cell {
border-radius: 2px; border-radius: 2px;
color: #333;
cursor: pointer; cursor: pointer;
display: flex; display: flex;
position: relative;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
width: 32px; width: 32px;
height: 32px; } height: 32px;
z-index: 1; }
.datepicker--cell:hover { .datepicker--cell:hover {
background: #eee; } background: #eee; }
.datepicker--cell.-current- {
color: #60C4F5;
border: 1px solid #60C4F5; }
.datepicker--cell.-current-:hover {
background: rgba(96, 196, 245, 0.05); }
.datepicker--cell-day.-another-month- { .datepicker--cell-day.-another-month- {
color: #ddd; } color: #ddd; }

View File

@ -47,6 +47,7 @@ var Datepicker;
this.currentDate = this.opts.start; this.currentDate = this.opts.start;
this.currentView = this.opts.defaultView; this.currentView = this.opts.defaultView;
this.selectedDate = '';
this.views = {}; this.views = {};
this.init() this.init()
@ -412,6 +413,7 @@ Datepicker.Cell = function () {
if (this.d.isWeekend(date.getDay())) _class += " -weekend-"; if (this.d.isWeekend(date.getDay())) _class += " -weekend-";
if (date.getMonth() != this.d.currentDate.getMonth()) _class += " -another-month-"; if (date.getMonth() != this.d.currentDate.getMonth()) _class += " -another-month-";
if (date.getDate() == new Date().getDate()) _class += ' -current-';
return '<div class="' + _class + '" data-date="' + date.getDate() + '">' + date.getDate() + '</div>'; return '<div class="' + _class + '" data-date="' + date.getDate() + '">' + date.getDate() + '</div>';
}, },
@ -438,8 +440,11 @@ Datepicker.Cell = function () {
_getMonthHtml: function (date) { _getMonthHtml: function (date) {
var _class = "datepicker--cell datepicker--cell-month", var _class = "datepicker--cell datepicker--cell-month",
d = Datepicker.getParsedDate(date), d = Datepicker.getParsedDate(date),
currentDate = new Date(),
loc = this.d.loc; loc = this.d.loc;
if (d.month == currentDate.getMonth() && d.year == currentDate.getFullYear()) _class += ' -current-';
return '<div class="' + _class + '" data-month="' + d.month + '">' + loc.months[d.month] + '</div>' return '<div class="' + _class + '" data-month="' + d.month + '">' + loc.months[d.month] + '</div>'
}, },
@ -466,6 +471,8 @@ Datepicker.Cell = function () {
_class += ' -another-decade-'; _class += ' -another-decade-';
} }
if (d.year == new Date().getFullYear()) _class += ' -current-';
return '<div class="' + _class + '" data-year="' + d.year + '">' + d.year + '</div>' return '<div class="' + _class + '" data-year="' + d.year + '">' + d.year + '</div>'
}, },

View File

@ -89,6 +89,7 @@
if (this.d.isWeekend(date.getDay())) _class += " -weekend-"; if (this.d.isWeekend(date.getDay())) _class += " -weekend-";
if (date.getMonth() != this.d.currentDate.getMonth()) _class += " -another-month-"; if (date.getMonth() != this.d.currentDate.getMonth()) _class += " -another-month-";
if (date.getDate() == new Date().getDate()) _class += ' -current-';
return '<div class="' + _class + '" data-date="' + date.getDate() + '">' + date.getDate() + '</div>'; return '<div class="' + _class + '" data-date="' + date.getDate() + '">' + date.getDate() + '</div>';
}, },
@ -115,8 +116,11 @@
_getMonthHtml: function (date) { _getMonthHtml: function (date) {
var _class = "datepicker--cell datepicker--cell-month", var _class = "datepicker--cell datepicker--cell-month",
d = Datepicker.getParsedDate(date), d = Datepicker.getParsedDate(date),
currentDate = new Date(),
loc = this.d.loc; loc = this.d.loc;
if (d.month == currentDate.getMonth() && d.year == currentDate.getFullYear()) _class += ' -current-';
return '<div class="' + _class + '" data-month="' + d.month + '">' + loc.months[d.month] + '</div>' return '<div class="' + _class + '" data-month="' + d.month + '">' + loc.months[d.month] + '</div>'
}, },
@ -143,6 +147,8 @@
_class += ' -another-decade-'; _class += ' -another-decade-';
} }
if (d.year == new Date().getFullYear()) _class += ' -current-';
return '<div class="' + _class + '" data-year="' + d.year + '">' + d.year + '</div>' return '<div class="' + _class + '" data-year="' + d.year + '">' + d.year + '</div>'
}, },

View File

@ -47,6 +47,7 @@ var Datepicker;
this.currentDate = this.opts.start; this.currentDate = this.opts.start;
this.currentView = this.opts.defaultView; this.currentView = this.opts.defaultView;
this.selectedDate = '';
this.views = {}; this.views = {};
this.init() this.init()

View File

@ -11,16 +11,28 @@
.datepicker--cell { .datepicker--cell {
border-radius: $datepickerBorderRadius; border-radius: $datepickerBorderRadius;
color: $textColor;
cursor: pointer; cursor: pointer;
display: flex; display: flex;
position: relative;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
width: $dayCellSize; width: $dayCellSize;
height: $dayCellSize; height: $dayCellSize;
z-index: 1;
&:hover { &:hover {
background: $colorCellHover; background: $colorCellHover;
} }
&.-current- {
color: $colorCellCurrent;
border: 1px solid $colorCellCurrent;
&:hover {
background: rgba($colorCellCurrent, .05);
}
}
} }
// Day cell // Day cell

View File

@ -16,6 +16,7 @@
.datepicker--body { .datepicker--body {
display: none; display: none;
margin: -1px;
&.active { &.active {
display: block; display: block;

View File

@ -2,6 +2,7 @@ $dayCellSize: 32px;
$datepickerWidth: 7 * $dayCellSize; $datepickerWidth: 7 * $dayCellSize;
$datepickerBorderRadius: 2px; $datepickerBorderRadius: 2px;
$yearsPerRow: 4; $yearsPerRow: 4;
$textColor: #333;
$navigationHeight: 32px; $navigationHeight: 32px;
@ -10,6 +11,6 @@ $colorGrey: #ddd;
$colorAnotherMonth: #ddd; $colorAnotherMonth: #ddd;
$colorCellHover: #eee; $colorCellHover: #eee;
$colorCellCurrent: ''; $colorCellCurrent: #60C4F5;
$colorCellSelected: ''; $colorCellSelected: '';
$colorCellWeekend: ''; $colorCellWeekend: '';