diff options
Diffstat (limited to 'plugins/CoreHome/templates/calendar.js')
-rw-r--r-- | plugins/CoreHome/templates/calendar.js | 153 |
1 files changed, 71 insertions, 82 deletions
diff --git a/plugins/CoreHome/templates/calendar.js b/plugins/CoreHome/templates/calendar.js index 506f994e00..43f35f0110 100644 --- a/plugins/CoreHome/templates/calendar.js +++ b/plugins/CoreHome/templates/calendar.js @@ -1,20 +1,22 @@ + Date.prototype.getWeek = function() { - var onejan = new Date(this.getFullYear(),0,1); - return Math.ceil((((this - onejan) / 86400000) + onejan.getDay())/7); +var onejan = new Date(this.getFullYear(),0,1); +return Math.ceil((((this - onejan) / 86400000) + onejan.getDay())/7); } var splitDate = piwik.currentDateString.split("-"); + var currentYear = splitDate[0]; var currentMonth = splitDate[1] - 1; var currentDay = splitDate[2]; -var currentDate = new Date(currentYear, currentMonth, currentDay); +var currentDate = new Date(currentYear, currentMonth, currentDay); var todayDate = new Date; var todayMonth = todayDate.getMonth(); var todayYear = todayDate.getFullYear(); var todayDay = todayDate.getDate(); -function highlightCurrentPeriod( date ) +function isDateSelected( date ) { var valid = false; @@ -23,16 +25,21 @@ function highlightCurrentPeriod( date ) var dateDay = date.getDate(); var style = ''; - // we don't color dates in the future + if( date.toLocaleDateString() == todayDate.toLocaleDateString()) + { + style = style + 'dateToday '; + } + + // we dont color dates in the future if( dateMonth == todayMonth && dateYear == todayYear && dateDay >= todayDay ) { - return [true, '']; + return [true, style]; } - // we don't color dates before the minimum date + // we dont color dates before the minimum date if( dateYear < piwik.minDateYear || ( dateYear == piwik.minDateYear && @@ -44,7 +51,7 @@ function highlightCurrentPeriod( date ) ) ) { - return [true, '']; + return [true, style]; } // we color all day of the month for the same year for the month period @@ -80,85 +87,67 @@ function highlightCurrentPeriod( date ) if(valid) { - return [true, 'ui-datepicker-current-period']; + return [true, style+'dateUsedStats']; } + return [true, style]; +} + - return [true, '']; +function updateDate() +{ + var date = formatDate(popUpCal.getDateFor($('#calendar')[0])); + // Let broadcast do it job: + // It will replace date value to both search query and hash and load the new page. + broadcast.propagateNewPage('date='+date); } -function updateDate(dateText, inst) +function formatDate(date) { - var date = dateText; - // Let broadcast do its job: - // It will replace date value to both search query and hash and load the new page. - broadcast.propagateNewPage('date=' + date); + var day = date.getDate(); + var month = date.getMonth() + 1; + return date.getFullYear() + '-' + + (month < 10 ? '0' : '') + month + '-' + + (day < 10 ? '0' : '') + day ; } $(document).ready(function(){ - $('#datepicker').datepicker({ - onSelect: updateDate, - showOtherMonths: false, - dateFormat: 'yy-mm-dd', - firstDay: 1, - minDate: new Date(piwik.minDateYear, piwik.minDateMonth - 1, piwik.minDateDay), - maxDate: new Date(piwik.maxDateYear, piwik.maxDateMonth - 1, piwik.maxDateDay), - prevText: "", - nextText: "", - currentText: "", - beforeShowDay: highlightCurrentPeriod, - defaultDate: currentDate, - changeMonth: true, - changeYear: true, - // jquery-ui-i18n 1.7.2 lacks some translations, so we use our own - dayNamesMin: [ - _pk_translate('CoreHome_DaySu_js'), - _pk_translate('CoreHome_DayMo_js'), - _pk_translate('CoreHome_DayTu_js'), - _pk_translate('CoreHome_DayWe_js'), - _pk_translate('CoreHome_DayTh_js'), - _pk_translate('CoreHome_DayFr_js'), - _pk_translate('CoreHome_DaySa_js')], - dayNamesShort: [ - _pk_translate('CoreHome_ShortDay_1_js'), - _pk_translate('CoreHome_ShortDay_2_js'), - _pk_translate('CoreHome_ShortDay_3_js'), - _pk_translate('CoreHome_ShortDay_4_js'), - _pk_translate('CoreHome_ShortDay_5_js'), - _pk_translate('CoreHome_ShortDay_6_js'), - _pk_translate('CoreHome_ShortDay_7_js')], - dayNames: [ - _pk_translate('CoreHome_LongDay_1_js'), - _pk_translate('CoreHome_LongDay_2_js'), - _pk_translate('CoreHome_LongDay_3_js'), - _pk_translate('CoreHome_LongDay_4_js'), - _pk_translate('CoreHome_LongDay_5_js'), - _pk_translate('CoreHome_LongDay_6_js'), - _pk_translate('CoreHome_LongDay_7_js')], - monthNamesShort: [ - _pk_translate('CoreHome_ShortMonth_1_js'), - _pk_translate('CoreHome_ShortMonth_2_js'), - _pk_translate('CoreHome_ShortMonth_3_js'), - _pk_translate('CoreHome_ShortMonth_4_js'), - _pk_translate('CoreHome_ShortMonth_5_js'), - _pk_translate('CoreHome_ShortMonth_6_js'), - _pk_translate('CoreHome_ShortMonth_7_js'), - _pk_translate('CoreHome_ShortMonth_8_js'), - _pk_translate('CoreHome_ShortMonth_9_js'), - _pk_translate('CoreHome_ShortMonth_10_js'), - _pk_translate('CoreHome_ShortMonth_11_js'), - _pk_translate('CoreHome_ShortMonth_12_js')], - monthNames: [ - _pk_translate('CoreHome_MonthJanuary_js'), - _pk_translate('CoreHome_MonthFebruary_js'), - _pk_translate('CoreHome_MonthMarch_js'), - _pk_translate('CoreHome_MonthApril_js'), - _pk_translate('CoreHome_MonthMay_js'), - _pk_translate('CoreHome_MonthJune_js'), - _pk_translate('CoreHome_MonthJuly_js'), - _pk_translate('CoreHome_MonthAugust_js'), - _pk_translate('CoreHome_MonthSeptember_js'), - _pk_translate('CoreHome_MonthOctober_js'), - _pk_translate('CoreHome_MonthNovember_js'), - _pk_translate('CoreHome_MonthDecember_js')] - }); -}); + + $("#calendar").calendar({ + onSelect: updateDate, + showOtherMonths: true, + dateFormat: 'DMY-', + firstDay: 1, + minDate: new Date(piwik.minDateYear, piwik.minDateMonth - 1, piwik.minDateDay), + maxDate: new Date(piwik.maxDateYear, piwik.maxDateMonth - 1, piwik.maxDateDay), + changeFirstDay: false, + prevText: "", + nextText: "", + currentText: "", + customDate: isDateSelected, + dayNames: [ + _pk_translate('CoreHome_DaySu_js'), + _pk_translate('CoreHome_DayMo_js'), + _pk_translate('CoreHome_DayTu_js'), + _pk_translate('CoreHome_DayWe_js'), + _pk_translate('CoreHome_DayTh_js'), + _pk_translate('CoreHome_DayFr_js'), + _pk_translate('CoreHome_DaySa_js')], + monthNames: [ + _pk_translate('CoreHome_MonthJanuary_js'), + _pk_translate('CoreHome_MonthFebruary_js'), + _pk_translate('CoreHome_MonthMarch_js'), + _pk_translate('CoreHome_MonthApril_js'), + _pk_translate('CoreHome_MonthMay_js'), + _pk_translate('CoreHome_MonthJune_js'), + _pk_translate('CoreHome_MonthJuly_js'), + _pk_translate('CoreHome_MonthAugust_js'), + _pk_translate('CoreHome_MonthSeptember_js'), + _pk_translate('CoreHome_MonthOctober_js'), + _pk_translate('CoreHome_MonthNovember_js'), + _pk_translate('CoreHome_MonthDecember_js')] + }, + currentDate); + + $("#calendar").hide(); + } +); |