mirror of
https://github.com/frappe/air-datepicker.git
synced 2026-01-14 11:01:22 +08:00
add i18n.js and day names rendering
This commit is contained in:
parent
118b7d4c5a
commit
88a97bbb95
56
dist/js/datepicker.js
vendored
56
dist/js/datepicker.js
vendored
@ -10,6 +10,8 @@ var Datepicker;
|
|||||||
'</div>',
|
'</div>',
|
||||||
defaults = {
|
defaults = {
|
||||||
inline: true,
|
inline: true,
|
||||||
|
region: 'ru',
|
||||||
|
firstDay: 1,
|
||||||
start: '',
|
start: '',
|
||||||
format: 'dd.mm.yyyy'
|
format: 'dd.mm.yyyy'
|
||||||
};
|
};
|
||||||
@ -26,6 +28,8 @@ var Datepicker;
|
|||||||
this._buildDatepickersContainer();
|
this._buildDatepickersContainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.loc = Datepicker.region[this.opts.region];
|
||||||
|
|
||||||
if ($body == undefined) {
|
if ($body == undefined) {
|
||||||
$body = $('body');
|
$body = $('body');
|
||||||
}
|
}
|
||||||
@ -33,6 +37,18 @@ var Datepicker;
|
|||||||
this.init()
|
this.init()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Datepicker.getDaysCount = function (date) {
|
||||||
|
return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
|
||||||
|
};
|
||||||
|
|
||||||
|
Datepicker.getParsedDate = function (date) {
|
||||||
|
return {
|
||||||
|
year: date.getUTCFullYear(),
|
||||||
|
month: date.getUTCMonth(),
|
||||||
|
day: date.getUTCDay()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Datepicker.prototype = {
|
Datepicker.prototype = {
|
||||||
containerBuilt: false,
|
containerBuilt: false,
|
||||||
init: function () {
|
init: function () {
|
||||||
@ -83,6 +99,14 @@ var Datepicker;
|
|||||||
};
|
};
|
||||||
|
|
||||||
})(window, jQuery, '');
|
})(window, jQuery, '');
|
||||||
|
;(function () {
|
||||||
|
Datepicker.region = {
|
||||||
|
'ru': {
|
||||||
|
days: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
Datepicker.Cell = function () {
|
Datepicker.Cell = function () {
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -110,26 +134,34 @@ Datepicker.Cell = function () {
|
|||||||
this._render();
|
this._render();
|
||||||
},
|
},
|
||||||
|
|
||||||
_getCellsNumber: function () {
|
|
||||||
var d = this.viewDate;
|
|
||||||
|
|
||||||
return {
|
|
||||||
days: new Date(d.getFullYear(), d.getMonth()+1, 0).getDate(),
|
|
||||||
months: 12,
|
|
||||||
years: 10
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
_buildBaseHtml: function () {
|
_buildBaseHtml: function () {
|
||||||
this.$el = $(templates[this.type]).appendTo(this.d.$content);
|
this.$el = $(templates[this.type]).appendTo(this.d.$content);
|
||||||
this.$names = $('.datepicker--days--names', this.$el);
|
this.$names = $('.datepicker--days--names', this.$el);
|
||||||
this.$cells = $('.datepicker--days--cells', this.$el);
|
this.$cells = $('.datepicker--days--cells', this.$el);
|
||||||
},
|
},
|
||||||
|
|
||||||
_render: function () {
|
_getDayNamesHtml: function (firstDay, curDay, html, circle) {
|
||||||
var cells = this._getCellsNumber();
|
curDay = curDay != undefined ? curDay : firstDay;
|
||||||
|
html = html ? html : '';
|
||||||
|
if (curDay == firstDay && circle) return html;
|
||||||
|
if (curDay == 7) return this._getDayNamesHtml(firstDay, 0, html, true);
|
||||||
|
|
||||||
|
html += '<div class="datepicker--days--name">' + this.d.loc.days[curDay] + '</div>';
|
||||||
|
|
||||||
|
return this._getDayNamesHtml(firstDay, ++curDay, html, circle);
|
||||||
|
},
|
||||||
|
|
||||||
|
_renderDays: function () {
|
||||||
|
var count = Datepicker.getDaysCount(this.viewDate),
|
||||||
|
dayNames = this._getDayNamesHtml(this.opts.firstDay),
|
||||||
|
firstDayIndex = new Date(this.viewDate.getFullYear(), this.viewDate.getMonth(), 1).getDay();
|
||||||
|
|
||||||
|
this.$names.html(dayNames)
|
||||||
|
},
|
||||||
|
|
||||||
|
_render: function () {
|
||||||
this._buildBaseHtml();
|
this._buildBaseHtml();
|
||||||
|
this._renderDays();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|||||||
@ -6,7 +6,7 @@ var gulp = require('gulp'),
|
|||||||
concat = require('gulp-concat');
|
concat = require('gulp-concat');
|
||||||
|
|
||||||
gulp.task('js', function () {
|
gulp.task('js', function () {
|
||||||
gulp.src(['js/datepicker/datepicker.js', 'js/datepicker/cell.js', 'js/datepicker/body.js'])
|
gulp.src(['js/datepicker/datepicker.js', 'js/datepicker/i18n.js', 'js/datepicker/cell.js', 'js/datepicker/body.js'])
|
||||||
.pipe(concat('datepicker.js'))
|
.pipe(concat('datepicker.js'))
|
||||||
.pipe(gulp.dest('dist/js/'))
|
.pipe(gulp.dest('dist/js/'))
|
||||||
.pipe(livereload())
|
.pipe(livereload())
|
||||||
|
|||||||
@ -22,26 +22,34 @@
|
|||||||
this._render();
|
this._render();
|
||||||
},
|
},
|
||||||
|
|
||||||
_getCellsNumber: function () {
|
|
||||||
var d = this.viewDate;
|
|
||||||
|
|
||||||
return {
|
|
||||||
days: new Date(d.getFullYear(), d.getMonth()+1, 0).getDate(),
|
|
||||||
months: 12,
|
|
||||||
years: 10
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
_buildBaseHtml: function () {
|
_buildBaseHtml: function () {
|
||||||
this.$el = $(templates[this.type]).appendTo(this.d.$content);
|
this.$el = $(templates[this.type]).appendTo(this.d.$content);
|
||||||
this.$names = $('.datepicker--days--names', this.$el);
|
this.$names = $('.datepicker--days--names', this.$el);
|
||||||
this.$cells = $('.datepicker--days--cells', this.$el);
|
this.$cells = $('.datepicker--days--cells', this.$el);
|
||||||
},
|
},
|
||||||
|
|
||||||
_render: function () {
|
_getDayNamesHtml: function (firstDay, curDay, html, circle) {
|
||||||
var cells = this._getCellsNumber();
|
curDay = curDay != undefined ? curDay : firstDay;
|
||||||
|
html = html ? html : '';
|
||||||
|
if (curDay == firstDay && circle) return html;
|
||||||
|
if (curDay == 7) return this._getDayNamesHtml(firstDay, 0, html, true);
|
||||||
|
|
||||||
|
html += '<div class="datepicker--days--name">' + this.d.loc.days[curDay] + '</div>';
|
||||||
|
|
||||||
|
return this._getDayNamesHtml(firstDay, ++curDay, html, circle);
|
||||||
|
},
|
||||||
|
|
||||||
|
_renderDays: function () {
|
||||||
|
var count = Datepicker.getDaysCount(this.viewDate),
|
||||||
|
dayNames = this._getDayNamesHtml(this.opts.firstDay),
|
||||||
|
firstDayIndex = new Date(this.viewDate.getFullYear(), this.viewDate.getMonth(), 1).getDay();
|
||||||
|
|
||||||
|
this.$names.html(dayNames)
|
||||||
|
},
|
||||||
|
|
||||||
|
_render: function () {
|
||||||
this._buildBaseHtml();
|
this._buildBaseHtml();
|
||||||
|
this._renderDays();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|||||||
@ -10,6 +10,8 @@ var Datepicker;
|
|||||||
'</div>',
|
'</div>',
|
||||||
defaults = {
|
defaults = {
|
||||||
inline: true,
|
inline: true,
|
||||||
|
region: 'ru',
|
||||||
|
firstDay: 1,
|
||||||
start: '',
|
start: '',
|
||||||
format: 'dd.mm.yyyy'
|
format: 'dd.mm.yyyy'
|
||||||
};
|
};
|
||||||
@ -26,6 +28,8 @@ var Datepicker;
|
|||||||
this._buildDatepickersContainer();
|
this._buildDatepickersContainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.loc = Datepicker.region[this.opts.region];
|
||||||
|
|
||||||
if ($body == undefined) {
|
if ($body == undefined) {
|
||||||
$body = $('body');
|
$body = $('body');
|
||||||
}
|
}
|
||||||
@ -33,6 +37,18 @@ var Datepicker;
|
|||||||
this.init()
|
this.init()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Datepicker.getDaysCount = function (date) {
|
||||||
|
return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
|
||||||
|
};
|
||||||
|
|
||||||
|
Datepicker.getParsedDate = function (date) {
|
||||||
|
return {
|
||||||
|
year: date.getUTCFullYear(),
|
||||||
|
month: date.getUTCMonth(),
|
||||||
|
day: date.getUTCDay()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Datepicker.prototype = {
|
Datepicker.prototype = {
|
||||||
containerBuilt: false,
|
containerBuilt: false,
|
||||||
init: function () {
|
init: function () {
|
||||||
|
|||||||
7
js/datepicker/i18n.js
Normal file
7
js/datepicker/i18n.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
;(function () {
|
||||||
|
Datepicker.region = {
|
||||||
|
'ru': {
|
||||||
|
days: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
Loading…
x
Reference in New Issue
Block a user