Skip to content

Commit

Permalink
added onlyTimepicker option, closes t1m0n#102, t1m0n#75, t1m0n#108
Browse files Browse the repository at this point in the history
  • Loading branch information
t1m0n committed Aug 28, 2016
1 parent d3a578d commit e8facd2
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 21 deletions.
6 changes: 6 additions & 0 deletions dist/css/datepicker.css
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@
.datepicker--content {
box-sizing: content-box;
padding: 4px; }
.-only-timepicker- .datepicker--content {
display: none; }

.datepicker--pointer {
position: absolute;
Expand Down Expand Up @@ -297,6 +299,8 @@
border-bottom: 1px solid #efefef;
min-height: 32px;
padding: 4px; }
.-only-timepicker- .datepicker--nav {
display: none; }

.datepicker--nav-title,
.datepicker--nav-action {
Expand Down Expand Up @@ -409,6 +413,8 @@
-ms-flex: 0 1 138px;
flex: 0 1 138px;
max-width: 138px; }
.-only-timepicker- .datepicker--time {
border-top: none; }

.datepicker--time-sliders {
-webkit-flex: 0 1 153px;
Expand Down
2 changes: 1 addition & 1 deletion dist/css/datepicker.min.css

Large diffs are not rendered by default.

23 changes: 14 additions & 9 deletions dist/js/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

// timepicker
timepicker: false,
onlyTimePicker: false,
onlyTimepicker: false,
dateTimeSeparator: ' ',
timeFormat: '',
minHours: 0,
Expand Down Expand Up @@ -161,7 +161,7 @@
this._setPositionClasses(this.opts.position);
this._bindEvents()
}
if (this.opts.keyboardNav && !this.opts.onlyTimePicker) {
if (this.opts.keyboardNav && !this.opts.onlyTimepicker) {
this._bindKeyboardEvents();
}
this.$datepicker.on('mousedown', this._onMouseDownDatepicker.bind(this));
Expand All @@ -177,7 +177,7 @@
this._bindTimepickerEvents();
}

if (this.opts.onlyTimePicker) {
if (this.opts.onlyTimepicker) {
this.$datepicker.addClass('-only-timepicker-');
}

Expand Down Expand Up @@ -250,7 +250,7 @@
this.loc.dateFormat = [this.loc.dateFormat, this.loc.timeFormat].join(this.opts.dateTimeSeparator);
}

if (this.opts.onlyTimePicker) {
if (this.opts.onlyTimepicker) {
this.loc.dateFormat = this.loc.timeFormat;
}

Expand Down Expand Up @@ -610,7 +610,7 @@
this._syncWithMinMaxDates();
this._defineLocale(this.opts.language);
this.nav._addButtonsIfNeed();
this.nav._render();
if (!this.opts.onlyTimepicker) this.nav._render();
this.views[this.currentView]._render();

if (this.elIsInput && !this.opts.inline) {
Expand All @@ -624,6 +624,10 @@
this.$datepicker.addClass(this.opts.classes)
}

if (this.opts.onlyTimepicker) {
this.$datepicker.addClass('-only-timepicker-');
}

if (this.opts.timepicker) {
if (lastSelectedDate) this.timepicker._handleDate(lastSelectedDate);
this.timepicker._updateRanges();
Expand Down Expand Up @@ -1479,8 +1483,9 @@
this.d = d;
this.type = type;
this.opts = opts;
this.$el = $('');

if (this.opts.onlyTimePicker) return;
if (this.opts.onlyTimepicker) return;
this.init();
};

Expand Down Expand Up @@ -1702,7 +1707,7 @@
},

_render: function () {
if (this.opts.onlyTimePicker) return;
if (this.opts.onlyTimepicker) return;
this._renderTypes[this.type].bind(this)();
},

Expand All @@ -1721,7 +1726,7 @@
},

show: function () {
if (this.opts.onlyTimePicker) return;
if (this.opts.onlyTimepicker) return;
this.$el.addClass('active');
this.acitve = true;
},
Expand Down Expand Up @@ -1815,7 +1820,7 @@
},

_buildBaseHtml: function () {
if (!this.opts.onlyTimePicker) {
if (!this.opts.onlyTimepicker) {
this._render();
}
this._addButtonsIfNeed();
Expand Down
4 changes: 2 additions & 2 deletions dist/js/datepicker.min.js

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions src/js/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
this.d = d;
this.type = type;
this.opts = opts;
this.$el = $('');

if (this.opts.onlyTimePicker) return;
if (this.opts.onlyTimepicker) return;
this.init();
};

Expand Down Expand Up @@ -244,7 +245,7 @@
},

_render: function () {
if (this.opts.onlyTimePicker) return;
if (this.opts.onlyTimepicker) return;
this._renderTypes[this.type].bind(this)();
},

Expand All @@ -263,7 +264,7 @@
},

show: function () {
if (this.opts.onlyTimePicker) return;
if (this.opts.onlyTimepicker) return;
this.$el.addClass('active');
this.acitve = true;
},
Expand Down
14 changes: 9 additions & 5 deletions src/js/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

// timepicker
timepicker: false,
onlyTimePicker: false,
onlyTimepicker: false,
dateTimeSeparator: ' ',
timeFormat: '',
minHours: 0,
Expand Down Expand Up @@ -161,7 +161,7 @@
this._setPositionClasses(this.opts.position);
this._bindEvents()
}
if (this.opts.keyboardNav && !this.opts.onlyTimePicker) {
if (this.opts.keyboardNav && !this.opts.onlyTimepicker) {
this._bindKeyboardEvents();
}
this.$datepicker.on('mousedown', this._onMouseDownDatepicker.bind(this));
Expand All @@ -177,7 +177,7 @@
this._bindTimepickerEvents();
}

if (this.opts.onlyTimePicker) {
if (this.opts.onlyTimepicker) {
this.$datepicker.addClass('-only-timepicker-');
}

Expand Down Expand Up @@ -250,7 +250,7 @@
this.loc.dateFormat = [this.loc.dateFormat, this.loc.timeFormat].join(this.opts.dateTimeSeparator);
}

if (this.opts.onlyTimePicker) {
if (this.opts.onlyTimepicker) {
this.loc.dateFormat = this.loc.timeFormat;
}

Expand Down Expand Up @@ -610,7 +610,7 @@
this._syncWithMinMaxDates();
this._defineLocale(this.opts.language);
this.nav._addButtonsIfNeed();
this.nav._render();
if (!this.opts.onlyTimepicker) this.nav._render();
this.views[this.currentView]._render();

if (this.elIsInput && !this.opts.inline) {
Expand All @@ -624,6 +624,10 @@
this.$datepicker.addClass(this.opts.classes)
}

if (this.opts.onlyTimepicker) {
this.$datepicker.addClass('-only-timepicker-');
}

if (this.opts.timepicker) {
if (lastSelectedDate) this.timepicker._handleDate(lastSelectedDate);
this.timepicker._updateRanges();
Expand Down
2 changes: 1 addition & 1 deletion src/js/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},

_buildBaseHtml: function () {
if (!this.opts.onlyTimePicker) {
if (!this.opts.onlyTimepicker) {
this._render();
}
this._addButtonsIfNeed();
Expand Down
4 changes: 4 additions & 0 deletions src/sass/datepicker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
.datepicker--content {
box-sizing: content-box;
padding: $datepickerPadding;

.-only-timepicker- & {
display: none;
}
}

// Pointer
Expand Down
4 changes: 4 additions & 0 deletions src/sass/navigation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
border-bottom: 1px solid map_get($datepickerBorderColor, nav);
min-height: $datepickerNavigationHeight;
padding: $datepickerPadding;

.-only-timepicker- & {
display: none;
}
}

.datepicker--nav-title,
Expand Down
4 changes: 4 additions & 0 deletions src/sass/timepicker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ $rangeThumbBg: #dedede;
max-width: 138px;
}
}

.-only-timepicker- & {
border-top: none;
}
}

.datepicker--time-sliders {
Expand Down
20 changes: 20 additions & 0 deletions tests/specs/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,26 @@ describe('Options', function () {
})
});

describe('onlyTimepicker', function () {
it('only timepicker should be visible', function () {
dp = $input.datepicker({
timepicker: true,
onlyTimepicker: true
}).data('datepicker');

var $time = $('.datepicker--time', dp.$datepicker),
$cells = $('.datepicker--cells', dp.$datepicker),
$nav = $('.datepicker--nav-title', dp.$datepicker),
_class = dp.$datepicker.hasClass('-only-timepicker-');

expect($time).to.have.length(1);
expect($cells).to.have.length(0);
expect($nav).to.have.length(0);
expect(_class).to.be.equal(true);

})
});

describe('dateTimeSeparator', function () {
it('should define separator between date string and time', function () {
var date = new Date(2016,2,9,11,24);
Expand Down

0 comments on commit e8facd2

Please sign in to comment.