Skip to content

Commit 2eb80dd

Browse files
author
Elvis Justino da Silva
committed
Adding language support to Brazilian Portuguese (br) and Espanhish(es) and methods selectDates and unselectDates
1 parent 7ae60cc commit 2eb80dd

File tree

8 files changed

+2206
-1330
lines changed

8 files changed

+2206
-1330
lines changed

dist/datepickk.js

Lines changed: 91 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,24 @@ function Datepickk(args) {
112112
weekStart: 1
113113
},
114114
en: {
115-
monthNames: ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'],
116-
dayNames: ['su', 'mo', 'tu', 'we', 'th', 'fr', 'sa'],
115+
monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
116+
dayNames: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
117117
weekStart: 0
118118
},
119119
de: {
120120
monthNames: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
121121
dayNames: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
122122
weekStart: 1
123+
},
124+
br: {
125+
monthNames: ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'],
126+
dayNames: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb'],
127+
weekStart: 0
128+
},
129+
es: {
130+
monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
131+
dayNames: ['Dom', 'Lun', 'Mar', 'Mié', 'Jue', 'Vie', 'Sáb'],
132+
weekStart: 0
123133
}
124134
};
125135

@@ -320,6 +330,13 @@ function Datepickk(args) {
320330
}
321331
var monthText = languages[lang].monthNames[parseMonth(month - 1 + index)];
322332
element.setAttribute('data-month', monthText);
333+
element.setAttribute('data-month-year', new Date(year, month - 1 + index, 1).getFullYear());
334+
element.setAttribute('data-month-num', parseMonth(month - 1 + index));
335+
element.setAttribute('data-month-last-day', days);
336+
element.setAttribute('data-month-first-day', 1);
337+
if (minDate instanceof Date) {
338+
element.setAttribute('data-month-first-day', minDate.getTime() >= new Date(year, month - 1 + index, 1).getTime() && minDate.getTime() <= new Date(year, month - 1 + index, days).getTime() ? minDate.getDate() + 1 : 1);
339+
}
323340

324341
[].slice.call(element.querySelectorAll('.d-table input')).forEach(function (inputEl, i) {
325342
var labelEl = inputEl.nextSibling;
@@ -540,45 +557,61 @@ function Datepickk(args) {
540557
};
541558

542559
function selectDate(date, ignoreOnSelect) {
543-
date = new Date(date);
544-
date.setHours(0, 0, 0, 0);
545-
var el = that.el.querySelector('[data-date="' + date.toJSON() + '"]');
560+
if (date != '') {
561+
date = new Date(date);
562+
date.setHours(0, 0, 0, 0);
563+
var el = that.el.querySelector('[data-date="' + date.toJSON() + '"]');
546564

547-
if (range && el && el.checked) {
548-
el.classList.add('single');
549-
}
565+
if (range && el && el.checked) {
566+
el.classList.add('single');
567+
}
550568

551-
if (el && !el.checked) {
552-
el.checked = true;
553-
}
569+
if (el && !el.checked) {
570+
el.checked = true;
571+
}
554572

555-
selectedDates.push(date);
573+
selectedDates.push(date);
556574

557-
if (onSelect && !ignoreOnSelect) {
558-
onSelect.apply(date, [true]);
575+
if (onSelect && !ignoreOnSelect) {
576+
onSelect.apply(date, [true]);
577+
}
559578
}
560579
};
561580

581+
function selectDates(dates, ignoreOnSelect) {
582+
dates.forEach(function (element) {
583+
selectDate(element, ignoreOnSelect);
584+
});
585+
};
586+
562587
function unselectDate(date, ignoreOnSelect) {
563-
date = new Date(date);
564-
date.setHours(0, 0, 0, 0);
565-
var el = that.el.querySelector('[data-date="' + date.toJSON() + '"]');
566-
if (el) {
567-
el.classList.remove('single');
568-
if (el.checked) {
569-
el.checked = false;
588+
if (date != '') {
589+
date = new Date(date);
590+
date.setHours(0, 0, 0, 0);
591+
var el = that.el.querySelector('[data-date="' + date.toJSON() + '"]');
592+
if (el) {
593+
el.classList.remove('single');
594+
if (el.checked) {
595+
el.checked = false;
596+
}
570597
}
571-
}
572598

573-
selectedDates = selectedDates.filter(function (x) {
574-
return x.getTime() != date.getTime();
575-
});
599+
selectedDates = selectedDates.filter(function (x) {
600+
return x.getTime() != date.getTime();
601+
});
576602

577-
if (onSelect && !ignoreOnSelect) {
578-
onSelect.call(date, false);
603+
if (onSelect && !ignoreOnSelect) {
604+
onSelect.call(date, false);
605+
}
579606
}
580607
};
581608

609+
function unselectDates(dates, ignoreOnSelect) {
610+
dates.forEach(function (element) {
611+
unselectDate(element, ignoreOnSelect);
612+
});
613+
};
614+
582615
function unselectAll(ignoreOnSelect) {
583616
selectedDates.forEach(function (date) {
584617
unselectDate(date, ignoreOnSelect);
@@ -780,12 +813,15 @@ function Datepickk(args) {
780813
that.show = show;
781814
that.hide = hide;
782815
that.selectDate = selectDate;
816+
that.selectDates = selectDates;
783817
that.unselectAll = unselectAll;
784818
that.unselectDate = unselectDate;
819+
that.unselectDates = unselectDates;
785820

786821
function currentDateGetter() {
787822
return new Date(currentYear, currentMonth - 1, 1);
788823
}
824+
789825
function currentDateSetter(x) {
790826
x = new Date(x);
791827
currentMonth = x.getMonth() + 1;
@@ -852,6 +888,33 @@ function Datepickk(args) {
852888
}
853889
}
854890
},
891+
"languages": {
892+
get: function get() {
893+
return languages[lang];
894+
}
895+
},
896+
"firstDateCalendar": {
897+
get: function get() {
898+
var monthNodes = document.querySelectorAll('.d-table');
899+
var firstMonth = monthNodes[0];
900+
var year = firstMonth.getAttribute('data-month-year');
901+
var month = firstMonth.getAttribute('data-month-num');
902+
var day = firstMonth.getAttribute('data-month-first-day');
903+
904+
return new Date(year, month, day);
905+
}
906+
},
907+
"lastDateCalendar": {
908+
get: function get() {
909+
var monthNodes = document.querySelectorAll('.d-table');
910+
var lastMonth = monthNodes[monthNodes.length - 1];
911+
var year = lastMonth.getAttribute('data-month-year');
912+
var month = lastMonth.getAttribute('data-month-num');
913+
var day = lastMonth.getAttribute('data-month-last-day');
914+
915+
return new Date(year, month, day);
916+
}
917+
},
855918
"weekStart": {
856919
get: function get() {
857920
return weekStart !== null ? weekStart : languages[lang].weekStart;
@@ -883,7 +946,7 @@ function Datepickk(args) {
883946
that.el.classList.add('multi');
884947
}
885948
} else {
886-
console.error('months must be a number > 0');
949+
console.error('Months must be a number > 0');
887950
}
888951
}
889952
},

dist/datepickk.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/doc.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*Flex grid*/
1+
@import url(http://fonts.googleapis.com/css?family=Raleway:400,100,200,300);@import url(https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css);/*Flex grid*/
22
.container {
33
padding: 7.5px;
44
}
@@ -1015,7 +1015,6 @@ ul li:before {
10151015
}
10161016
.nav h1 {
10171017
color: #222;
1018-
width: auto;
10191018
display: inline;
10201019
}
10211020
.nav h1 span {

docs/doc.less

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
@import "_button.less";
44
@import "_variables.less";
55

6+
@import url(http://fonts.googleapis.com/css?family=Raleway:400,100,200,300);
7+
@import url(https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css);
8+
69
@main: #D55C2B;
710

811
*{
@@ -56,7 +59,6 @@ ul{
5659

5760
h1{
5861
color:#222;
59-
width:auto;
6062
display: inline;
6163

6264
span{
@@ -166,4 +168,4 @@ code{
166168

167169
a{
168170
color:@blue;
169-
}
171+
}

0 commit comments

Comments
 (0)