Skip to content

Commit 41fd3fb

Browse files
committed
feat(DateObject, html, css): Current date has light gray background in week view.
The current date has a light gray background only in the week view. If the current date is selected, then the .active date highligh overrides the light gray background. Closes #202, #249
1 parent f993d20 commit 41fd3fb

9 files changed

+52
-10
lines changed

gulpfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ gulp.task('templatecache', function () {
7676
.pipe(htmlMin({removeComments: true}))
7777
.pipe(templateCache('datetimepicker.templates.js', {
7878
base: path.join(__dirname, 'src'),
79+
modulesystem: 'IIFE',
7980
module: 'ui.bootstrap.datetimepicker'
8081
}))
8182
.pipe(gulp.dest('src/js'))
@@ -111,7 +112,6 @@ gulp.task('test', ['lint', 'css-lint'], function (done) {
111112
})
112113

113114
gulp.task('default', ['complexity', 'test'])
114-
gulp.task('css-build', ['scss', 'css-lint'])
115115

116116
function testConfig (options) {
117117
var travisDefaultOptions = {

src/css/datetimepicker.css

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/css/datetimepicker.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/datetimepicker.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@
413413
return this.utcDateValue + localOffset
414414
}
415415

416-
var validProperties = ['utcDateValue', 'localDateValue', 'display', 'active', 'selectable', 'past', 'future']
416+
var validProperties = ['utcDateValue', 'display', 'active', 'selectable', 'past', 'future']
417417

418418
var constructorObject = arguments[0]
419419

@@ -422,6 +422,8 @@
422422
}).forEach(function (key) {
423423
this[key] = constructorObject[key]
424424
}, this)
425+
426+
this.isToday = moment().utc().local().format('YYYY-MM-DD') === moment.utc(this.utcDateValue).format('YYYY-MM-DD')
425427
}
426428

427429
return directiveDefinition

src/js/datetimepicker.templates.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
}(this, function (angular) {
2626
'use strict'
2727
angular.module('ui.bootstrap.datetimepicker').run(['$templateCache', function ($templateCache) {
28-
$templateCache.put('templates/datetimepicker.html', '<div class="datetimepicker table-responsive">\n <table class="table table-condensed {{ data.currentView }}-view">\n <thead>\n <tr>\n <th class="left" data-ng-click="changeView(data.currentView, data.leftDate, $event)" data-ng-show="data.leftDate.selectable"><i class="glyphicon glyphicon-arrow-left"><span class="sr-only">{{ screenReader.previous }}</span></i>\n </th>\n <th class="switch" colspan="5" data-ng-show="data.previousViewDate.selectable" data-ng-click="changeView(data.previousView, data.previousViewDate, $event)">{{ data.previousViewDate.display }}</th>\n <th class="right" data-ng-click="changeView(data.currentView, data.rightDate, $event)" data-ng-show="data.rightDate.selectable"><i class="glyphicon glyphicon-arrow-right"><span class="sr-only">{{ screenReader.next }}</span></i>\n </th>\n </tr>\n <tr>\n <th class="dow" data-ng-repeat="day in data.dayNames">{{ day }}</th>\n </tr>\n </thead>\n <tbody>\n <tr data-ng-if="data.currentView !== \'day\'">\n <td colspan="7">\n <span class="{{ data.currentView }}" data-ng-repeat="dateObject in data.dates" data-ng-class="{active: dateObject.active, past: dateObject.past, future: dateObject.future, disabled: !dateObject.selectable}" data-ng-click="changeView(data.nextView, dateObject, $event)">{{ dateObject.display }}</span></td>\n </tr>\n <tr data-ng-if="data.currentView === \'day\'" data-ng-repeat="week in data.weeks">\n <td data-ng-repeat="dateObject in week.dates" data-ng-click="changeView(data.nextView, dateObject, $event)" class="day" data-ng-class="{active: dateObject.active, past: dateObject.past, future: dateObject.future, disabled: !dateObject.selectable}">{{ dateObject.display }}</td>\n </tr>\n </tbody>\n </table>\n</div>')
28+
$templateCache.put('templates/datetimepicker.html', '<div class="datetimepicker table-responsive">\n <table class="table table-condensed {{ data.currentView }}-view">\n <thead>\n <tr>\n <th class="left" data-ng-click="changeView(data.currentView, data.leftDate, $event)" data-ng-show="data.leftDate.selectable"><i class="glyphicon glyphicon-arrow-left"><span class="sr-only">{{ screenReader.previous }}</span></i>\n </th>\n <th class="switch" colspan="5" data-ng-show="data.previousViewDate.selectable" data-ng-click="changeView(data.previousView, data.previousViewDate, $event)" data-ng-class="{today: data.previousViewDate.isToday}">{{ data.previousViewDate.display }}</th>\n <th class="right" data-ng-click="changeView(data.currentView, data.rightDate, $event)" data-ng-show="data.rightDate.selectable"><i class="glyphicon glyphicon-arrow-right"><span class="sr-only">{{ screenReader.next }}</span></i>\n </th>\n </tr>\n <tr>\n <th class="dow" data-ng-repeat="day in data.dayNames">{{ day }}</th>\n </tr>\n </thead>\n <tbody>\n <tr data-ng-if="data.currentView !== \'day\'">\n <td colspan="7">\n <span class="{{ data.currentView }}" data-ng-repeat="dateObject in data.dates" data-ng-class="{active: dateObject.active, past: dateObject.past, future: dateObject.future, disabled: !dateObject.selectable}" data-ng-click="changeView(data.nextView, dateObject, $event)">{{ dateObject.display }}</span></td>\n </tr>\n <tr data-ng-if="data.currentView === \'day\'" data-ng-repeat="week in data.weeks">\n <td data-ng-repeat="dateObject in week.dates" data-ng-click="changeView(data.nextView, dateObject, $event)" class="day" data-ng-class="{today: dateObject.isToday, active: dateObject.active, past: dateObject.past, future: dateObject.future, disabled: !dateObject.selectable}">{{ dateObject.display }}</td>\n </tr>\n </tbody>\n </table>\n</div>\n')
2929
}])
3030
}))

src/scss/_core.scss

+7
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@
6060
text-shadow: 0 -1px 0 rgba(0, 0, 0, .25);
6161
}
6262

63+
.today,
64+
.today:hover,
65+
.today.disabled,
66+
.today.disabled:hover {
67+
background-color: $abdtp-today-border;
68+
}
69+
6370
// scss-lint:disable QualifyingElement
6471
.active:hover,
6572
.active:hover:hover,

src/scss/_variables.scss

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
$abdtp-active-color: #fff !default;
21
$abdtp-active-background-color: #04c !default;
3-
$abdtp-active-border-top-color: #04c !default;
42
$abdtp-active-border-bottom-color: #002a80 !default;
3+
$abdtp-active-border-top-color: #04c !default;
4+
$abdtp-active-color: #fff !default;
55
$abdtp-background-color-end: #04c !default;
66
$abdtp-background-color-start: #08c !default;
77
$abdtp-background-color: #006dcc !default;
88
$abdtp-color-disabled: #ebebeb !default;
99
$abdtp-color-hover: #eee !default;
1010
$abdtp-color-past-future: #999 !default;
11+
$abdtp-today-border: #e5e5e5 !default;
1112
$abdtp-width: 320px !default;

src/templates/datetimepicker.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
data-ng-click="changeView(data.currentView, data.leftDate, $event)"
77
data-ng-show="data.leftDate.selectable"><i class="glyphicon glyphicon-arrow-left"><span class="sr-only">{{ screenReader.previous }}</span></i>
88
</th>
9-
<th class="switch" colspan="5"
9+
<th class="switch"
10+
colspan="5"
1011
data-ng-show="data.previousViewDate.selectable"
1112
data-ng-click="changeView(data.previousView, data.previousViewDate, $event)">{{ data.previousViewDate.display }}</th>
1213
<th class="right" data-ng-click="changeView(data.currentView, data.rightDate, $event)"
@@ -30,7 +31,7 @@
3031
<td data-ng-repeat="dateObject in week.dates"
3132
data-ng-click="changeView(data.nextView, dateObject, $event)"
3233
class="day"
33-
data-ng-class="{active: dateObject.active, past: dateObject.past, future: dateObject.future, disabled: !dateObject.selectable}">{{ dateObject.display }}</td>
34+
data-ng-class="{today: dateObject.isToday, active: dateObject.active, past: dateObject.past, future: dateObject.future, disabled: !dateObject.selectable}">{{ dateObject.display }}</td>
3435
</tr>
3536
</tbody>
3637
</table>

test/view/css.spec.js

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* globals describe, beforeEach, it, expect, module, inject, moment, angular, afterEach, jQuery */
1+
/* globals describe, beforeEach, it, expect, module, inject, moment, angular, afterEach, jQuery, jasmine */
22

33
/**
44
* @license angular-bootstrap-datetimepicker
@@ -13,10 +13,19 @@ describe('css styling', function () {
1313
'use strict'
1414

1515
var element = null
16+
var $rootScope
1617

1718
beforeEach(module('ui.bootstrap.datetimepicker'))
18-
beforeEach(inject(function ($compile, $rootScope) {
19+
beforeEach(inject(function ($compile, _$rootScope_) {
1920
moment.locale('en')
21+
$rootScope = _$rootScope_
22+
jasmine.clock().install()
23+
24+
var baseDate = moment('2013-01-23T00:00:00.000').toDate()
25+
jasmine.clock().mockDate(baseDate)
26+
27+
expect(moment().toDate().getTime()).toEqual(baseDate.getTime())
28+
2029
$rootScope.date = moment('2013-01-22T00:00:00.000').toDate()
2130
element = $compile('<datetimepicker data-ng-model="date"></datetimepicker>')($rootScope)
2231
angular.element(document).find('body').append(element)
@@ -57,7 +66,23 @@ describe('css styling', function () {
5766
})
5867
})
5968

69+
describe('of `.today` element', function () {
70+
it('should have light grey background when not active', function () {
71+
var todayElement = element.find('.today')
72+
expect(todayElement.text()).toBe('23')
73+
expect(todayElement.css('background-color')).toBe('rgb(229, 229, 229)')
74+
})
75+
it('should have `.active` background when active', function () {
76+
$rootScope.date = moment('2013-01-23T00:00:00.000').toDate()
77+
$rootScope.$digest()
78+
var todayElement = element.find('.today')
79+
expect(todayElement.text()).toBe('23')
80+
expect(todayElement.css('background-color')).toBe('rgb(0, 68, 204)')
81+
})
82+
})
83+
6084
afterEach(function () {
85+
jasmine.clock().uninstall()
6186
angular.element(document).find('body').remove('.datetimepicker')
6287
})
6388
})

0 commit comments

Comments
 (0)