Ticket #4574: 4574.diff
File 4574.diff, 3.3 KB (added by , 13 years ago) |
---|
-
django/contrib/admin/static/admin/js/calendar.js
45 45 } 46 46 return days; 47 47 }, 48 draw: function(month, year, div_id, callback ) { // month = 1-12, year = 1-999948 draw: function(month, year, div_id, callback, selected) { // month = 1-12, year = 1-9999 49 49 var today = new Date(); 50 50 var todayDay = today.getDate(); 51 51 var todayMonth = today.getMonth()+1; 52 52 var todayYear = today.getFullYear(); 53 53 var todayClass = ''; 54 54 var is_selected_month = false; 55 if (typeof selected != 'undefined') { 56 is_selected_month = (selected.getFullYear() == year && (selected.getMonth()+1) == month); 57 } 55 58 month = parseInt(month); 56 59 year = parseInt(year); 57 60 var calDiv = document.getElementById(div_id); … … 74 77 for (var i = 0; i < startingPos; i++) { 75 78 var _cell = quickElement('td', tableRow, ' '); 76 79 _cell.style.backgroundColor = '#f3f3f3'; 80 _cell.className = "nonday"; 77 81 } 78 82 79 83 // Draw days of month … … 82 86 if (i%7 == 0 && currentDay != 1) { 83 87 tableRow = quickElement('tr', tableBody); 84 88 } 89 todayClass=''; 85 90 if ((currentDay==todayDay) && (month==todayMonth) && (year==todayYear)) { 86 91 todayClass='today'; 87 } else {88 todayClass='';89 92 } 93 if (is_selected_month && currentDay == selected.getDate()) { 94 if (todayclass != '') todayclass += " "; 95 todayclass += "selected"; /* e.g: class="today selected" */ 96 } 90 97 var cell = quickElement('td', tableRow, '', 'class', todayClass); 91 98 92 99 quickElement('a', cell, currentDay, 'href', 'javascript:void(' + callback + '('+year+','+month+','+currentDay+'));'); … … 97 104 while (tableRow.childNodes.length < 7) { 98 105 var _cell = quickElement('td', tableRow, ' '); 99 106 _cell.style.backgroundColor = '#f3f3f3'; 107 _cell.className = "nonday"; 100 108 } 101 109 102 110 calDiv.appendChild(calTable); … … 104 112 } 105 113 106 114 // Calendar -- A calendar instance 107 function Calendar(div_id, callback ) {115 function Calendar(div_id, callback, selected) { 108 116 // div_id (string) is the ID of the element in which the calendar will 109 117 // be displayed 110 118 // callback (string) is the name of a JavaScript function that will be … … 115 123 this.today = new Date(); 116 124 this.currentMonth = this.today.getMonth() + 1; 117 125 this.currentYear = this.today.getFullYear(); 126 if (typeof selected == 'undefined') { 127 this.selected = this.today; 128 } 129 else { 130 this.selected = selected; 131 } 118 132 } 119 133 Calendar.prototype = { 120 134 drawCurrent: function() { 121 CalendarNamespace.draw(this.currentMonth, this.currentYear, this.div_id, this.callback );135 CalendarNamespace.draw(this.currentMonth, this.currentYear, this.div_id, this.callback, this.selected); 122 136 }, 123 137 drawDate: function(month, year) { 124 138 this.currentMonth = month;