begin onlyTimepicker feature

This commit is contained in:
t1m0n 2016-08-18 11:26:24 +03:00
parent 2440a1168b
commit d3a578daab
5 changed files with 38 additions and 8 deletions

21
dist/js/datepicker.js vendored
View File

@ -1,5 +1,6 @@
;(function (window, $, undefined) { ;(function () { ;(function (window, $, undefined) { ;(function () {
//TODO добавить описание метода destroy //TODO добавить описание метода destroy
// TODO добавить описание onShow onHide
var VERSION = '2.1.0', var VERSION = '2.1.0',
pluginName = 'datepicker', pluginName = 'datepicker',
autoInitSelector = '.datepicker-here', autoInitSelector = '.datepicker-here',
@ -64,6 +65,7 @@
// timepicker // timepicker
timepicker: false, timepicker: false,
onlyTimePicker: false,
dateTimeSeparator: ' ', dateTimeSeparator: ' ',
timeFormat: '', timeFormat: '',
minHours: 0, minHours: 0,
@ -159,7 +161,7 @@
this._setPositionClasses(this.opts.position); this._setPositionClasses(this.opts.position);
this._bindEvents() this._bindEvents()
} }
if (this.opts.keyboardNav) { if (this.opts.keyboardNav && !this.opts.onlyTimePicker) {
this._bindKeyboardEvents(); this._bindKeyboardEvents();
} }
this.$datepicker.on('mousedown', this._onMouseDownDatepicker.bind(this)); this.$datepicker.on('mousedown', this._onMouseDownDatepicker.bind(this));
@ -175,6 +177,10 @@
this._bindTimepickerEvents(); 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] = new $.fn.datepicker.Body(this, this.currentView, this.opts);
this.views[this.currentView].show(); this.views[this.currentView].show();
this.nav = new $.fn.datepicker.Navigation(this, this.opts); this.nav = new $.fn.datepicker.Navigation(this, this.opts);
@ -244,6 +250,10 @@
this.loc.dateFormat = [this.loc.dateFormat, this.loc.timeFormat].join(this.opts.dateTimeSeparator); 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; var boundary = this._getWordBoundaryRegExp;
if (this.loc.timeFormat.match(boundary('aa')) || if (this.loc.timeFormat.match(boundary('aa')) ||
this.loc.timeFormat.match(boundary('AA')) this.loc.timeFormat.match(boundary('AA'))
@ -1046,7 +1056,7 @@
} }
$cell = this.views[this.currentView].$el.find(selector); $cell = this.views[this.currentView].$el.find(selector);
return $cell.length ? $cell : ''; return $cell.length ? $cell : $('');
}, },
destroy: function () { destroy: function () {
@ -1470,6 +1480,7 @@
this.type = type; this.type = type;
this.opts = opts; this.opts = opts;
if (this.opts.onlyTimePicker) return;
this.init(); this.init();
}; };
@ -1691,6 +1702,7 @@
}, },
_render: function () { _render: function () {
if (this.opts.onlyTimePicker) return;
this._renderTypes[this.type].bind(this)(); this._renderTypes[this.type].bind(this)();
}, },
@ -1709,6 +1721,7 @@
}, },
show: function () { show: function () {
if (this.opts.onlyTimePicker) return;
this.$el.addClass('active'); this.$el.addClass('active');
this.acitve = true; this.acitve = true;
}, },
@ -1802,7 +1815,9 @@
}, },
_buildBaseHtml: function () { _buildBaseHtml: function () {
this._render(); if (!this.opts.onlyTimePicker) {
this._render();
}
this._addButtonsIfNeed(); this._addButtonsIfNeed();
}, },

File diff suppressed because one or more lines are too long

View File

@ -22,6 +22,7 @@
this.type = type; this.type = type;
this.opts = opts; this.opts = opts;
if (this.opts.onlyTimePicker) return;
this.init(); this.init();
}; };
@ -243,6 +244,7 @@
}, },
_render: function () { _render: function () {
if (this.opts.onlyTimePicker) return;
this._renderTypes[this.type].bind(this)(); this._renderTypes[this.type].bind(this)();
}, },
@ -261,6 +263,7 @@
}, },
show: function () { show: function () {
if (this.opts.onlyTimePicker) return;
this.$el.addClass('active'); this.$el.addClass('active');
this.acitve = true; this.acitve = true;
}, },

View File

@ -1,5 +1,6 @@
;(function () { ;(function () {
//TODO добавить описание метода destroy //TODO добавить описание метода destroy
// TODO добавить описание onShow onHide
var VERSION = '2.1.0', var VERSION = '2.1.0',
pluginName = 'datepicker', pluginName = 'datepicker',
autoInitSelector = '.datepicker-here', autoInitSelector = '.datepicker-here',
@ -64,6 +65,7 @@
// timepicker // timepicker
timepicker: false, timepicker: false,
onlyTimePicker: false,
dateTimeSeparator: ' ', dateTimeSeparator: ' ',
timeFormat: '', timeFormat: '',
minHours: 0, minHours: 0,
@ -159,7 +161,7 @@
this._setPositionClasses(this.opts.position); this._setPositionClasses(this.opts.position);
this._bindEvents() this._bindEvents()
} }
if (this.opts.keyboardNav) { if (this.opts.keyboardNav && !this.opts.onlyTimePicker) {
this._bindKeyboardEvents(); this._bindKeyboardEvents();
} }
this.$datepicker.on('mousedown', this._onMouseDownDatepicker.bind(this)); this.$datepicker.on('mousedown', this._onMouseDownDatepicker.bind(this));
@ -175,6 +177,10 @@
this._bindTimepickerEvents(); 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] = new $.fn.datepicker.Body(this, this.currentView, this.opts);
this.views[this.currentView].show(); this.views[this.currentView].show();
this.nav = new $.fn.datepicker.Navigation(this, this.opts); this.nav = new $.fn.datepicker.Navigation(this, this.opts);
@ -244,6 +250,10 @@
this.loc.dateFormat = [this.loc.dateFormat, this.loc.timeFormat].join(this.opts.dateTimeSeparator); 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; var boundary = this._getWordBoundaryRegExp;
if (this.loc.timeFormat.match(boundary('aa')) || if (this.loc.timeFormat.match(boundary('aa')) ||
this.loc.timeFormat.match(boundary('AA')) this.loc.timeFormat.match(boundary('AA'))
@ -1046,7 +1056,7 @@
} }
$cell = this.views[this.currentView].$el.find(selector); $cell = this.views[this.currentView].$el.find(selector);
return $cell.length ? $cell : ''; return $cell.length ? $cell : $('');
}, },
destroy: function () { destroy: function () {

View File

@ -30,7 +30,9 @@
}, },
_buildBaseHtml: function () { _buildBaseHtml: function () {
this._render(); if (!this.opts.onlyTimePicker) {
this._render();
}
this._addButtonsIfNeed(); this._addButtonsIfNeed();
}, },