Witam,
mam taki app.js znaleziony gdzieś w necie:
var app = app || {};
app.calendar = {
date: {
names: {
months: ['Styczeń','Luty','Marzec','Kwiecień','Maj','Czerwiec','Lipiec','Sierpień','Wrzesień','Październik','Listopad','Grudzień'],
monthsShortEng: ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],
days: ['Niedziela','Poniedziałek','Wtorek','Środa','Czwartek','Piątek','Sobota'],
daysShort: ['Pon.','Wt.','Śr.','Czw.','Piąt.','Sob.','Niedz.']
},
actual: {
dayOfWeek: new Date().getDay(),
day: new Date().getDate(),
month: new Date().getMonth(),
year: new Date().getFullYear(),
hour: parseInt((new Date().getHours()<10?'0':'') + new Date().getHours()),
minutes: parseInt((new Date().getMinutes()<10?'0':'') + new Date().getMinutes())
},
get: {
firstDayOfMonth: function(month,year){
return new Date(year,month,0).getDay();
},
monthsBetwenDates: function(month1,year1,month2,year2){
var date1 = new Date(year1,month1,1),
date2 = new Date(year2,month2,1),
year1 = date1.getFullYear(),
year2 = date2.getFullYear(),
month1 = date1.getMonth(),
month2 = date2.getMonth();
if(month1 === 0){
month1++;
month2++;
}
return (year2 - year1) * 12 + (month2 - month1);
},
dayInMonth: function(month,year){
return new Date(year,month+1,0).getDate();
},
dayInLastMonth: function(month,year){
return new Date(year,month,0).getDate();
},
dayInNextMonth: function(month,year){
return new Date(year,month+2,0).getDate();
}
}
},
currentMonthDays: function(month,year,dayInMonth,numberOfLastMonthDay){
var numberOfDays = 42;
// 0 - disable, 1 - this month disable, 2 - enable, 3 - current day
var typeOfDaysToRender = [];
var actualDateTime = parseInt((new Date().getTime() / 1000).toFixed(0));
for(var i0=1;i0<=numberOfLastMonthDay;++i0){ typeOfDaysToRender.push(0); numberOfDays--; }
for(var i1=1;i1<=dayInMonth;++i1){
var dateTime = parseInt((new Date(i1+'-'+this.date.names.monthsShortEng[month]+'-'+year).getTime() / 1000).toFixed(0));
if(dateTime < actualDateTime && parseInt(dateTime + 86400) > actualDateTime){
typeOfDaysToRender.push(3);
}else if(dateTime < actualDateTime){
typeOfDaysToRender.push(1);
}else{
typeOfDaysToRender.push(2);
}
numberOfDays--;
}
for(var i2=1;i2<=numberOfDays;++i2){ typeOfDaysToRender.push(0); }
return typeOfDaysToRender;
},
renderCalendarClock: function(){
var getHours = new Date().getHours(),
getMinutes = new Date().getMinutes();
if(getHours < 10){
getHours = '0'+getHours;
}
if(getMinutes < 10){
getMinutes = '0'+getMinutes;
}
$('#calendar-control').find('.time-hours').html(getHours);
$('#calendar-control').find('.time-minutes').html(getMinutes);
setTimeout(function(){
app.calendar.renderCalendarClock();
},1000);
},
renderCalendarNavi: function(month,year){
var newMonthPrev, newMonthNext, newYearPrev, newYearNext, monthModifier;
var actualMonth = this.date.actual.month,
actualYear = this.date.actual.year;
if(month == 0 || month == 11){
if(month == 0){
newMonthPrev = parseInt(11);
newMonthNext = parseInt(month + 1);
newYearPrev = parseInt(year - 1);
newYearNext = parseInt(year);
monthModifier = parseInt(0);
}else{
newMonthPrev = parseInt(month - 1);
newMonthNext = parseInt(0);
newYearPrev = parseInt(year);
newYearNext = parseInt(year - -1);
monthModifier = parseInt(0);
}
}else{
newMonthPrev = parseInt(month);
newMonthNext = parseInt(month);
newYearPrev = parseInt(year);
newYearNext = parseInt(year);
monthModifier = parseInt(1);
}
$('#calendar-last-month,#calendar-next-month').removeClass('disable');
if(this.date.get.monthsBetwenDates(actualMonth,actualYear,month,year) > 11){
$('#calendar-next-month').attr('data-calendar-navi','false').addClass('disable');
}else{
$('#calendar-next-month').attr('data-calendar-navi',parseInt(newMonthNext+monthModifier)+'/'+parseInt(newYearNext));
}
if(this.date.get.monthsBetwenDates(actualMonth,actualYear,month,year) < -2){
$('#calendar-last-month').attr('data-calendar-navi','false').addClass('disable');
}else{
$('#calendar-last-month').attr('data-calendar-navi',parseInt(newMonthPrev-monthModifier)+'/'+parseInt(newYearPrev));
}
$('#calendar-control').find('.month').html(this.date.names.months[month]);
$('#calendar-control').find('.year').html(year);
},
renderCalendar: function(month,year){
var dayInMonth = this.date.get.dayInMonth(month,year),
dayInLastMonth = this.date.get.dayInLastMonth(month,year),
dayInNextMonth = this.date.get.dayInNextMonth(month,year),
numberOfLastMonthDay = this.date.get.firstDayOfMonth(month,year);
if(numberOfLastMonthDay == 0){
numberOfLastMonthDay = 7;
}
var typeOfDaysToRender = this.currentMonthDays(month,year,dayInMonth,numberOfLastMonthDay),
lastMonthStartDay = parseInt(dayInLastMonth - numberOfLastMonthDay);
var actualDay, day = 0, dayNameOfWeek = 0, lastMonth = true;
this.renderCalendarNavi(month,year);
$('#calendar').empty();
$.ajax({
type: 'POST',
url: '/wp-admin/admin.php?page=multi_booking_calendar',
data: {
action: 'getCalendar',
month: month,
},
success: function(response){
window.dayInCalendar = JSON.parse(response.split('<!--CUT-->')[1]);
$.each(typeOfDaysToRender,function(i){
var specialClass, dayCopyElement, thisMonth, dataAttrDate, thisDayOccupied = false;
val = typeOfDaysToRender[i];
if(val == 0){
lastMonthStartDay++;
actualDay = lastMonthStartDay;
specialClass = 'disable';
}else{
day++;
actualDay = day;
if(val == 1){
specialClass = 'block';
}
if(val == 3){
specialClass = 'today active';
}
if($.inArray(parseInt(actualDay),window.dayInCalendar) > -1){
thisDayOccupied = true;
specialClass += ' busy';
}
dataAttrDate = (actualDay<10?'0'+actualDay:actualDay)+'/'+(parseInt(month+1)<10?'0'+parseInt(month+1):parseInt(month+1))+'/'+year;
}
dayCopyElement = $('#calendar-elems').children('.day').clone();
dayCopyElement.addClass(specialClass);
dayCopyElement.attr('data-attr-date',dataAttrDate);
dayCopyElement.find('.day').html(actualDay);
dayCopyElement.find('.day-name').html(app.calendar.date.names.daysShort[dayNameOfWeek]);
if(thisDayOccupied){
dayCopyElement.find('select').val(1);
}
thisDayOccupied
$('#calendar').append(dayCopyElement);
if(lastMonthStartDay == dayInLastMonth){
lastMonthStartDay = 0;
}
dayNameOfWeek++;
if(dayNameOfWeek == 7){
dayNameOfWeek = 0;
lastMonth = false;
}
});
}
});
}
};
Ten skrypt generuje kalendarz na
rok od bieżącej daty a chciałbym mieć na dwa lata... Jest to na pewno jakaś mała zmiana ale nie jestem w stanie go do końca zrozumieć i tego znaleść... myślałem, że to tutaj:
if(this.date.get.monthsBetwenDates(actualMonth,actualYear,month,year) > 25){
$('#calendar-next-month').attr('data-calendar-navi','false').addClass('disable');
}else{
$('#calendar-next-month').attr('data-calendar-navi',parseInt(newMonthNext+monthModifier)+'/'+parseInt(newYearNext));
}
ale jednak nie...
z góry wielkie dzięki bo już za długo nad tym siedzę..
ktos, coś ? mogę nawet zlecić to komuś
Ten post edytował matkuz 9.06.2015, 13:18:03