Ticket #4574: django_cal_css_classes.diff
File django_cal_css_classes.diff, 3.4 KB (added by , 17 years ago) |
---|
-
django/contrib/admin/media/js/calendar.js
44 44 } 45 45 return days; 46 46 }, 47 draw: function(month, year, div_id, callback ) { // month = 1-12, year = 1-999947 draw: function(month, year, div_id, callback, selected) { // month = 1-12, year = 1-9999 48 48 month = parseInt(month); 49 49 year = parseInt(year); 50 50 var calDiv = document.getElementById(div_id); … … 66 66 tableRow = quickElement('tr', tableBody); 67 67 for (var i = 0; i < startingPos; i++) { 68 68 var _cell = quickElement('td', tableRow, ' '); 69 _cell. style.backgroundColor = '#f3f3f3';69 _cell.className = "nonday"; 70 70 } 71 71 72 72 // Draw days of month 73 73 var currentDay = 1; 74 var today = new Date(); 75 var is_current_month = (today.getFullYear() == year && (today.getMonth()+1) == month); 76 var is_selected_month = false; 77 if (typeof selected != 'undefined') { 78 is_selected_month = (selected.getFullYear() == year && (selected.getMonth()+1) == month); 79 } 74 80 for (var i = startingPos; currentDay <= days; i++) { 75 81 if (i%7 == 0 && currentDay != 1) { 76 82 tableRow = quickElement('tr', tableBody); 77 83 } 78 84 var cell = quickElement('td', tableRow, ''); 85 var elemclass = ''; 86 if (is_current_month && currentDay == today.getDate()) { 87 if (elemclass != '') elemclass += " "; 88 elemclass += "today"; 89 } 90 if (is_selected_month && currentDay == selected.getDate()) { 91 if (elemclass != '') elemclass += " "; 92 elemclass += "selected"; 93 } 94 if (elemclass != '') { 95 cell.className = elemclass; 96 } 79 97 quickElement('a', cell, currentDay, 'href', 'javascript:void(' + callback + '('+year+','+month+','+currentDay+'));'); 80 98 currentDay++; 81 99 } … … 83 101 // Draw blanks after end of month (optional, but makes for valid code) 84 102 while (tableRow.childNodes.length < 7) { 85 103 var _cell = quickElement('td', tableRow, ' '); 86 _cell. style.backgroundColor = '#f3f3f3';104 _cell.className = "nonday"; 87 105 } 88 106 89 107 calDiv.appendChild(calTable); … … 91 109 } 92 110 93 111 // Calendar -- A calendar instance 94 function Calendar(div_id, callback ) {112 function Calendar(div_id, callback, selected) { 95 113 // div_id (string) is the ID of the element in which the calendar will 96 114 // be displayed 97 115 // callback (string) is the name of a JavaScript function that will be … … 102 120 this.today = new Date(); 103 121 this.currentMonth = this.today.getMonth() + 1; 104 122 this.currentYear = this.today.getFullYear(); 123 if (typeof selected == 'undefined') { 124 this.selected = this.today; 125 } 126 else { 127 this.selected = selected; 128 } 105 129 } 106 130 Calendar.prototype = { 107 131 drawCurrent: function() { 108 CalendarNamespace.draw(this.currentMonth, this.currentYear, this.div_id, this.callback );132 CalendarNamespace.draw(this.currentMonth, this.currentYear, this.div_id, this.callback, this.selected); 109 133 }, 110 134 drawDate: function(month, year) { 111 135 this.currentMonth = month;