Code

Ticket #11314: CalUsability.diff

File CalUsability.diff, 1.3 KB (added by latentflip, 5 years ago)

Adds Today's date highlighting to admin calendar widget

Line 
1Index: django/contrib/admin/media/js/calendar.js
2===================================================================
3--- django/contrib/admin/media/js/calendar.js   (revision 11003)
4+++ django/contrib/admin/media/js/calendar.js   (working copy)
5@@ -45,6 +45,12 @@
6         return days;
7     },
8     draw: function(month, year, div_id, callback) { // month = 1-12, year = 1-9999
9+        var today = new Date();
10+        var todayDay = today.getDate();
11+        var todayMonth = today.getMonth()+1;
12+        var todayYear = today.getFullYear();
13+        var todayClass = '';
14+       
15         month = parseInt(month);
16         year = parseInt(year);
17         var calDiv = document.getElementById(div_id);
18@@ -75,7 +81,13 @@
19             if (i%7 == 0 && currentDay != 1) {
20                 tableRow = quickElement('tr', tableBody);
21             }
22-            var cell = quickElement('td', tableRow, '');
23+            if ((currentDay==todayDay) && (month==todayMonth) && (year==todayYear)) {
24+                todayClass='today';
25+            } else {
26+                todayClass='';
27+            }
28+            var cell = quickElement('td', tableRow, '', 'class', todayClass);
29+           
30             quickElement('a', cell, currentDay, 'href', 'javascript:void(' + callback + '('+year+','+month+','+currentDay+'));');
31             currentDay++;
32         }