mirror of
https://github.com/frappe/air-datepicker.git
synced 2026-01-14 11:01:22 +08:00
remove global 'Datepicker' var, add it to $.fn, closes #32
This commit is contained in:
parent
c648cba3ab
commit
12e7c3dd1f
120
dist/js/datepicker.js
vendored
120
dist/js/datepicker.js
vendored
@ -1,6 +1,4 @@
|
|||||||
;(function (window, $, undefined) { window.Datepicker = '';
|
;(function (window, $, undefined) { ;(function () {
|
||||||
|
|
||||||
(function () {
|
|
||||||
var pluginName = 'datepicker',
|
var pluginName = 'datepicker',
|
||||||
autoInitSelector = '.datepicker-here',
|
autoInitSelector = '.datepicker-here',
|
||||||
$body, $datepickersContainer,
|
$body, $datepickersContainer,
|
||||||
@ -98,7 +96,7 @@
|
|||||||
},
|
},
|
||||||
datepicker;
|
datepicker;
|
||||||
|
|
||||||
Datepicker = function (el, options) {
|
var Datepicker = function (el, options) {
|
||||||
this.el = el;
|
this.el = el;
|
||||||
this.$el = $(el);
|
this.$el = $(el);
|
||||||
|
|
||||||
@ -167,13 +165,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.opts.timepicker) {
|
if (this.opts.timepicker) {
|
||||||
this.timepicker = new Datepicker.Timepicker(this, this.opts);
|
this.timepicker = new $.fn.datepicker.Timepicker(this, this.opts);
|
||||||
this._bindTimepickerEvents();
|
this._bindTimepickerEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.views[this.currentView] = new 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 Datepicker.Navigation(this, this.opts);
|
this.nav = new $.fn.datepicker.Navigation(this, this.opts);
|
||||||
this.view = this.currentView;
|
this.view = this.currentView;
|
||||||
|
|
||||||
this.$el.on('clickCell.adp', this._onClickCell.bind(this));
|
this.$el.on('clickCell.adp', this._onClickCell.bind(this));
|
||||||
@ -213,15 +211,15 @@
|
|||||||
|
|
||||||
_defineLocale: function (lang) {
|
_defineLocale: function (lang) {
|
||||||
if (typeof lang == 'string') {
|
if (typeof lang == 'string') {
|
||||||
this.loc = Datepicker.language[lang];
|
this.loc = $.fn.datepicker.language[lang];
|
||||||
if (!this.loc) {
|
if (!this.loc) {
|
||||||
console.warn('Can\'t find language "' + lang + '" in Datepicker.language, will use "ru" instead');
|
console.warn('Can\'t find language "' + lang + '" in Datepicker.language, will use "ru" instead');
|
||||||
this.loc = $.extend(true, {}, Datepicker.language.ru)
|
this.loc = $.extend(true, {}, $.fn.datepicker.language.ru)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loc = $.extend(true, {}, Datepicker.language.ru, Datepicker.language[lang])
|
this.loc = $.extend(true, {}, $.fn.datepicker.language.ru, $.fn.datepicker.language[lang])
|
||||||
} else {
|
} else {
|
||||||
this.loc = $.extend(true, {}, Datepicker.language.ru, lang)
|
this.loc = $.extend(true, {}, $.fn.datepicker.language.ru, lang)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.opts.dateFormat) {
|
if (this.opts.dateFormat) {
|
||||||
@ -1240,7 +1238,7 @@
|
|||||||
|
|
||||||
if (this.inited) {
|
if (this.inited) {
|
||||||
if (!this.views[val]) {
|
if (!this.views[val]) {
|
||||||
this.views[val] = new Datepicker.Body(this, val, this.opts)
|
this.views[val] = new $.fn.datepicker.Body(this, val, this.opts)
|
||||||
} else {
|
} else {
|
||||||
this.views[val]._render();
|
this.views[val]._render();
|
||||||
}
|
}
|
||||||
@ -1346,7 +1344,23 @@
|
|||||||
return parseInt(num) < 10 ? '0' + num : num;
|
return parseInt(num) < 10 ? '0' + num : num;
|
||||||
};
|
};
|
||||||
|
|
||||||
Datepicker.language = {
|
$.fn.datepicker = function ( options ) {
|
||||||
|
return this.each(function () {
|
||||||
|
if (!$.data(this, pluginName)) {
|
||||||
|
$.data(this, pluginName,
|
||||||
|
new Datepicker( this, options ));
|
||||||
|
} else {
|
||||||
|
var _this = $.data(this, pluginName);
|
||||||
|
|
||||||
|
_this.opts = $.extend(true, _this.opts, options);
|
||||||
|
_this.update();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
$.fn.datepicker.Constructor = Datepicker;
|
||||||
|
|
||||||
|
$.fn.datepicker.language = {
|
||||||
ru: {
|
ru: {
|
||||||
days: ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'],
|
days: ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'],
|
||||||
daysShort: ['Вос','Пон','Вто','Сре','Чет','Пят','Суб'],
|
daysShort: ['Вос','Пон','Вто','Сре','Чет','Пят','Суб'],
|
||||||
@ -1361,20 +1375,6 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$.fn[pluginName] = function ( options ) {
|
|
||||||
return this.each(function () {
|
|
||||||
if (!$.data(this, pluginName)) {
|
|
||||||
$.data(this, pluginName,
|
|
||||||
new Datepicker( this, options ));
|
|
||||||
} else {
|
|
||||||
var _this = $.data(this, pluginName);
|
|
||||||
|
|
||||||
_this.opts = $.extend(true, _this.opts, options);
|
|
||||||
_this.update();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
$(autoInitSelector).datepicker();
|
$(autoInitSelector).datepicker();
|
||||||
})
|
})
|
||||||
@ -1397,9 +1397,10 @@
|
|||||||
'<div class="datepicker--cells datepicker--cells-years"></div>' +
|
'<div class="datepicker--cells datepicker--cells-years"></div>' +
|
||||||
'</div>'
|
'</div>'
|
||||||
},
|
},
|
||||||
D = Datepicker;
|
datepicker = $.fn.datepicker,
|
||||||
|
dp = datepicker.Constructor;
|
||||||
|
|
||||||
D.Body = function (d, type, opts) {
|
datepicker.Body = function (d, type, opts) {
|
||||||
this.d = d;
|
this.d = d;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.opts = opts;
|
this.opts = opts;
|
||||||
@ -1407,7 +1408,7 @@
|
|||||||
this.init();
|
this.init();
|
||||||
};
|
};
|
||||||
|
|
||||||
D.Body.prototype = {
|
datepicker.Body.prototype = {
|
||||||
init: function () {
|
init: function () {
|
||||||
this._buildBaseHtml();
|
this._buildBaseHtml();
|
||||||
this._render();
|
this._render();
|
||||||
@ -1443,7 +1444,7 @@
|
|||||||
currentDate = new Date(),
|
currentDate = new Date(),
|
||||||
parent = this.d,
|
parent = this.d,
|
||||||
opts = parent.opts,
|
opts = parent.opts,
|
||||||
d = D.getParsedDate(date),
|
d = dp.getParsedDate(date),
|
||||||
render = {},
|
render = {},
|
||||||
html = d.date;
|
html = d.date;
|
||||||
|
|
||||||
@ -1487,34 +1488,34 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (opts.range) {
|
if (opts.range) {
|
||||||
if (D.isSame(parent.minRange, date, type)) classes += ' -range-from-';
|
if (dp.isSame(parent.minRange, date, type)) classes += ' -range-from-';
|
||||||
if (D.isSame(parent.maxRange, date, type)) classes += ' -range-to-';
|
if (dp.isSame(parent.maxRange, date, type)) classes += ' -range-to-';
|
||||||
|
|
||||||
if (parent.selectedDates.length == 1 && parent.focused) {
|
if (parent.selectedDates.length == 1 && parent.focused) {
|
||||||
if (
|
if (
|
||||||
(D.bigger(parent.minRange, date) && D.less(parent.focused, date)) ||
|
(dp.bigger(parent.minRange, date) && dp.less(parent.focused, date)) ||
|
||||||
(D.less(parent.maxRange, date) && D.bigger(parent.focused, date)))
|
(dp.less(parent.maxRange, date) && dp.bigger(parent.focused, date)))
|
||||||
{
|
{
|
||||||
classes += ' -in-range-'
|
classes += ' -in-range-'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (D.less(parent.maxRange, date) && D.isSame(parent.focused, date)) {
|
if (dp.less(parent.maxRange, date) && dp.isSame(parent.focused, date)) {
|
||||||
classes += ' -range-from-'
|
classes += ' -range-from-'
|
||||||
}
|
}
|
||||||
if (D.bigger(parent.minRange, date) && D.isSame(parent.focused, date)) {
|
if (dp.bigger(parent.minRange, date) && dp.isSame(parent.focused, date)) {
|
||||||
classes += ' -range-to-'
|
classes += ' -range-to-'
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (parent.selectedDates.length == 2) {
|
} else if (parent.selectedDates.length == 2) {
|
||||||
if (D.bigger(parent.minRange, date) && D.less(parent.maxRange, date)) {
|
if (dp.bigger(parent.minRange, date) && dp.less(parent.maxRange, date)) {
|
||||||
classes += ' -in-range-'
|
classes += ' -in-range-'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (D.isSame(currentDate, date, type)) classes += ' -current-';
|
if (dp.isSame(currentDate, date, type)) classes += ' -current-';
|
||||||
if (parent.focused && D.isSame(date, parent.focused, type)) classes += ' -focus-';
|
if (parent.focused && dp.isSame(date, parent.focused, type)) classes += ' -focus-';
|
||||||
if (parent._isSelected(date, type)) classes += ' -selected-';
|
if (parent._isSelected(date, type)) classes += ' -selected-';
|
||||||
if (!parent._isInRange(date, type) || render.disabled) classes += ' -disabled-';
|
if (!parent._isInRange(date, type) || render.disabled) classes += ' -disabled-';
|
||||||
|
|
||||||
@ -1531,7 +1532,7 @@
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_getDaysHtml: function (date) {
|
_getDaysHtml: function (date) {
|
||||||
var totalMonthDays = D.getDaysCount(date),
|
var totalMonthDays = dp.getDaysCount(date),
|
||||||
firstMonthDay = new Date(date.getFullYear(), date.getMonth(), 1).getDay(),
|
firstMonthDay = new Date(date.getFullYear(), date.getMonth(), 1).getDay(),
|
||||||
lastMonthDay = new Date(date.getFullYear(), date.getMonth(), totalMonthDays).getDay(),
|
lastMonthDay = new Date(date.getFullYear(), date.getMonth(), totalMonthDays).getDay(),
|
||||||
daysFromPevMonth = firstMonthDay - this.d.loc.firstDay,
|
daysFromPevMonth = firstMonthDay - this.d.loc.firstDay,
|
||||||
@ -1571,7 +1572,7 @@
|
|||||||
*/
|
*/
|
||||||
_getMonthsHtml: function (date) {
|
_getMonthsHtml: function (date) {
|
||||||
var html = '',
|
var html = '',
|
||||||
d = D.getParsedDate(date),
|
d = dp.getParsedDate(date),
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
while(i < 12) {
|
while(i < 12) {
|
||||||
@ -1589,8 +1590,8 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
_getYearsHtml: function (date) {
|
_getYearsHtml: function (date) {
|
||||||
var d = D.getParsedDate(date),
|
var d = dp.getParsedDate(date),
|
||||||
decade = D.getDecade(date),
|
decade = dp.getDecade(date),
|
||||||
firstYear = decade[0] - 1,
|
firstYear = decade[0] - 1,
|
||||||
html = '',
|
html = '',
|
||||||
i = firstYear;
|
i = firstYear;
|
||||||
@ -1696,9 +1697,11 @@
|
|||||||
'<div class="datepicker--nav-title">#{title}</div>' +
|
'<div class="datepicker--nav-title">#{title}</div>' +
|
||||||
'<div class="datepicker--nav-action" data-action="next">#{nextHtml}</div>',
|
'<div class="datepicker--nav-action" data-action="next">#{nextHtml}</div>',
|
||||||
buttonsContainerTemplate = '<div class="datepicker--buttons"></div>',
|
buttonsContainerTemplate = '<div class="datepicker--buttons"></div>',
|
||||||
button = '<span class="datepicker--button" data-action="#{action}">#{label}</span>';
|
button = '<span class="datepicker--button" data-action="#{action}">#{label}</span>',
|
||||||
|
datepicker = $.fn.datepicker,
|
||||||
|
dp = datepicker.Constructor;
|
||||||
|
|
||||||
Datepicker.Navigation = function (d, opts) {
|
datepicker.Navigation = function (d, opts) {
|
||||||
this.d = d;
|
this.d = d;
|
||||||
this.opts = opts;
|
this.opts = opts;
|
||||||
|
|
||||||
@ -1707,7 +1710,7 @@
|
|||||||
this.init();
|
this.init();
|
||||||
};
|
};
|
||||||
|
|
||||||
Datepicker.Navigation.prototype = {
|
datepicker.Navigation.prototype = {
|
||||||
init: function () {
|
init: function () {
|
||||||
this._buildBaseHtml();
|
this._buildBaseHtml();
|
||||||
this._bindEvents();
|
this._bindEvents();
|
||||||
@ -1735,7 +1738,7 @@
|
|||||||
|
|
||||||
_render: function () {
|
_render: function () {
|
||||||
var title = this._getTitle(this.d.currentDate),
|
var title = this._getTitle(this.d.currentDate),
|
||||||
html = Datepicker.template(template, $.extend({title: title}, this.opts));
|
html = dp.template(template, $.extend({title: title}, this.opts));
|
||||||
this.d.$nav.html(html);
|
this.d.$nav.html(html);
|
||||||
if (this.d.view == 'years') {
|
if (this.d.view == 'years') {
|
||||||
$('.datepicker--nav-title', this.d.$nav).addClass('-disabled-');
|
$('.datepicker--nav-title', this.d.$nav).addClass('-disabled-');
|
||||||
@ -1756,7 +1759,7 @@
|
|||||||
action: type,
|
action: type,
|
||||||
label: this.d.loc[type]
|
label: this.d.loc[type]
|
||||||
},
|
},
|
||||||
html = Datepicker.template(button, data);
|
html = dp.template(button, data);
|
||||||
|
|
||||||
if ($('[data-action=' + type + ']', this.$buttonsContainer).length) return;
|
if ($('[data-action=' + type + ']', this.$buttonsContainer).length) return;
|
||||||
this.$buttonsContainer.append(html);
|
this.$buttonsContainer.append(html);
|
||||||
@ -1847,7 +1850,8 @@
|
|||||||
' </div>' +
|
' </div>' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
'</div>',
|
'</div>',
|
||||||
datepicker = Datepicker;
|
datepicker = $.fn.datepicker,
|
||||||
|
dp = datepicker.Constructor;
|
||||||
|
|
||||||
datepicker.Timepicker = function (inst, opts) {
|
datepicker.Timepicker = function (inst, opts) {
|
||||||
this.d = inst;
|
this.d = inst;
|
||||||
@ -1873,7 +1877,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
_setInitialTime: function (date, parse) {
|
_setInitialTime: function (date, parse) {
|
||||||
var _date = datepicker.getParsedDate(date);
|
var _date = dp.getParsedDate(date);
|
||||||
|
|
||||||
this._handleDate(date);
|
this._handleDate(date);
|
||||||
this.hours = _date.hours < this.minHours ? this.minHours : _date.hours;
|
this.hours = _date.hours < this.minHours ? this.minHours : _date.hours;
|
||||||
@ -1921,7 +1925,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
_buildHTML: function () {
|
_buildHTML: function () {
|
||||||
var lz = datepicker.getLeadingZeroNum,
|
var lz = dp.getLeadingZeroNum,
|
||||||
data = {
|
data = {
|
||||||
hourMin: this.minHours,
|
hourMin: this.minHours,
|
||||||
hourMax: lz(this.maxHours),
|
hourMax: lz(this.maxHours),
|
||||||
@ -1932,7 +1936,7 @@
|
|||||||
minStep: this.opts.minutesStep,
|
minStep: this.opts.minutesStep,
|
||||||
minValue: lz(this.minutes)
|
minValue: lz(this.minutes)
|
||||||
},
|
},
|
||||||
_template = datepicker.template(template, data);
|
_template = dp.template(template, data);
|
||||||
|
|
||||||
this.$timepicker = $(_template).appendTo(this.d.$datepicker);
|
this.$timepicker = $(_template).appendTo(this.d.$datepicker);
|
||||||
this.$ranges = $('[type="range"]', this.$timepicker);
|
this.$ranges = $('[type="range"]', this.$timepicker);
|
||||||
@ -1951,8 +1955,8 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
_updateCurrentTime: function () {
|
_updateCurrentTime: function () {
|
||||||
var h = datepicker.getLeadingZeroNum(this.displayHours),
|
var h = dp.getLeadingZeroNum(this.displayHours),
|
||||||
m = datepicker.getLeadingZeroNum(this.minutes);
|
m = dp.getLeadingZeroNum(this.minutes);
|
||||||
|
|
||||||
this.$hoursText.html(h);
|
this.$hoursText.html(h);
|
||||||
this.$minutesText.html(m);
|
this.$minutesText.html(m);
|
||||||
@ -1986,9 +1990,9 @@
|
|||||||
this._setDefaultMinMaxTime();
|
this._setDefaultMinMaxTime();
|
||||||
|
|
||||||
if (date) {
|
if (date) {
|
||||||
if (datepicker.isSame(date, this.d.opts.minDate)) {
|
if (dp.isSame(date, this.d.opts.minDate)) {
|
||||||
this._setMinTimeFromDate(this.d.opts.minDate);
|
this._setMinTimeFromDate(this.d.opts.minDate);
|
||||||
} else if (datepicker.isSame(date, this.d.opts.maxDate)) {
|
} else if (dp.isSame(date, this.d.opts.maxDate)) {
|
||||||
this._setMaxTimeFromDate(this.d.opts.maxDate);
|
this._setMaxTimeFromDate(this.d.opts.maxDate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2012,7 +2016,7 @@
|
|||||||
hours = date;
|
hours = date;
|
||||||
|
|
||||||
if (date instanceof Date) {
|
if (date instanceof Date) {
|
||||||
d = datepicker.getParsedDate(date);
|
d = dp.getParsedDate(date);
|
||||||
hours = d.hours;
|
hours = d.hours;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
4
dist/js/datepicker.min.js
vendored
4
dist/js/datepicker.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/js/i18n/datepicker.de.js
vendored
2
dist/js/i18n/datepicker.de.js
vendored
@ -1,4 +1,4 @@
|
|||||||
Datepicker.language['de'] = {
|
$.fn.datepicker.language['de'] = {
|
||||||
days: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
|
days: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
|
||||||
daysShort: ['Son', 'Mon', 'Die', 'Mit', 'Don', 'Fre', 'Sam'],
|
daysShort: ['Son', 'Mon', 'Die', 'Mit', 'Don', 'Fre', 'Sam'],
|
||||||
daysMin: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
|
daysMin: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
|
||||||
|
|||||||
2
dist/js/i18n/datepicker.en.js
vendored
2
dist/js/i18n/datepicker.en.js
vendored
@ -1,4 +1,4 @@
|
|||||||
Datepicker.language['en'] = {
|
$.fn.datepicker.language['en'] = {
|
||||||
days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
|
days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
|
||||||
daysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
daysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
||||||
daysMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
|
daysMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
|
||||||
|
|||||||
2
dist/js/i18n/datepicker.zh.js
vendored
2
dist/js/i18n/datepicker.zh.js
vendored
@ -1,4 +1,4 @@
|
|||||||
Datepicker.language['zh'] = {
|
$.fn.datepicker.language['zh'] = {
|
||||||
days: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
|
days: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
|
||||||
daysShort: ['日', '一', '二', '三', '四', '五', '六'],
|
daysShort: ['日', '一', '二', '三', '四', '五', '六'],
|
||||||
daysMin: ['日', '一', '二', '三', '四', '五', '六'],
|
daysMin: ['日', '一', '二', '三', '四', '五', '六'],
|
||||||
|
|||||||
@ -14,9 +14,10 @@
|
|||||||
'<div class="datepicker--cells datepicker--cells-years"></div>' +
|
'<div class="datepicker--cells datepicker--cells-years"></div>' +
|
||||||
'</div>'
|
'</div>'
|
||||||
},
|
},
|
||||||
D = Datepicker;
|
datepicker = $.fn.datepicker,
|
||||||
|
dp = datepicker.Constructor;
|
||||||
|
|
||||||
D.Body = function (d, type, opts) {
|
datepicker.Body = function (d, type, opts) {
|
||||||
this.d = d;
|
this.d = d;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.opts = opts;
|
this.opts = opts;
|
||||||
@ -24,7 +25,7 @@
|
|||||||
this.init();
|
this.init();
|
||||||
};
|
};
|
||||||
|
|
||||||
D.Body.prototype = {
|
datepicker.Body.prototype = {
|
||||||
init: function () {
|
init: function () {
|
||||||
this._buildBaseHtml();
|
this._buildBaseHtml();
|
||||||
this._render();
|
this._render();
|
||||||
@ -60,7 +61,7 @@
|
|||||||
currentDate = new Date(),
|
currentDate = new Date(),
|
||||||
parent = this.d,
|
parent = this.d,
|
||||||
opts = parent.opts,
|
opts = parent.opts,
|
||||||
d = D.getParsedDate(date),
|
d = dp.getParsedDate(date),
|
||||||
render = {},
|
render = {},
|
||||||
html = d.date;
|
html = d.date;
|
||||||
|
|
||||||
@ -104,34 +105,34 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (opts.range) {
|
if (opts.range) {
|
||||||
if (D.isSame(parent.minRange, date, type)) classes += ' -range-from-';
|
if (dp.isSame(parent.minRange, date, type)) classes += ' -range-from-';
|
||||||
if (D.isSame(parent.maxRange, date, type)) classes += ' -range-to-';
|
if (dp.isSame(parent.maxRange, date, type)) classes += ' -range-to-';
|
||||||
|
|
||||||
if (parent.selectedDates.length == 1 && parent.focused) {
|
if (parent.selectedDates.length == 1 && parent.focused) {
|
||||||
if (
|
if (
|
||||||
(D.bigger(parent.minRange, date) && D.less(parent.focused, date)) ||
|
(dp.bigger(parent.minRange, date) && dp.less(parent.focused, date)) ||
|
||||||
(D.less(parent.maxRange, date) && D.bigger(parent.focused, date)))
|
(dp.less(parent.maxRange, date) && dp.bigger(parent.focused, date)))
|
||||||
{
|
{
|
||||||
classes += ' -in-range-'
|
classes += ' -in-range-'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (D.less(parent.maxRange, date) && D.isSame(parent.focused, date)) {
|
if (dp.less(parent.maxRange, date) && dp.isSame(parent.focused, date)) {
|
||||||
classes += ' -range-from-'
|
classes += ' -range-from-'
|
||||||
}
|
}
|
||||||
if (D.bigger(parent.minRange, date) && D.isSame(parent.focused, date)) {
|
if (dp.bigger(parent.minRange, date) && dp.isSame(parent.focused, date)) {
|
||||||
classes += ' -range-to-'
|
classes += ' -range-to-'
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (parent.selectedDates.length == 2) {
|
} else if (parent.selectedDates.length == 2) {
|
||||||
if (D.bigger(parent.minRange, date) && D.less(parent.maxRange, date)) {
|
if (dp.bigger(parent.minRange, date) && dp.less(parent.maxRange, date)) {
|
||||||
classes += ' -in-range-'
|
classes += ' -in-range-'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (D.isSame(currentDate, date, type)) classes += ' -current-';
|
if (dp.isSame(currentDate, date, type)) classes += ' -current-';
|
||||||
if (parent.focused && D.isSame(date, parent.focused, type)) classes += ' -focus-';
|
if (parent.focused && dp.isSame(date, parent.focused, type)) classes += ' -focus-';
|
||||||
if (parent._isSelected(date, type)) classes += ' -selected-';
|
if (parent._isSelected(date, type)) classes += ' -selected-';
|
||||||
if (!parent._isInRange(date, type) || render.disabled) classes += ' -disabled-';
|
if (!parent._isInRange(date, type) || render.disabled) classes += ' -disabled-';
|
||||||
|
|
||||||
@ -148,7 +149,7 @@
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_getDaysHtml: function (date) {
|
_getDaysHtml: function (date) {
|
||||||
var totalMonthDays = D.getDaysCount(date),
|
var totalMonthDays = dp.getDaysCount(date),
|
||||||
firstMonthDay = new Date(date.getFullYear(), date.getMonth(), 1).getDay(),
|
firstMonthDay = new Date(date.getFullYear(), date.getMonth(), 1).getDay(),
|
||||||
lastMonthDay = new Date(date.getFullYear(), date.getMonth(), totalMonthDays).getDay(),
|
lastMonthDay = new Date(date.getFullYear(), date.getMonth(), totalMonthDays).getDay(),
|
||||||
daysFromPevMonth = firstMonthDay - this.d.loc.firstDay,
|
daysFromPevMonth = firstMonthDay - this.d.loc.firstDay,
|
||||||
@ -188,7 +189,7 @@
|
|||||||
*/
|
*/
|
||||||
_getMonthsHtml: function (date) {
|
_getMonthsHtml: function (date) {
|
||||||
var html = '',
|
var html = '',
|
||||||
d = D.getParsedDate(date),
|
d = dp.getParsedDate(date),
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
while(i < 12) {
|
while(i < 12) {
|
||||||
@ -206,8 +207,8 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
_getYearsHtml: function (date) {
|
_getYearsHtml: function (date) {
|
||||||
var d = D.getParsedDate(date),
|
var d = dp.getParsedDate(date),
|
||||||
decade = D.getDecade(date),
|
decade = dp.getDecade(date),
|
||||||
firstYear = decade[0] - 1,
|
firstYear = decade[0] - 1,
|
||||||
html = '',
|
html = '',
|
||||||
i = firstYear;
|
i = firstYear;
|
||||||
|
|||||||
@ -1,6 +1,4 @@
|
|||||||
window.Datepicker = '';
|
;(function () {
|
||||||
|
|
||||||
(function () {
|
|
||||||
var pluginName = 'datepicker',
|
var pluginName = 'datepicker',
|
||||||
autoInitSelector = '.datepicker-here',
|
autoInitSelector = '.datepicker-here',
|
||||||
$body, $datepickersContainer,
|
$body, $datepickersContainer,
|
||||||
@ -98,7 +96,7 @@ window.Datepicker = '';
|
|||||||
},
|
},
|
||||||
datepicker;
|
datepicker;
|
||||||
|
|
||||||
Datepicker = function (el, options) {
|
var Datepicker = function (el, options) {
|
||||||
this.el = el;
|
this.el = el;
|
||||||
this.$el = $(el);
|
this.$el = $(el);
|
||||||
|
|
||||||
@ -167,13 +165,13 @@ window.Datepicker = '';
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.opts.timepicker) {
|
if (this.opts.timepicker) {
|
||||||
this.timepicker = new Datepicker.Timepicker(this, this.opts);
|
this.timepicker = new $.fn.datepicker.Timepicker(this, this.opts);
|
||||||
this._bindTimepickerEvents();
|
this._bindTimepickerEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.views[this.currentView] = new 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 Datepicker.Navigation(this, this.opts);
|
this.nav = new $.fn.datepicker.Navigation(this, this.opts);
|
||||||
this.view = this.currentView;
|
this.view = this.currentView;
|
||||||
|
|
||||||
this.$el.on('clickCell.adp', this._onClickCell.bind(this));
|
this.$el.on('clickCell.adp', this._onClickCell.bind(this));
|
||||||
@ -213,15 +211,15 @@ window.Datepicker = '';
|
|||||||
|
|
||||||
_defineLocale: function (lang) {
|
_defineLocale: function (lang) {
|
||||||
if (typeof lang == 'string') {
|
if (typeof lang == 'string') {
|
||||||
this.loc = Datepicker.language[lang];
|
this.loc = $.fn.datepicker.language[lang];
|
||||||
if (!this.loc) {
|
if (!this.loc) {
|
||||||
console.warn('Can\'t find language "' + lang + '" in Datepicker.language, will use "ru" instead');
|
console.warn('Can\'t find language "' + lang + '" in Datepicker.language, will use "ru" instead');
|
||||||
this.loc = $.extend(true, {}, Datepicker.language.ru)
|
this.loc = $.extend(true, {}, $.fn.datepicker.language.ru)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loc = $.extend(true, {}, Datepicker.language.ru, Datepicker.language[lang])
|
this.loc = $.extend(true, {}, $.fn.datepicker.language.ru, $.fn.datepicker.language[lang])
|
||||||
} else {
|
} else {
|
||||||
this.loc = $.extend(true, {}, Datepicker.language.ru, lang)
|
this.loc = $.extend(true, {}, $.fn.datepicker.language.ru, lang)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.opts.dateFormat) {
|
if (this.opts.dateFormat) {
|
||||||
@ -1240,7 +1238,7 @@ window.Datepicker = '';
|
|||||||
|
|
||||||
if (this.inited) {
|
if (this.inited) {
|
||||||
if (!this.views[val]) {
|
if (!this.views[val]) {
|
||||||
this.views[val] = new Datepicker.Body(this, val, this.opts)
|
this.views[val] = new $.fn.datepicker.Body(this, val, this.opts)
|
||||||
} else {
|
} else {
|
||||||
this.views[val]._render();
|
this.views[val]._render();
|
||||||
}
|
}
|
||||||
@ -1346,7 +1344,23 @@ window.Datepicker = '';
|
|||||||
return parseInt(num) < 10 ? '0' + num : num;
|
return parseInt(num) < 10 ? '0' + num : num;
|
||||||
};
|
};
|
||||||
|
|
||||||
Datepicker.language = {
|
$.fn.datepicker = function ( options ) {
|
||||||
|
return this.each(function () {
|
||||||
|
if (!$.data(this, pluginName)) {
|
||||||
|
$.data(this, pluginName,
|
||||||
|
new Datepicker( this, options ));
|
||||||
|
} else {
|
||||||
|
var _this = $.data(this, pluginName);
|
||||||
|
|
||||||
|
_this.opts = $.extend(true, _this.opts, options);
|
||||||
|
_this.update();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
$.fn.datepicker.Constructor = Datepicker;
|
||||||
|
|
||||||
|
$.fn.datepicker.language = {
|
||||||
ru: {
|
ru: {
|
||||||
days: ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'],
|
days: ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'],
|
||||||
daysShort: ['Вос','Пон','Вто','Сре','Чет','Пят','Суб'],
|
daysShort: ['Вос','Пон','Вто','Сре','Чет','Пят','Суб'],
|
||||||
@ -1361,20 +1375,6 @@ window.Datepicker = '';
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$.fn[pluginName] = function ( options ) {
|
|
||||||
return this.each(function () {
|
|
||||||
if (!$.data(this, pluginName)) {
|
|
||||||
$.data(this, pluginName,
|
|
||||||
new Datepicker( this, options ));
|
|
||||||
} else {
|
|
||||||
var _this = $.data(this, pluginName);
|
|
||||||
|
|
||||||
_this.opts = $.extend(true, _this.opts, options);
|
|
||||||
_this.update();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
$(autoInitSelector).datepicker();
|
$(autoInitSelector).datepicker();
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
Datepicker.language['de'] = {
|
$.fn.datepicker.language['de'] = {
|
||||||
days: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
|
days: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
|
||||||
daysShort: ['Son', 'Mon', 'Die', 'Mit', 'Don', 'Fre', 'Sam'],
|
daysShort: ['Son', 'Mon', 'Die', 'Mit', 'Don', 'Fre', 'Sam'],
|
||||||
daysMin: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
|
daysMin: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
Datepicker.language['en'] = {
|
$.fn.datepicker.language['en'] = {
|
||||||
days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
|
days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
|
||||||
daysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
daysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
||||||
daysMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
|
daysMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
Datepicker.language['zh'] = {
|
$.fn.datepicker.language['zh'] = {
|
||||||
days: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
|
days: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
|
||||||
daysShort: ['日', '一', '二', '三', '四', '五', '六'],
|
daysShort: ['日', '一', '二', '三', '四', '五', '六'],
|
||||||
daysMin: ['日', '一', '二', '三', '四', '五', '六'],
|
daysMin: ['日', '一', '二', '三', '四', '五', '六'],
|
||||||
|
|||||||
@ -4,9 +4,11 @@
|
|||||||
'<div class="datepicker--nav-title">#{title}</div>' +
|
'<div class="datepicker--nav-title">#{title}</div>' +
|
||||||
'<div class="datepicker--nav-action" data-action="next">#{nextHtml}</div>',
|
'<div class="datepicker--nav-action" data-action="next">#{nextHtml}</div>',
|
||||||
buttonsContainerTemplate = '<div class="datepicker--buttons"></div>',
|
buttonsContainerTemplate = '<div class="datepicker--buttons"></div>',
|
||||||
button = '<span class="datepicker--button" data-action="#{action}">#{label}</span>';
|
button = '<span class="datepicker--button" data-action="#{action}">#{label}</span>',
|
||||||
|
datepicker = $.fn.datepicker,
|
||||||
|
dp = datepicker.Constructor;
|
||||||
|
|
||||||
Datepicker.Navigation = function (d, opts) {
|
datepicker.Navigation = function (d, opts) {
|
||||||
this.d = d;
|
this.d = d;
|
||||||
this.opts = opts;
|
this.opts = opts;
|
||||||
|
|
||||||
@ -15,7 +17,7 @@
|
|||||||
this.init();
|
this.init();
|
||||||
};
|
};
|
||||||
|
|
||||||
Datepicker.Navigation.prototype = {
|
datepicker.Navigation.prototype = {
|
||||||
init: function () {
|
init: function () {
|
||||||
this._buildBaseHtml();
|
this._buildBaseHtml();
|
||||||
this._bindEvents();
|
this._bindEvents();
|
||||||
@ -43,7 +45,7 @@
|
|||||||
|
|
||||||
_render: function () {
|
_render: function () {
|
||||||
var title = this._getTitle(this.d.currentDate),
|
var title = this._getTitle(this.d.currentDate),
|
||||||
html = Datepicker.template(template, $.extend({title: title}, this.opts));
|
html = dp.template(template, $.extend({title: title}, this.opts));
|
||||||
this.d.$nav.html(html);
|
this.d.$nav.html(html);
|
||||||
if (this.d.view == 'years') {
|
if (this.d.view == 'years') {
|
||||||
$('.datepicker--nav-title', this.d.$nav).addClass('-disabled-');
|
$('.datepicker--nav-title', this.d.$nav).addClass('-disabled-');
|
||||||
@ -64,7 +66,7 @@
|
|||||||
action: type,
|
action: type,
|
||||||
label: this.d.loc[type]
|
label: this.d.loc[type]
|
||||||
},
|
},
|
||||||
html = Datepicker.template(button, data);
|
html = dp.template(button, data);
|
||||||
|
|
||||||
if ($('[data-action=' + type + ']', this.$buttonsContainer).length) return;
|
if ($('[data-action=' + type + ']', this.$buttonsContainer).length) return;
|
||||||
this.$buttonsContainer.append(html);
|
this.$buttonsContainer.append(html);
|
||||||
|
|||||||
@ -14,7 +14,8 @@
|
|||||||
' </div>' +
|
' </div>' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
'</div>',
|
'</div>',
|
||||||
datepicker = Datepicker;
|
datepicker = $.fn.datepicker,
|
||||||
|
dp = datepicker.Constructor;
|
||||||
|
|
||||||
datepicker.Timepicker = function (inst, opts) {
|
datepicker.Timepicker = function (inst, opts) {
|
||||||
this.d = inst;
|
this.d = inst;
|
||||||
@ -40,7 +41,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
_setInitialTime: function (date, parse) {
|
_setInitialTime: function (date, parse) {
|
||||||
var _date = datepicker.getParsedDate(date);
|
var _date = dp.getParsedDate(date);
|
||||||
|
|
||||||
this._handleDate(date);
|
this._handleDate(date);
|
||||||
this.hours = _date.hours < this.minHours ? this.minHours : _date.hours;
|
this.hours = _date.hours < this.minHours ? this.minHours : _date.hours;
|
||||||
@ -88,7 +89,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
_buildHTML: function () {
|
_buildHTML: function () {
|
||||||
var lz = datepicker.getLeadingZeroNum,
|
var lz = dp.getLeadingZeroNum,
|
||||||
data = {
|
data = {
|
||||||
hourMin: this.minHours,
|
hourMin: this.minHours,
|
||||||
hourMax: lz(this.maxHours),
|
hourMax: lz(this.maxHours),
|
||||||
@ -99,7 +100,7 @@
|
|||||||
minStep: this.opts.minutesStep,
|
minStep: this.opts.minutesStep,
|
||||||
minValue: lz(this.minutes)
|
minValue: lz(this.minutes)
|
||||||
},
|
},
|
||||||
_template = datepicker.template(template, data);
|
_template = dp.template(template, data);
|
||||||
|
|
||||||
this.$timepicker = $(_template).appendTo(this.d.$datepicker);
|
this.$timepicker = $(_template).appendTo(this.d.$datepicker);
|
||||||
this.$ranges = $('[type="range"]', this.$timepicker);
|
this.$ranges = $('[type="range"]', this.$timepicker);
|
||||||
@ -118,8 +119,8 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
_updateCurrentTime: function () {
|
_updateCurrentTime: function () {
|
||||||
var h = datepicker.getLeadingZeroNum(this.displayHours),
|
var h = dp.getLeadingZeroNum(this.displayHours),
|
||||||
m = datepicker.getLeadingZeroNum(this.minutes);
|
m = dp.getLeadingZeroNum(this.minutes);
|
||||||
|
|
||||||
this.$hoursText.html(h);
|
this.$hoursText.html(h);
|
||||||
this.$minutesText.html(m);
|
this.$minutesText.html(m);
|
||||||
@ -153,9 +154,9 @@
|
|||||||
this._setDefaultMinMaxTime();
|
this._setDefaultMinMaxTime();
|
||||||
|
|
||||||
if (date) {
|
if (date) {
|
||||||
if (datepicker.isSame(date, this.d.opts.minDate)) {
|
if (dp.isSame(date, this.d.opts.minDate)) {
|
||||||
this._setMinTimeFromDate(this.d.opts.minDate);
|
this._setMinTimeFromDate(this.d.opts.minDate);
|
||||||
} else if (datepicker.isSame(date, this.d.opts.maxDate)) {
|
} else if (dp.isSame(date, this.d.opts.maxDate)) {
|
||||||
this._setMaxTimeFromDate(this.d.opts.maxDate);
|
this._setMaxTimeFromDate(this.d.opts.maxDate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -179,7 +180,7 @@
|
|||||||
hours = date;
|
hours = date;
|
||||||
|
|
||||||
if (date instanceof Date) {
|
if (date instanceof Date) {
|
||||||
d = datepicker.getParsedDate(date);
|
d = dp.getParsedDate(date);
|
||||||
hours = d.hours;
|
hours = d.hours;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -34,7 +34,7 @@ var assert = chai.assert,
|
|||||||
onSelect: function (fd, d, inst) {
|
onSelect: function (fd, d, inst) {
|
||||||
expect(fd).to.be.equal('13.01.2016');
|
expect(fd).to.be.equal('13.01.2016');
|
||||||
expect(d).to.be.instanceof(Date);
|
expect(d).to.be.instanceof(Date);
|
||||||
expect(inst).to.be.instanceof(Datepicker);
|
expect(inst).to.be.instanceof($.fn.datepicker.Constructor);
|
||||||
}
|
}
|
||||||
}).data('datepicker');
|
}).data('datepicker');
|
||||||
|
|
||||||
|
|||||||
@ -58,7 +58,7 @@ describe('Options', function () {
|
|||||||
language: 'en'
|
language: 'en'
|
||||||
}).data('datepicker');
|
}).data('datepicker');
|
||||||
|
|
||||||
expect(dp.loc.days).to.eql(Datepicker.language.en.days);
|
expect(dp.loc.days).to.eql($.fn.datepicker.language.en.days);
|
||||||
});
|
});
|
||||||
it('should change language to custom if object is passed', function () {
|
it('should change language to custom if object is passed', function () {
|
||||||
var daysMin = ['В','П','В','С','Ч','П','С'];
|
var daysMin = ['В','П','В','С','Ч','П','С'];
|
||||||
@ -69,7 +69,7 @@ describe('Options', function () {
|
|||||||
}).data('datepicker');
|
}).data('datepicker');
|
||||||
|
|
||||||
expect(dp.loc.daysMin).to.eql(daysMin);
|
expect(dp.loc.daysMin).to.eql(daysMin);
|
||||||
expect(dp.loc.days).to.eql(Datepicker.language.ru.days);
|
expect(dp.loc.days).to.eql($.fn.datepicker.language.ru.days);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,22 +1,24 @@
|
|||||||
var assert = chai.assert,
|
var assert = chai.assert,
|
||||||
expect = chai.expect;
|
expect = chai.expect,
|
||||||
|
plugin = $.fn.datepicker.Constructor;
|
||||||
|
|
||||||
describe('Datepicker', function () {
|
describe('Datepicker', function () {
|
||||||
describe('getDaysCount', function () {
|
describe('getDaysCount', function () {
|
||||||
it('should return 31 days in December', function () {
|
it('should return 31 days in December', function () {
|
||||||
assert.equal(Datepicker.getDaysCount(new Date(2015, 11)), 31)
|
console.log(plugin.getDaysCount);
|
||||||
|
assert.equal(plugin.getDaysCount(new Date(2015, 11)), 31)
|
||||||
});
|
});
|
||||||
it('should return 30 days in September', function () {
|
it('should return 30 days in September', function () {
|
||||||
assert.equal(Datepicker.getDaysCount(new Date(2015, 8)), 30)
|
assert.equal(plugin.getDaysCount(new Date(2015, 8)), 30)
|
||||||
});
|
});
|
||||||
it('should return 28 days in February', function () {
|
it('should return 28 days in February', function () {
|
||||||
assert.equal(Datepicker.getDaysCount(new Date(2015, 1)), 28)
|
assert.equal(plugin.getDaysCount(new Date(2015, 1)), 28)
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getParsedDate', function () {
|
describe('getParsedDate', function () {
|
||||||
var currentDate = new Date(),
|
var currentDate = new Date(),
|
||||||
date = Datepicker.getParsedDate(currentDate);
|
date = plugin.getParsedDate(currentDate);
|
||||||
|
|
||||||
it('should return object with detailed date fields', function () {
|
it('should return object with detailed date fields', function () {
|
||||||
expect(date).to.have.all.keys(['year','month','fullMonth','date', 'fullDate', 'day','hours', 'fullHours', 'minutes', 'fullMinutes']);
|
expect(date).to.have.all.keys(['year','month','fullMonth','date', 'fullDate', 'day','hours', 'fullHours', 'minutes', 'fullMinutes']);
|
||||||
@ -76,7 +78,7 @@ describe('Datepicker', function () {
|
|||||||
|
|
||||||
describe('getDecade', function () {
|
describe('getDecade', function () {
|
||||||
it('should return array with first and last years in decade', function () {
|
it('should return array with first and last years in decade', function () {
|
||||||
var decade = Datepicker.getDecade(new Date(2015, 1));
|
var decade = plugin.getDecade(new Date(2015, 1));
|
||||||
|
|
||||||
expect(decade).to.be.an('array');
|
expect(decade).to.be.an('array');
|
||||||
assert.equal(decade[0], 2010)
|
assert.equal(decade[0], 2010)
|
||||||
@ -87,7 +89,7 @@ describe('Datepicker', function () {
|
|||||||
describe('template', function () {
|
describe('template', function () {
|
||||||
it('should return string with replaced #{} signs', function () {
|
it('should return string with replaced #{} signs', function () {
|
||||||
var template = 'Hello #{who}';
|
var template = 'Hello #{who}';
|
||||||
assert.equal(Datepicker.template(template, {who:'World!'}), 'Hello World!')
|
assert.equal(plugin.template(template, {who:'World!'}), 'Hello World!')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -98,33 +100,33 @@ describe('Datepicker', function () {
|
|||||||
date4 = new Date(2016, 11, 14);
|
date4 = new Date(2016, 11, 14);
|
||||||
|
|
||||||
it('should return true if dates are equal', function () {
|
it('should return true if dates are equal', function () {
|
||||||
assert(Datepicker.isSame(date1,date2))
|
assert(plugin.isSame(date1,date2))
|
||||||
})
|
})
|
||||||
it('should return false when checking dates with different months', function () {
|
it('should return false when checking dates with different months', function () {
|
||||||
assert.isFalse(Datepicker.isSame(date1,date3))
|
assert.isFalse(plugin.isSame(date1,date3))
|
||||||
})
|
})
|
||||||
it('should return false when checking dates with different years', function () {
|
it('should return false when checking dates with different years', function () {
|
||||||
assert.isFalse(Datepicker.isSame(date1,date4))
|
assert.isFalse(plugin.isSame(date1,date4))
|
||||||
})
|
})
|
||||||
it('should return true when comparing months', function () {
|
it('should return true when comparing months', function () {
|
||||||
assert(Datepicker.isSame(date1, date2,'month'))
|
assert(plugin.isSame(date1, date2,'month'))
|
||||||
})
|
})
|
||||||
it('should return false when comparing months from different years', function () {
|
it('should return false when comparing months from different years', function () {
|
||||||
assert.isFalse(Datepicker.isSame(date1, date4, 'month'))
|
assert.isFalse(plugin.isSame(date1, date4, 'month'))
|
||||||
})
|
})
|
||||||
it('should return true when comparing years', function () {
|
it('should return true when comparing years', function () {
|
||||||
assert(Datepicker.isSame(date1, date2, 'year'))
|
assert(plugin.isSame(date1, date2, 'year'))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('less(date1, date2)', function () {
|
describe('less(date1, date2)', function () {
|
||||||
it('should return true if date2 less then date1', function () {
|
it('should return true if date2 less then date1', function () {
|
||||||
assert(Datepicker.less(new Date(2015, 11, 14), new Date(2015, 11, 13)))
|
assert(plugin.less(new Date(2015, 11, 14), new Date(2015, 11, 13)))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
describe('bigger(date1, date2)', function () {
|
describe('bigger(date1, date2)', function () {
|
||||||
it('should return true if date2 bigger then date1', function () {
|
it('should return true if date2 bigger then date1', function () {
|
||||||
assert(Datepicker.bigger(new Date(2015, 11, 14), new Date(2015, 11, 15)))
|
assert(plugin.bigger(new Date(2015, 11, 14), new Date(2015, 11, 15)))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user