Skip to content

Commit

Permalink
add i18n.js and day names rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
t1m0n committed Oct 2, 2015
1 parent 118b7d4 commit 88a97bb
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 25 deletions.
56 changes: 44 additions & 12 deletions dist/js/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var Datepicker;
'</div>',
defaults = {
inline: true,
region: 'ru',
firstDay: 1,
start: '',
format: 'dd.mm.yyyy'
};
Expand All @@ -26,13 +28,27 @@ var Datepicker;
this._buildDatepickersContainer();
}

this.loc = Datepicker.region[this.opts.region];

if ($body == undefined) {
$body = $('body');
}

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 = {
containerBuilt: false,
init: function () {
Expand Down Expand Up @@ -83,6 +99,14 @@ var Datepicker;
};

})(window, jQuery, '');
;(function () {
Datepicker.region = {
'ru': {
days: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб']
}
}
})();

Datepicker.Cell = function () {

};
Expand Down Expand Up @@ -110,26 +134,34 @@ Datepicker.Cell = function () {
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 () {
this.$el = $(templates[this.type]).appendTo(this.d.$content);
this.$names = $('.datepicker--days--names', this.$el);
this.$cells = $('.datepicker--days--cells', this.$el);
},

_render: function () {
var cells = this._getCellsNumber();
_getDayNamesHtml: function (firstDay, curDay, html, circle) {
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._renderDays();
}
};
})();
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var gulp = require('gulp'),
concat = require('gulp-concat');

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(gulp.dest('dist/js/'))
.pipe(livereload())
Expand Down
32 changes: 20 additions & 12 deletions js/datepicker/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,34 @@
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 () {
this.$el = $(templates[this.type]).appendTo(this.d.$content);
this.$names = $('.datepicker--days--names', this.$el);
this.$cells = $('.datepicker--days--cells', this.$el);
},

_render: function () {
var cells = this._getCellsNumber();
_getDayNamesHtml: function (firstDay, curDay, html, circle) {
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._renderDays();
}
};
})();
16 changes: 16 additions & 0 deletions js/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var Datepicker;
'</div>',
defaults = {
inline: true,
region: 'ru',
firstDay: 1,
start: '',
format: 'dd.mm.yyyy'
};
Expand All @@ -26,13 +28,27 @@ var Datepicker;
this._buildDatepickersContainer();
}

this.loc = Datepicker.region[this.opts.region];

if ($body == undefined) {
$body = $('body');
}

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 = {
containerBuilt: false,
init: function () {
Expand Down
7 changes: 7 additions & 0 deletions js/datepicker/i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
;(function () {
Datepicker.region = {
'ru': {
days: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб']
}
}
})();

0 comments on commit 88a97bb

Please sign in to comment.