remove global 'Datepicker' var, add it to $.fn, closes #32

This commit is contained in:
t1m0n 2016-04-06 10:58:12 +03:00
parent c648cba3ab
commit 12e7c3dd1f
15 changed files with 152 additions and 142 deletions

120
dist/js/datepicker.js vendored
View File

@ -1,6 +1,4 @@
;(function (window, $, undefined) { window.Datepicker = '';
(function () {
;(function (window, $, undefined) { ;(function () {
var pluginName = 'datepicker',
autoInitSelector = '.datepicker-here',
$body, $datepickersContainer,
@ -98,7 +96,7 @@
},
datepicker;
Datepicker = function (el, options) {
var Datepicker = function (el, options) {
this.el = el;
this.$el = $(el);
@ -167,13 +165,13 @@
}
if (this.opts.timepicker) {
this.timepicker = new Datepicker.Timepicker(this, this.opts);
this.timepicker = new $.fn.datepicker.Timepicker(this, this.opts);
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.nav = new Datepicker.Navigation(this, this.opts);
this.nav = new $.fn.datepicker.Navigation(this, this.opts);
this.view = this.currentView;
this.$el.on('clickCell.adp', this._onClickCell.bind(this));
@ -213,15 +211,15 @@
_defineLocale: function (lang) {
if (typeof lang == 'string') {
this.loc = Datepicker.language[lang];
this.loc = $.fn.datepicker.language[lang];
if (!this.loc) {
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 {
this.loc = $.extend(true, {}, Datepicker.language.ru, lang)
this.loc = $.extend(true, {}, $.fn.datepicker.language.ru, lang)
}
if (this.opts.dateFormat) {
@ -1240,7 +1238,7 @@
if (this.inited) {
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 {
this.views[val]._render();
}
@ -1346,7 +1344,23 @@
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: {
days: ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'],
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 () {
$(autoInitSelector).datepicker();
})
@ -1397,9 +1397,10 @@
'<div class="datepicker--cells datepicker--cells-years"></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.type = type;
this.opts = opts;
@ -1407,7 +1408,7 @@
this.init();
};
D.Body.prototype = {
datepicker.Body.prototype = {
init: function () {
this._buildBaseHtml();
this._render();
@ -1443,7 +1444,7 @@
currentDate = new Date(),
parent = this.d,
opts = parent.opts,
d = D.getParsedDate(date),
d = dp.getParsedDate(date),
render = {},
html = d.date;
@ -1487,34 +1488,34 @@
}
if (opts.range) {
if (D.isSame(parent.minRange, date, type)) classes += ' -range-from-';
if (D.isSame(parent.maxRange, date, type)) classes += ' -range-to-';
if (dp.isSame(parent.minRange, date, type)) classes += ' -range-from-';
if (dp.isSame(parent.maxRange, date, type)) classes += ' -range-to-';
if (parent.selectedDates.length == 1 && parent.focused) {
if (
(D.bigger(parent.minRange, date) && D.less(parent.focused, date)) ||
(D.less(parent.maxRange, date) && D.bigger(parent.focused, date)))
(dp.bigger(parent.minRange, date) && dp.less(parent.focused, date)) ||
(dp.less(parent.maxRange, date) && dp.bigger(parent.focused, date)))
{
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-'
}
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-'
}
} 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-'
}
}
}
if (D.isSame(currentDate, date, type)) classes += ' -current-';
if (parent.focused && D.isSame(date, parent.focused, type)) classes += ' -focus-';
if (dp.isSame(currentDate, date, type)) classes += ' -current-';
if (parent.focused && dp.isSame(date, parent.focused, type)) classes += ' -focus-';
if (parent._isSelected(date, type)) classes += ' -selected-';
if (!parent._isInRange(date, type) || render.disabled) classes += ' -disabled-';
@ -1531,7 +1532,7 @@
* @private
*/
_getDaysHtml: function (date) {
var totalMonthDays = D.getDaysCount(date),
var totalMonthDays = dp.getDaysCount(date),
firstMonthDay = new Date(date.getFullYear(), date.getMonth(), 1).getDay(),
lastMonthDay = new Date(date.getFullYear(), date.getMonth(), totalMonthDays).getDay(),
daysFromPevMonth = firstMonthDay - this.d.loc.firstDay,
@ -1571,7 +1572,7 @@
*/
_getMonthsHtml: function (date) {
var html = '',
d = D.getParsedDate(date),
d = dp.getParsedDate(date),
i = 0;
while(i < 12) {
@ -1589,8 +1590,8 @@
},
_getYearsHtml: function (date) {
var d = D.getParsedDate(date),
decade = D.getDecade(date),
var d = dp.getParsedDate(date),
decade = dp.getDecade(date),
firstYear = decade[0] - 1,
html = '',
i = firstYear;
@ -1696,9 +1697,11 @@
'<div class="datepicker--nav-title">#{title}</div>' +
'<div class="datepicker--nav-action" data-action="next">#{nextHtml}</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.opts = opts;
@ -1707,7 +1710,7 @@
this.init();
};
Datepicker.Navigation.prototype = {
datepicker.Navigation.prototype = {
init: function () {
this._buildBaseHtml();
this._bindEvents();
@ -1735,7 +1738,7 @@
_render: function () {
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);
if (this.d.view == 'years') {
$('.datepicker--nav-title', this.d.$nav).addClass('-disabled-');
@ -1756,7 +1759,7 @@
action: type,
label: this.d.loc[type]
},
html = Datepicker.template(button, data);
html = dp.template(button, data);
if ($('[data-action=' + type + ']', this.$buttonsContainer).length) return;
this.$buttonsContainer.append(html);
@ -1847,7 +1850,8 @@
' </div>' +
'</div>' +
'</div>',
datepicker = Datepicker;
datepicker = $.fn.datepicker,
dp = datepicker.Constructor;
datepicker.Timepicker = function (inst, opts) {
this.d = inst;
@ -1873,7 +1877,7 @@
},
_setInitialTime: function (date, parse) {
var _date = datepicker.getParsedDate(date);
var _date = dp.getParsedDate(date);
this._handleDate(date);
this.hours = _date.hours < this.minHours ? this.minHours : _date.hours;
@ -1921,7 +1925,7 @@
},
_buildHTML: function () {
var lz = datepicker.getLeadingZeroNum,
var lz = dp.getLeadingZeroNum,
data = {
hourMin: this.minHours,
hourMax: lz(this.maxHours),
@ -1932,7 +1936,7 @@
minStep: this.opts.minutesStep,
minValue: lz(this.minutes)
},
_template = datepicker.template(template, data);
_template = dp.template(template, data);
this.$timepicker = $(_template).appendTo(this.d.$datepicker);
this.$ranges = $('[type="range"]', this.$timepicker);
@ -1951,8 +1955,8 @@
},
_updateCurrentTime: function () {
var h = datepicker.getLeadingZeroNum(this.displayHours),
m = datepicker.getLeadingZeroNum(this.minutes);
var h = dp.getLeadingZeroNum(this.displayHours),
m = dp.getLeadingZeroNum(this.minutes);
this.$hoursText.html(h);
this.$minutesText.html(m);
@ -1986,9 +1990,9 @@
this._setDefaultMinMaxTime();
if (date) {
if (datepicker.isSame(date, this.d.opts.minDate)) {
if (dp.isSame(date, 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);
}
}
@ -2012,7 +2016,7 @@
hours = date;
if (date instanceof Date) {
d = datepicker.getParsedDate(date);
d = dp.getParsedDate(date);
hours = d.hours;
}

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
Datepicker.language['de'] = {
$.fn.datepicker.language['de'] = {
days: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
daysShort: ['Son', 'Mon', 'Die', 'Mit', 'Don', 'Fre', 'Sam'],
daysMin: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],

View File

@ -1,4 +1,4 @@
Datepicker.language['en'] = {
$.fn.datepicker.language['en'] = {
days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
daysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
daysMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],

View File

@ -1,4 +1,4 @@
Datepicker.language['zh'] = {
$.fn.datepicker.language['zh'] = {
days: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
daysShort: ['日', '一', '二', '三', '四', '五', '六'],
daysMin: ['日', '一', '二', '三', '四', '五', '六'],

View File

@ -14,9 +14,10 @@
'<div class="datepicker--cells datepicker--cells-years"></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.type = type;
this.opts = opts;
@ -24,7 +25,7 @@
this.init();
};
D.Body.prototype = {
datepicker.Body.prototype = {
init: function () {
this._buildBaseHtml();
this._render();
@ -60,7 +61,7 @@
currentDate = new Date(),
parent = this.d,
opts = parent.opts,
d = D.getParsedDate(date),
d = dp.getParsedDate(date),
render = {},
html = d.date;
@ -104,34 +105,34 @@
}
if (opts.range) {
if (D.isSame(parent.minRange, date, type)) classes += ' -range-from-';
if (D.isSame(parent.maxRange, date, type)) classes += ' -range-to-';
if (dp.isSame(parent.minRange, date, type)) classes += ' -range-from-';
if (dp.isSame(parent.maxRange, date, type)) classes += ' -range-to-';
if (parent.selectedDates.length == 1 && parent.focused) {
if (
(D.bigger(parent.minRange, date) && D.less(parent.focused, date)) ||
(D.less(parent.maxRange, date) && D.bigger(parent.focused, date)))
(dp.bigger(parent.minRange, date) && dp.less(parent.focused, date)) ||
(dp.less(parent.maxRange, date) && dp.bigger(parent.focused, date)))
{
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-'
}
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-'
}
} 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-'
}
}
}
if (D.isSame(currentDate, date, type)) classes += ' -current-';
if (parent.focused && D.isSame(date, parent.focused, type)) classes += ' -focus-';
if (dp.isSame(currentDate, date, type)) classes += ' -current-';
if (parent.focused && dp.isSame(date, parent.focused, type)) classes += ' -focus-';
if (parent._isSelected(date, type)) classes += ' -selected-';
if (!parent._isInRange(date, type) || render.disabled) classes += ' -disabled-';
@ -148,7 +149,7 @@
* @private
*/
_getDaysHtml: function (date) {
var totalMonthDays = D.getDaysCount(date),
var totalMonthDays = dp.getDaysCount(date),
firstMonthDay = new Date(date.getFullYear(), date.getMonth(), 1).getDay(),
lastMonthDay = new Date(date.getFullYear(), date.getMonth(), totalMonthDays).getDay(),
daysFromPevMonth = firstMonthDay - this.d.loc.firstDay,
@ -188,7 +189,7 @@
*/
_getMonthsHtml: function (date) {
var html = '',
d = D.getParsedDate(date),
d = dp.getParsedDate(date),
i = 0;
while(i < 12) {
@ -206,8 +207,8 @@
},
_getYearsHtml: function (date) {
var d = D.getParsedDate(date),
decade = D.getDecade(date),
var d = dp.getParsedDate(date),
decade = dp.getDecade(date),
firstYear = decade[0] - 1,
html = '',
i = firstYear;

View File

@ -1,6 +1,4 @@
window.Datepicker = '';
(function () {
;(function () {
var pluginName = 'datepicker',
autoInitSelector = '.datepicker-here',
$body, $datepickersContainer,
@ -98,7 +96,7 @@ window.Datepicker = '';
},
datepicker;
Datepicker = function (el, options) {
var Datepicker = function (el, options) {
this.el = el;
this.$el = $(el);
@ -167,13 +165,13 @@ window.Datepicker = '';
}
if (this.opts.timepicker) {
this.timepicker = new Datepicker.Timepicker(this, this.opts);
this.timepicker = new $.fn.datepicker.Timepicker(this, this.opts);
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.nav = new Datepicker.Navigation(this, this.opts);
this.nav = new $.fn.datepicker.Navigation(this, this.opts);
this.view = this.currentView;
this.$el.on('clickCell.adp', this._onClickCell.bind(this));
@ -213,15 +211,15 @@ window.Datepicker = '';
_defineLocale: function (lang) {
if (typeof lang == 'string') {
this.loc = Datepicker.language[lang];
this.loc = $.fn.datepicker.language[lang];
if (!this.loc) {
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 {
this.loc = $.extend(true, {}, Datepicker.language.ru, lang)
this.loc = $.extend(true, {}, $.fn.datepicker.language.ru, lang)
}
if (this.opts.dateFormat) {
@ -1240,7 +1238,7 @@ window.Datepicker = '';
if (this.inited) {
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 {
this.views[val]._render();
}
@ -1346,7 +1344,23 @@ window.Datepicker = '';
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: {
days: ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'],
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 () {
$(autoInitSelector).datepicker();
})

View File

@ -1,4 +1,4 @@
Datepicker.language['de'] = {
$.fn.datepicker.language['de'] = {
days: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
daysShort: ['Son', 'Mon', 'Die', 'Mit', 'Don', 'Fre', 'Sam'],
daysMin: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],

View File

@ -1,4 +1,4 @@
Datepicker.language['en'] = {
$.fn.datepicker.language['en'] = {
days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
daysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
daysMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],

View File

@ -1,4 +1,4 @@
Datepicker.language['zh'] = {
$.fn.datepicker.language['zh'] = {
days: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
daysShort: ['日', '一', '二', '三', '四', '五', '六'],
daysMin: ['日', '一', '二', '三', '四', '五', '六'],

View File

@ -4,9 +4,11 @@
'<div class="datepicker--nav-title">#{title}</div>' +
'<div class="datepicker--nav-action" data-action="next">#{nextHtml}</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.opts = opts;
@ -15,7 +17,7 @@
this.init();
};
Datepicker.Navigation.prototype = {
datepicker.Navigation.prototype = {
init: function () {
this._buildBaseHtml();
this._bindEvents();
@ -43,7 +45,7 @@
_render: function () {
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);
if (this.d.view == 'years') {
$('.datepicker--nav-title', this.d.$nav).addClass('-disabled-');
@ -64,7 +66,7 @@
action: type,
label: this.d.loc[type]
},
html = Datepicker.template(button, data);
html = dp.template(button, data);
if ($('[data-action=' + type + ']', this.$buttonsContainer).length) return;
this.$buttonsContainer.append(html);

View File

@ -14,7 +14,8 @@
' </div>' +
'</div>' +
'</div>',
datepicker = Datepicker;
datepicker = $.fn.datepicker,
dp = datepicker.Constructor;
datepicker.Timepicker = function (inst, opts) {
this.d = inst;
@ -40,7 +41,7 @@
},
_setInitialTime: function (date, parse) {
var _date = datepicker.getParsedDate(date);
var _date = dp.getParsedDate(date);
this._handleDate(date);
this.hours = _date.hours < this.minHours ? this.minHours : _date.hours;
@ -88,7 +89,7 @@
},
_buildHTML: function () {
var lz = datepicker.getLeadingZeroNum,
var lz = dp.getLeadingZeroNum,
data = {
hourMin: this.minHours,
hourMax: lz(this.maxHours),
@ -99,7 +100,7 @@
minStep: this.opts.minutesStep,
minValue: lz(this.minutes)
},
_template = datepicker.template(template, data);
_template = dp.template(template, data);
this.$timepicker = $(_template).appendTo(this.d.$datepicker);
this.$ranges = $('[type="range"]', this.$timepicker);
@ -118,8 +119,8 @@
},
_updateCurrentTime: function () {
var h = datepicker.getLeadingZeroNum(this.displayHours),
m = datepicker.getLeadingZeroNum(this.minutes);
var h = dp.getLeadingZeroNum(this.displayHours),
m = dp.getLeadingZeroNum(this.minutes);
this.$hoursText.html(h);
this.$minutesText.html(m);
@ -153,9 +154,9 @@
this._setDefaultMinMaxTime();
if (date) {
if (datepicker.isSame(date, this.d.opts.minDate)) {
if (dp.isSame(date, 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);
}
}
@ -179,7 +180,7 @@
hours = date;
if (date instanceof Date) {
d = datepicker.getParsedDate(date);
d = dp.getParsedDate(date);
hours = d.hours;
}

View File

@ -34,7 +34,7 @@ var assert = chai.assert,
onSelect: function (fd, d, inst) {
expect(fd).to.be.equal('13.01.2016');
expect(d).to.be.instanceof(Date);
expect(inst).to.be.instanceof(Datepicker);
expect(inst).to.be.instanceof($.fn.datepicker.Constructor);
}
}).data('datepicker');

View File

@ -58,7 +58,7 @@ describe('Options', function () {
language: 'en'
}).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 () {
var daysMin = ['В','П','В','С','Ч','П','С'];
@ -69,7 +69,7 @@ describe('Options', function () {
}).data('datepicker');
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);
})
});

View File

@ -1,22 +1,24 @@
var assert = chai.assert,
expect = chai.expect;
expect = chai.expect,
plugin = $.fn.datepicker.Constructor;
describe('Datepicker', function () {
describe('getDaysCount', 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 () {
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 () {
assert.equal(Datepicker.getDaysCount(new Date(2015, 1)), 28)
assert.equal(plugin.getDaysCount(new Date(2015, 1)), 28)
})
});
describe('getParsedDate', function () {
var currentDate = new Date(),
date = Datepicker.getParsedDate(currentDate);
date = plugin.getParsedDate(currentDate);
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']);
@ -76,7 +78,7 @@ describe('Datepicker', function () {
describe('getDecade', 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');
assert.equal(decade[0], 2010)
@ -87,7 +89,7 @@ describe('Datepicker', function () {
describe('template', function () {
it('should return string with replaced #{} signs', function () {
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);
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 () {
assert.isFalse(Datepicker.isSame(date1,date3))
assert.isFalse(plugin.isSame(date1,date3))
})
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 () {
assert(Datepicker.isSame(date1, date2,'month'))
assert(plugin.isSame(date1, date2,'month'))
})
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 () {
assert(Datepicker.isSame(date1, date2, 'year'))
assert(plugin.isSame(date1, date2, 'year'))
})
})
describe('less(date1, date2)', 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 () {
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)))
})
})
});