Ticket #4574: django_cal_css_classes.diff

File django_cal_css_classes.diff, 3.4 KB (added by calvin@…, 17 years ago)
  • django/contrib/admin/media/js/calendar.js

     
    4444        }
    4545        return days;
    4646    },
    47     draw: function(month, year, div_id, callback) { // month = 1-12, year = 1-9999
     47    draw: function(month, year, div_id, callback, selected) { // month = 1-12, year = 1-9999
    4848        month = parseInt(month);
    4949        year = parseInt(year);
    5050        var calDiv = document.getElementById(div_id);
     
    6666        tableRow = quickElement('tr', tableBody);
    6767        for (var i = 0; i < startingPos; i++) {
    6868            var _cell = quickElement('td', tableRow, ' ');
    69             _cell.style.backgroundColor = '#f3f3f3';
     69            _cell.className = "nonday";
    7070        }
    7171
    7272        // Draw days of month
    7373        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        }
    7480        for (var i = startingPos; currentDay <= days; i++) {
    7581            if (i%7 == 0 && currentDay != 1) {
    7682                tableRow = quickElement('tr', tableBody);
    7783            }
    7884            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            }
    7997            quickElement('a', cell, currentDay, 'href', 'javascript:void(' + callback + '('+year+','+month+','+currentDay+'));');
    8098            currentDay++;
    8199        }
     
    83101        // Draw blanks after end of month (optional, but makes for valid code)
    84102        while (tableRow.childNodes.length < 7) {
    85103            var _cell = quickElement('td', tableRow, ' ');
    86             _cell.style.backgroundColor = '#f3f3f3';
     104            _cell.className = "nonday";
    87105        }
    88106
    89107        calDiv.appendChild(calTable);
     
    91109}
    92110
    93111// Calendar -- A calendar instance
    94 function Calendar(div_id, callback) {
     112function Calendar(div_id, callback, selected) {
    95113    // div_id (string) is the ID of the element in which the calendar will
    96114    //     be displayed
    97115    // callback (string) is the name of a JavaScript function that will be
     
    102120    this.today = new Date();
    103121    this.currentMonth = this.today.getMonth() + 1;
    104122    this.currentYear = this.today.getFullYear();
     123    if (typeof selected == 'undefined') {
     124        this.selected = this.today;
     125    }
     126    else {
     127        this.selected = selected;
     128    }
    105129}
    106130Calendar.prototype = {
    107131    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);
    109133    },
    110134    drawDate: function(month, year) {
    111135        this.currentMonth = month;
Back to Top