diff options
author | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2008-07-28 03:32:54 +0400 |
---|---|---|
committer | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2008-07-28 03:32:54 +0400 |
commit | 4b544aa9c09777426715b606319e54646bab5eda (patch) | |
tree | ab59bac1803b272272ca9d16ae69b65fd44a25ba /plugins/CoreHome/templates/calendar.js | |
parent | e20c0f86431de3c35c3e5cf7f66d8d98c71aced7 (diff) |
- end of previous commit. For some reasons Tortoise didn't see these files, bad!
Diffstat (limited to 'plugins/CoreHome/templates/calendar.js')
-rw-r--r-- | plugins/CoreHome/templates/calendar.js | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/plugins/CoreHome/templates/calendar.js b/plugins/CoreHome/templates/calendar.js new file mode 100644 index 0000000000..a52f856063 --- /dev/null +++ b/plugins/CoreHome/templates/calendar.js @@ -0,0 +1,172 @@ + +Date.prototype.getWeek = function() { +var onejan = new Date(this.getFullYear(),0,1); +return Math.ceil((((this - onejan) / 86400000) + onejan.getDay())/7); +} + +var splitDate = currentDateStr.split("-"); + +var currentYear = splitDate[0]; +var currentMonth = splitDate[1] - 1; +var currentDay = splitDate[2]; + +var currentDate = new Date(currentYear, currentMonth, currentDay); +var todayDate = new Date; +var todayMonth = todayDate.getMonth(); +var todayYear = todayDate.getFullYear(); +var todayDay = todayDate.getDate(); + +function isDateSelected( date ) +{ + var valid = false; + + var dateMonth = date.getMonth(); + var dateYear = date.getFullYear(); + var dateDay = date.getDate(); + var style = ''; + + if( date.toLocaleDateString() == todayDate.toLocaleDateString()) + { + style = style + 'dateToday '; + } + + // we dont color dates in the future + if( dateMonth == todayMonth + && dateYear == todayYear + && dateDay >= todayDay + ) + { + return [true, style]; + } + + // we dont color dates before the minimum date + if( dateYear < minDateYear + || ( dateYear == minDateYear + && + ( + (dateMonth == minDateMonth - 1 + && dateDay < minDateDay) + || (dateMonth < minDateMonth - 1) + ) + ) + ) + { + return [true, style]; + } + + // we color all day of the month for the same year for the month period + if(period == "month" + && dateMonth == currentMonth + && dateYear == currentYear + ) + { + valid = true; + } + // we color all day of the year for the year period + else if(period == "year" + && dateYear == currentYear + ) + { + valid = true; + } + else if(period == "week" + && date.getWeek() == currentDate.getWeek() + && dateYear == currentYear + ) + { + valid = true; + } + else if( period == "day" + && dateDay == currentDay + && dateMonth == currentMonth + && dateYear == currentYear + ) + { + valid = true; + } + + if(valid) + { + return [true, style+'dateUsedStats']; + } + return [true, style]; +} + + +function updateDate() +{ + var date = formatDate(popUpCal.getDateFor($('#calendar')[0])); + + // available in global scope + var currentUrl = window.location.href; + if((startStrDate = currentUrl.indexOf("date")) >= 0) + { + // look for the & after the date + var endStrDate = currentUrl.indexOf("&", startStrDate); + if(endStrDate == -1) + { + endStrDate = currentUrl.length; + } + + var dateToReplace = currentUrl.substring( + startStrDate + 4+1, + endStrDate + ); + regDateToReplace = new RegExp(dateToReplace, 'ig'); + currentUrl = currentUrl.replace( regDateToReplace, date ); + } + else + { + currentUrl = currentUrl + '&date=' + date; + } + + window.location.href = currentUrl; +} + +function formatDate(date) +{ + var day = date.getDate(); + var month = date.getMonth() + 1; + return date.getFullYear() + '-' + + (month < 10 ? '0' : '') + month + '-' + + (day < 10 ? '0' : '') + day ; +} + +$(document).ready(function(){ + $("#calendar").calendar({ + onSelect: updateDate, + showOtherMonths: true, + dateFormat: 'DMY-', + firstDay: 1, + minDate: new Date(minDateYear, minDateMonth - 1, minDateDay), + maxDate: new Date(), + changeFirstDay: false, + prevText: "", + nextText: "", + currentText: "", + customDate: isDateSelected, + dayNames: [ + _pk_translate('CoreHome_DaySu'), + _pk_translate('CoreHome_DayMo'), + _pk_translate('CoreHome_DayTu'), + _pk_translate('CoreHome_DayWe'), + _pk_translate('CoreHome_DayTh'), + _pk_translate('CoreHome_DayFr'), + _pk_translate('CoreHome_DaySa')], + monthNames: [ + _pk_translate('CoreHome_MonthJanuary'), + _pk_translate('CoreHome_MonthFebruary'), + _pk_translate('CoreHome_MonthMarch'), + _pk_translate('CoreHome_MonthApril'), + _pk_translate('CoreHome_MonthMay'), + _pk_translate('CoreHome_MonthJune'), + _pk_translate('CoreHome_MonthJuly'), + _pk_translate('CoreHome_MonthAugust'), + _pk_translate('CoreHome_MonthSeptember'), + _pk_translate('CoreHome_MonthOctober'), + _pk_translate('CoreHome_MonthNovember'), + _pk_translate('CoreHome_MonthDecemeber')] + }, + currentDate); + } +); |