mirror of
https://github.com/frappe/air-datepicker.git
synced 2026-01-14 11:01:22 +08:00
add min max options for hours and minutes
This commit is contained in:
parent
1344888028
commit
d018a1c46f
87
dist/js/datepicker.js
vendored
87
dist/js/datepicker.js
vendored
@ -64,7 +64,12 @@ var Datepicker;
|
|||||||
|
|
||||||
// timepicker
|
// timepicker
|
||||||
timepicker: false,
|
timepicker: false,
|
||||||
timeFormat: 'hh:ii',
|
minHours: 0,
|
||||||
|
minMinutes: 0,
|
||||||
|
maxHours: 24,
|
||||||
|
maxMinutes: 59,
|
||||||
|
hoursStep: 1,
|
||||||
|
minutesStep: 1,
|
||||||
|
|
||||||
// events
|
// events
|
||||||
onSelect: '',
|
onSelect: '',
|
||||||
@ -317,6 +322,7 @@ var Datepicker;
|
|||||||
formatDate: function (string, date) {
|
formatDate: function (string, date) {
|
||||||
date = date || this.date;
|
date = date || this.date;
|
||||||
var result = string,
|
var result = string,
|
||||||
|
boundary = this._getWordBoundaryRegExp,
|
||||||
locale = this.loc,
|
locale = this.loc,
|
||||||
decade = datepicker.getDecade(date),
|
decade = datepicker.getDecade(date),
|
||||||
d = datepicker.getParsedDate(date);
|
d = datepicker.getParsedDate(date);
|
||||||
@ -325,21 +331,21 @@ var Datepicker;
|
|||||||
case /@/.test(result):
|
case /@/.test(result):
|
||||||
result = result.replace(/@/, date.getTime());
|
result = result.replace(/@/, date.getTime());
|
||||||
case /dd/.test(result):
|
case /dd/.test(result):
|
||||||
result = result.replace(/\bdd\b/, d.fullDate);
|
result = result.replace(boundary('dd'), d.fullDate);
|
||||||
case /d/.test(result):
|
case /d/.test(result):
|
||||||
result = result.replace(/\bd\b/, d.date);
|
result = result.replace(boundary('d'), d.date);
|
||||||
case /DD/.test(result):
|
case /DD/.test(result):
|
||||||
result = result.replace(/\bDD\b/, locale.days[d.day]);
|
result = result.replace(boundary('DD'), locale.days[d.day]);
|
||||||
case /D/.test(result):
|
case /D/.test(result):
|
||||||
result = result.replace(/\bD\b/, locale.daysShort[d.day]);
|
result = result.replace(boundary('D'), locale.daysShort[d.day]);
|
||||||
case /mm/.test(result):
|
case /mm/.test(result):
|
||||||
result = result.replace(/\bmm\b/, d.fullMonth);
|
result = result.replace(boundary('mm'), d.fullMonth);
|
||||||
case /m/.test(result):
|
case /m/.test(result):
|
||||||
result = result.replace(/\bm\b/, d.month + 1);
|
result = result.replace(boundary('m'), d.month + 1);
|
||||||
case /MM/.test(result):
|
case /MM/.test(result):
|
||||||
result = result.replace(/\bMM\b/, this.loc.months[d.month]);
|
result = result.replace(boundary('MM'), this.loc.months[d.month]);
|
||||||
case /M/.test(result):
|
case /M/.test(result):
|
||||||
result = result.replace(/\bM\b/, locale.monthsShort[d.month]);
|
result = result.replace(boundary('M'), locale.monthsShort[d.month]);
|
||||||
case /ii/.test(result):
|
case /ii/.test(result):
|
||||||
result = result.replace(/\bii\b/, d.fullMinutes);
|
result = result.replace(/\bii\b/, d.fullMinutes);
|
||||||
case /i/.test(result):
|
case /i/.test(result):
|
||||||
@ -349,18 +355,22 @@ var Datepicker;
|
|||||||
case /h/.test(result):
|
case /h/.test(result):
|
||||||
result = result.replace(/\bh\b/, d.hours);
|
result = result.replace(/\bh\b/, d.hours);
|
||||||
case /yyyy/.test(result):
|
case /yyyy/.test(result):
|
||||||
result = result.replace(/\byyyy\b/, d.year);
|
result = result.replace(boundary('yyyy'), d.year);
|
||||||
case /yyyy1/.test(result):
|
case /yyyy1/.test(result):
|
||||||
result = result.replace(/\byyyy1\b/, decade[0]);
|
result = result.replace(boundary('yyyy1'), decade[0]);
|
||||||
case /yyyy2/.test(result):
|
case /yyyy2/.test(result):
|
||||||
result = result.replace(/\byyyy2\b/, decade[1]);
|
result = result.replace(boundary('yyyy2'), decade[1]);
|
||||||
case /yy/.test(result):
|
case /yy/.test(result):
|
||||||
result = result.replace(/\byy\b/, d.year.toString().slice(-2));
|
result = result.replace(boundary('yy'), d.year.toString().slice(-2));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_getWordBoundaryRegExp: function (sign) {
|
||||||
|
return new RegExp('\\b(?=[a-zA-Z0-9äöüßÄÖÜ<])' + sign + '(?![>a-zA-Z0-9äöüßÄÖÜ])');
|
||||||
|
},
|
||||||
|
|
||||||
selectDate: function (date) {
|
selectDate: function (date) {
|
||||||
var _this = this,
|
var _this = this,
|
||||||
opts = _this.opts,
|
opts = _this.opts,
|
||||||
@ -1246,6 +1256,10 @@ var Datepicker;
|
|||||||
return date.getTime() > dateCompareTo.getTime();
|
return date.getTime() > dateCompareTo.getTime();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
datepicker.getLeadingZeroNum = function (num) {
|
||||||
|
return parseInt(num) < 0 ? '0' + num : num;
|
||||||
|
};
|
||||||
|
|
||||||
Datepicker.language = {
|
Datepicker.language = {
|
||||||
ru: {
|
ru: {
|
||||||
days: ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'],
|
days: ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'],
|
||||||
@ -1730,6 +1744,11 @@ var Datepicker;
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
(function (window, $, datepicker) {
|
(function (window, $, datepicker) {
|
||||||
|
//TODO включить время в минимальную и максимальную дату
|
||||||
|
//TODO возможность задания минимальных и максимальных минут/часов
|
||||||
|
//TODO возможность задания шага для часов минут
|
||||||
|
//TODO возоможность задавать определенные часы и минуты
|
||||||
|
|
||||||
var template = '<div class="datepicker--time">' +
|
var template = '<div class="datepicker--time">' +
|
||||||
'<div class="datepicker--time-sliders">' +
|
'<div class="datepicker--time-sliders">' +
|
||||||
' <label class="datepicker--time-label">#{hourLabel}</label>' +
|
' <label class="datepicker--time-label">#{hourLabel}</label>' +
|
||||||
@ -1754,18 +1773,13 @@ var Datepicker;
|
|||||||
this.d = inst;
|
this.d = inst;
|
||||||
this.opts = opts;
|
this.opts = opts;
|
||||||
|
|
||||||
var date = this.d.parsedDate;
|
|
||||||
this.minutes = date.minutes;
|
|
||||||
this.hours = date.hours;
|
|
||||||
this._minutes = date.minutes;
|
|
||||||
this._hours = date.hours;
|
|
||||||
|
|
||||||
this.init();
|
this.init();
|
||||||
};
|
};
|
||||||
|
|
||||||
datepicker.Timepicker.prototype = {
|
datepicker.Timepicker.prototype = {
|
||||||
init: function () {
|
init: function () {
|
||||||
var input = 'input';
|
var input = 'input';
|
||||||
|
this._setValidTimes(this.d.date);
|
||||||
this._buildHTML();
|
this._buildHTML();
|
||||||
|
|
||||||
if (navigator.userAgent.match(/trident/gi)) {
|
if (navigator.userAgent.match(/trident/gi)) {
|
||||||
@ -1780,19 +1794,30 @@ var Datepicker;
|
|||||||
this.$currentInputs.on('paste', this._onPasteInput.bind(this));
|
this.$currentInputs.on('paste', this._onPasteInput.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_setValidTimes: function (date) {
|
||||||
|
var _date = datepicker.getParsedDate(date),
|
||||||
|
maxHours = 23;
|
||||||
|
|
||||||
|
this.minHours = this.opts.minHours;
|
||||||
|
this.minMinutes = this.opts.minMinutes;
|
||||||
|
this.maxHours = this.opts.maxHours > maxHours ? maxHours : this.opts.maxHours;
|
||||||
|
this.maxMinutes = this.opts.maxMinutes > 59 ? 59 : this.opts.maxMinutes;
|
||||||
|
this.hours = _date.hours < this.minHours ? this.minHours : _date.hours;
|
||||||
|
this.minutes = _date.minutes < this.minMinutes ? this.minMinutes : _date.minutes;
|
||||||
|
},
|
||||||
|
|
||||||
_buildHTML: function () {
|
_buildHTML: function () {
|
||||||
var date = this.d.parsedDate,
|
var date = this.d.parsedDate,
|
||||||
|
lz = datepicker.getLeadingZeroNum,
|
||||||
data = {
|
data = {
|
||||||
hourMin: '00',
|
hourMin: this.minHours,
|
||||||
hourMax: '23',
|
hourMax: lz(this.maxHours),
|
||||||
hourStep: '1',
|
hourStep: this.opts.hoursStep,
|
||||||
hourValue: date.fullHours,
|
hourValue: lz(this.hours),
|
||||||
hourLabel: 'Часы',
|
minMin: this.minMinutes,
|
||||||
minMin: '00',
|
minMax: lz(this.maxMinutes),
|
||||||
minMax: '59',
|
minStep: this.opts.minutesStep,
|
||||||
minStep: '1',
|
minValue: lz(this.minutes)
|
||||||
minValue: date.fullMinutes,
|
|
||||||
minLabel: 'Минуты'
|
|
||||||
},
|
},
|
||||||
_template = datepicker.template(template, data);
|
_template = datepicker.template(template, data);
|
||||||
|
|
||||||
@ -1817,6 +1842,10 @@ var Datepicker;
|
|||||||
this.$minutesText.val(m)
|
this.$minutesText.val(m)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
// Events
|
||||||
|
// -------------------------------------------------
|
||||||
|
|
||||||
_onChangeRange: function (e) {
|
_onChangeRange: function (e) {
|
||||||
var $target = $(e.target),
|
var $target = $(e.target),
|
||||||
value = $target.val(),
|
value = $target.val(),
|
||||||
|
|||||||
2
dist/js/datepicker.min.js
vendored
2
dist/js/datepicker.min.js
vendored
File diff suppressed because one or more lines are too long
@ -64,7 +64,12 @@ var Datepicker;
|
|||||||
|
|
||||||
// timepicker
|
// timepicker
|
||||||
timepicker: false,
|
timepicker: false,
|
||||||
timeFormat: 'hh:ii',
|
minHours: 0,
|
||||||
|
minMinutes: 0,
|
||||||
|
maxHours: 24,
|
||||||
|
maxMinutes: 59,
|
||||||
|
hoursStep: 1,
|
||||||
|
minutesStep: 1,
|
||||||
|
|
||||||
// events
|
// events
|
||||||
onSelect: '',
|
onSelect: '',
|
||||||
@ -1251,6 +1256,10 @@ var Datepicker;
|
|||||||
return date.getTime() > dateCompareTo.getTime();
|
return date.getTime() > dateCompareTo.getTime();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
datepicker.getLeadingZeroNum = function (num) {
|
||||||
|
return parseInt(num) < 0 ? '0' + num : num;
|
||||||
|
};
|
||||||
|
|
||||||
Datepicker.language = {
|
Datepicker.language = {
|
||||||
ru: {
|
ru: {
|
||||||
days: ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'],
|
days: ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'],
|
||||||
|
|||||||
@ -28,18 +28,13 @@
|
|||||||
this.d = inst;
|
this.d = inst;
|
||||||
this.opts = opts;
|
this.opts = opts;
|
||||||
|
|
||||||
var date = this.d.parsedDate;
|
|
||||||
this.minutes = date.minutes;
|
|
||||||
this.hours = date.hours;
|
|
||||||
this._minutes = date.minutes;
|
|
||||||
this._hours = date.hours;
|
|
||||||
|
|
||||||
this.init();
|
this.init();
|
||||||
};
|
};
|
||||||
|
|
||||||
datepicker.Timepicker.prototype = {
|
datepicker.Timepicker.prototype = {
|
||||||
init: function () {
|
init: function () {
|
||||||
var input = 'input';
|
var input = 'input';
|
||||||
|
this._setValidTimes(this.d.date);
|
||||||
this._buildHTML();
|
this._buildHTML();
|
||||||
|
|
||||||
if (navigator.userAgent.match(/trident/gi)) {
|
if (navigator.userAgent.match(/trident/gi)) {
|
||||||
@ -54,19 +49,30 @@
|
|||||||
this.$currentInputs.on('paste', this._onPasteInput.bind(this));
|
this.$currentInputs.on('paste', this._onPasteInput.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_setValidTimes: function (date) {
|
||||||
|
var _date = datepicker.getParsedDate(date),
|
||||||
|
maxHours = 23;
|
||||||
|
|
||||||
|
this.minHours = this.opts.minHours;
|
||||||
|
this.minMinutes = this.opts.minMinutes;
|
||||||
|
this.maxHours = this.opts.maxHours > maxHours ? maxHours : this.opts.maxHours;
|
||||||
|
this.maxMinutes = this.opts.maxMinutes > 59 ? 59 : this.opts.maxMinutes;
|
||||||
|
this.hours = _date.hours < this.minHours ? this.minHours : _date.hours;
|
||||||
|
this.minutes = _date.minutes < this.minMinutes ? this.minMinutes : _date.minutes;
|
||||||
|
},
|
||||||
|
|
||||||
_buildHTML: function () {
|
_buildHTML: function () {
|
||||||
var date = this.d.parsedDate,
|
var date = this.d.parsedDate,
|
||||||
|
lz = datepicker.getLeadingZeroNum,
|
||||||
data = {
|
data = {
|
||||||
hourMin: '00',
|
hourMin: this.minHours,
|
||||||
hourMax: '23',
|
hourMax: lz(this.maxHours),
|
||||||
hourStep: '1',
|
hourStep: this.opts.hoursStep,
|
||||||
hourValue: date.fullHours,
|
hourValue: lz(this.hours),
|
||||||
hourLabel: 'Часы',
|
minMin: this.minMinutes,
|
||||||
minMin: '00',
|
minMax: lz(this.maxMinutes),
|
||||||
minMax: '59',
|
minStep: this.opts.minutesStep,
|
||||||
minStep: '1',
|
minValue: lz(this.minutes)
|
||||||
minValue: date.fullMinutes,
|
|
||||||
minLabel: 'Минуты'
|
|
||||||
},
|
},
|
||||||
_template = datepicker.template(template, data);
|
_template = datepicker.template(template, data);
|
||||||
|
|
||||||
@ -91,6 +97,10 @@
|
|||||||
this.$minutesText.val(m)
|
this.$minutesText.val(m)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
// Events
|
||||||
|
// -------------------------------------------------
|
||||||
|
|
||||||
_onChangeRange: function (e) {
|
_onChangeRange: function (e) {
|
||||||
var $target = $(e.target),
|
var $target = $(e.target),
|
||||||
value = $target.val(),
|
value = $target.val(),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user