Skip to content

Commit

Permalink
begin onlyTimepicker feature
Browse files Browse the repository at this point in the history
  • Loading branch information
t1m0n committed Aug 18, 2016
1 parent 2440a11 commit d3a578d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
21 changes: 18 additions & 3 deletions dist/js/datepicker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
;(function (window, $, undefined) { ;(function () {
//TODO добавить описание метода destroy
// TODO добавить описание onShow onHide
var VERSION = '2.1.0',
pluginName = 'datepicker',
autoInitSelector = '.datepicker-here',
Expand Down Expand Up @@ -64,6 +65,7 @@

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

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

this.views[this.currentView] = new $.fn.datepicker.Body(this, this.currentView, this.opts);
this.views[this.currentView].show();
this.nav = new $.fn.datepicker.Navigation(this, this.opts);
Expand Down Expand Up @@ -244,6 +250,10 @@
this.loc.dateFormat = [this.loc.dateFormat, this.loc.timeFormat].join(this.opts.dateTimeSeparator);
}

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

var boundary = this._getWordBoundaryRegExp;
if (this.loc.timeFormat.match(boundary('aa')) ||
this.loc.timeFormat.match(boundary('AA'))
Expand Down Expand Up @@ -1046,7 +1056,7 @@
}
$cell = this.views[this.currentView].$el.find(selector);

return $cell.length ? $cell : '';
return $cell.length ? $cell : $('');
},

destroy: function () {
Expand Down Expand Up @@ -1470,6 +1480,7 @@
this.type = type;
this.opts = opts;

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

Expand Down Expand Up @@ -1691,6 +1702,7 @@
},

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

Expand All @@ -1709,6 +1721,7 @@
},

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

_buildBaseHtml: function () {
this._render();
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.

3 changes: 3 additions & 0 deletions src/js/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
this.type = type;
this.opts = opts;

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

Expand Down Expand Up @@ -243,6 +244,7 @@
},

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

Expand All @@ -261,6 +263,7 @@
},

show: function () {
if (this.opts.onlyTimePicker) return;
this.$el.addClass('active');
this.acitve = true;
},
Expand Down
14 changes: 12 additions & 2 deletions src/js/datepicker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
;(function () {
//TODO добавить описание метода destroy
// TODO добавить описание onShow onHide
var VERSION = '2.1.0',
pluginName = 'datepicker',
autoInitSelector = '.datepicker-here',
Expand Down Expand Up @@ -64,6 +65,7 @@

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

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

this.views[this.currentView] = new $.fn.datepicker.Body(this, this.currentView, this.opts);
this.views[this.currentView].show();
this.nav = new $.fn.datepicker.Navigation(this, this.opts);
Expand Down Expand Up @@ -244,6 +250,10 @@
this.loc.dateFormat = [this.loc.dateFormat, this.loc.timeFormat].join(this.opts.dateTimeSeparator);
}

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

var boundary = this._getWordBoundaryRegExp;
if (this.loc.timeFormat.match(boundary('aa')) ||
this.loc.timeFormat.match(boundary('AA'))
Expand Down Expand Up @@ -1046,7 +1056,7 @@
}
$cell = this.views[this.currentView].$el.find(selector);

return $cell.length ? $cell : '';
return $cell.length ? $cell : $('');
},

destroy: function () {
Expand Down
4 changes: 3 additions & 1 deletion src/js/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
},

_buildBaseHtml: function () {
this._render();
if (!this.opts.onlyTimePicker) {
this._render();
}
this._addButtonsIfNeed();
},

Expand Down

0 comments on commit d3a578d

Please sign in to comment.