Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 136 additions & 37 deletions dist/datepickk.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,57 @@ function Datepickk(args) {
weekStart: 1
},
en: {
monthNames: ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'],
dayNames: ['su', 'mo', 'tu', 'we', 'th', 'fr', 'sa'],
monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
dayNames: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
dayNamesFull: ['Sundays', 'Mondays', 'Tuesdays', 'Wednesdays', 'Thursdays', 'Fridays', 'Saturdays'],
labels: {
clone: 'Clone multiple selection actions for all years',
clean: 'Clean Calendar',
selectWeekday: function selectWeekday(dayWeek) {
return 'Select all ' + languages['en'].dayNamesFull[dayWeek];
},
selectMonth: function selectMonth(month) {
return 'Select all days of the month of ' + languages['en'].monthNames[month];
}
},
weekStart: 0
},
de: {
monthNames: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
dayNames: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
weekStart: 1
},
br: {
monthNames: ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'],
dayNames: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb'],
dayNamesFull: ['Domingos', 'Segundas', 'Terças', 'Quartas', 'Quintas', 'Sextas', 'Sábados'],
labels: {
clone: 'Clonar ações de seleção multipla para todos anos',
clean: 'Limpar Calendário',
selectWeekday: function selectWeekday(dayWeek) {
return 'Seleciona todos os(as) ' + languages['br'].dayNamesFull[dayWeek];
},
selectMonth: function selectMonth(month) {
return 'Seleciona todos os dias do mês de ' + languages['br'].monthNames[month];
}
},
weekStart: 0
},
es: {
monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
dayNames: ['Dom', 'Lun', 'Mar', 'Mié', 'Jue', 'Vie', 'Sáb'],
dayNamesFull: ['Domingos', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábados'],
labels: {
clone: 'Clonar acciones de selección múltiple para todos los años',
clean: 'Limpiar Calendario',
selectWeekday: function selectWeekday(dayWeek) {
return 'Seleccionar todos los(as) ' + languages['es'].dayNamesFull[dayWeek];
},
selectMonth: function selectMonth(month) {
return 'Selecciona todos los días del mes de ' + languages['es'].monthNames[month];
}
},
weekStart: 0
}
};

Expand Down Expand Up @@ -303,6 +346,11 @@ function Datepickk(args) {
return month;
}

function isDisabledDate(date) {
var dateToVerify = date instanceof Date ? date : new Date(date);
return disabledDates.indexOf(dateToVerify.getTime()) != -1 || disabledDays.indexOf(dateToVerify.getDay()) != -1;
}

function generateDates(year, month) {
var monthElements = that.el.querySelectorAll('.d-table');
var ws = weekStart !== null ? weekStart : languages[lang].weekStart;
Expand All @@ -320,6 +368,13 @@ function Datepickk(args) {
}
var monthText = languages[lang].monthNames[parseMonth(month - 1 + index)];
element.setAttribute('data-month', monthText);
element.setAttribute('data-month-year', new Date(year, month - 1 + index, 1).getFullYear());
element.setAttribute('data-month-num', parseMonth(month - 1 + index));
element.setAttribute('data-month-last-day', days);
element.setAttribute('data-month-first-day', 1);
if (minDate instanceof Date) {
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);
}

[].slice.call(element.querySelectorAll('.d-table input')).forEach(function (inputEl, i) {
var labelEl = inputEl.nextSibling;
Expand Down Expand Up @@ -360,7 +415,7 @@ function Datepickk(args) {
if (date instanceof Date) {
inputEl.setAttribute('data-date', date.toJSON());

if (disabledDates.indexOf(date.getTime()) != -1 || disabledDays.indexOf(date.getDay()) != -1) {
if (isDisabledDate(date)) {
inputEl.setAttribute('disabled', true);
}

Expand Down Expand Up @@ -441,14 +496,12 @@ function Datepickk(args) {
}
}

if (maxDate && new Date(currentYear, currentMonth - 1 + months - 1, 1) >= new Date(maxDate).setDate(1)) {
currentYear = maxDate.getFullYear();
currentMonth = maxDate.getMonth() + 1 - months + 1;
if (maxDate && new Date(currentYear, currentMonth - 1 + months - 1, 1).getTime() >= new Date(new Date(maxDate).setDate(1)).getTime()) {
that.el.header.childNodes[2].setAttribute('style', 'visibility:hidden');
} else {
that.el.header.childNodes[2].removeAttribute('style');
}
if (minDate && new Date(currentYear, currentMonth - 1, 1) <= new Date(minDate).setDate(1)) {
if (minDate && new Date(currentYear, currentMonth - 1, 1).getTime() <= new Date(new Date(minDate).setDate(1)).getTime()) {
currentYear = minDate.getFullYear();
currentMonth = minDate.getMonth() + 1;
that.el.header.childNodes[0].setAttribute('style', 'visibility:hidden');
Expand Down Expand Up @@ -539,49 +592,65 @@ function Datepickk(args) {
setDate();
};

function selectDate(date, ignoreOnSelect) {
date = new Date(date);
date.setHours(0, 0, 0, 0);
var el = that.el.querySelector('[data-date="' + date.toJSON() + '"]');
function selectDate(date, ignoreOnSelect, ignoreDisabled) {
if (date != '' && (ignoreDisabled || !isDisabledDate(date))) {
date = new Date(date);
date.setHours(0, 0, 0, 0);
var el = that.el.querySelector('[data-date="' + date.toJSON() + '"]');

if (range && el && el.checked) {
el.classList.add('single');
}
if (range && el && el.checked) {
el.classList.add('single');
}

if (el && !el.checked) {
el.checked = true;
}
if (el && !el.checked) {
el.checked = true;
}

selectedDates.push(date);
selectedDates.push(date);

if (onSelect && !ignoreOnSelect) {
onSelect.apply(date, [true]);
if (onSelect && !ignoreOnSelect) {
onSelect.apply(date, [true]);
}
}
};

function unselectDate(date, ignoreOnSelect) {
date = new Date(date);
date.setHours(0, 0, 0, 0);
var el = that.el.querySelector('[data-date="' + date.toJSON() + '"]');
if (el) {
el.classList.remove('single');
if (el.checked) {
el.checked = false;
function selectDates(dates, ignoreOnSelect, ignoreDisabled) {
dates.forEach(function (element) {
selectDate(element, ignoreOnSelect, ignoreDisabled);
});
};

function unselectDate(date, ignoreOnSelect, ignoreDisabled) {
if (date != '' && (ignoreDisabled || !isDisabledDate(date))) {
date = new Date(date);
date.setHours(0, 0, 0, 0);
var el = that.el.querySelector('[data-date="' + date.toJSON() + '"]');
if (el) {
el.classList.remove('single');
if (el.checked) {
el.checked = false;
}
}
}

selectedDates = selectedDates.filter(function (x) {
return x.getTime() != date.getTime();
});
selectedDates = selectedDates.filter(function (x) {
return x.getTime() != date.getTime();
});

if (onSelect && !ignoreOnSelect) {
onSelect.call(date, false);
if (onSelect && !ignoreOnSelect) {
onSelect.call(date, false);
}
}
};

function unselectAll(ignoreOnSelect) {
function unselectDates(dates, ignoreOnSelect, ignoreDisabled) {
dates.forEach(function (element) {
unselectDate(element, ignoreOnSelect, ignoreDisabled);
});
};

function unselectAll(ignoreOnSelect, ignoreDisabled) {
selectedDates.forEach(function (date) {
unselectDate(date, ignoreOnSelect);
unselectDate(date, ignoreOnSelect, ignoreDisabled);
});
};

Expand Down Expand Up @@ -780,12 +849,15 @@ function Datepickk(args) {
that.show = show;
that.hide = hide;
that.selectDate = selectDate;
that.selectDates = selectDates;
that.unselectAll = unselectAll;
that.unselectDate = unselectDate;
that.unselectDates = unselectDates;

function currentDateGetter() {
return new Date(currentYear, currentMonth - 1, 1);
}

function currentDateSetter(x) {
x = new Date(x);
currentMonth = x.getMonth() + 1;
Expand Down Expand Up @@ -852,6 +924,33 @@ function Datepickk(args) {
}
}
},
"languages": {
get: function get() {
return languages[lang];
}
},
"firstDateCalendar": {
get: function get() {
var monthNodes = document.querySelectorAll('.d-table');
var firstMonth = monthNodes[0];
var year = firstMonth.getAttribute('data-month-year');
var month = firstMonth.getAttribute('data-month-num');
var day = firstMonth.getAttribute('data-month-first-day');

return new Date(year, month, day);
}
},
"lastDateCalendar": {
get: function get() {
var monthNodes = document.querySelectorAll('.d-table');
var lastMonth = monthNodes[monthNodes.length - 1];
var year = lastMonth.getAttribute('data-month-year');
var month = lastMonth.getAttribute('data-month-num');
var day = lastMonth.getAttribute('data-month-last-day');

return new Date(year, month, day);
}
},
"weekStart": {
get: function get() {
return weekStart !== null ? weekStart : languages[lang].weekStart;
Expand Down Expand Up @@ -883,7 +982,7 @@ function Datepickk(args) {
that.el.classList.add('multi');
}
} else {
console.error('months must be a number > 0');
console.error('Months must be a number > 0');
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion dist/datepickk.min.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions dist/doc.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*Flex grid*/
@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*/
.container {
padding: 7.5px;
}
Expand Down Expand Up @@ -1015,7 +1015,6 @@ ul li:before {
}
.nav h1 {
color: #222;
width: auto;
display: inline;
}
.nav h1 span {
Expand Down
6 changes: 4 additions & 2 deletions docs/doc.less
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
@import "_button.less";
@import "_variables.less";

@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);

@main: #D55C2B;

*{
Expand Down Expand Up @@ -56,7 +59,6 @@ ul{

h1{
color:#222;
width:auto;
display: inline;

span{
Expand Down Expand Up @@ -166,4 +168,4 @@ code{

a{
color:@blue;
}
}
Loading