Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Modified Calendar and Clock javascript to evaluate popup position at …

…time of display, rather than time of page load.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3504 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 97aa9b28437aecb867c82b12d9970b030262822e 1 parent 77f1b8a
Russell Keith-Magee authored August 01, 2006
66  django/contrib/admin/media/js/admin/DateTimeShortcuts.js
@@ -8,7 +8,9 @@ var DateTimeShortcuts = {
8 8
     clockInputs: [],
9 9
     calendarDivName1: 'calendarbox', // name of calendar <div> that gets toggled
10 10
     calendarDivName2: 'calendarin',  // name of <div> that contains calendar
  11
+    calendarLinkName: 'calendarlink',// name of the link that is used to toggle
11 12
     clockDivName: 'clockbox',        // name of clock <div> that gets toggled
  13
+    clockLinkName: 'clocklink',      // name of the link that is used to toggle
12 14
     admin_media_prefix: '',
13 15
     init: function() {
14 16
         // Deduce admin_media_prefix by looking at the <script>s in the
@@ -46,6 +48,7 @@ var DateTimeShortcuts = {
46 48
         now_link.appendChild(document.createTextNode(gettext('Now')));
47 49
         var clock_link = document.createElement('a');
48 50
         clock_link.setAttribute('href', 'javascript:DateTimeShortcuts.openClock(' + num + ');');
  51
+        clock_link.id = DateTimeShortcuts.clockLinkName + num;
49 52
         quickElement('img', clock_link, '', 'src', DateTimeShortcuts.admin_media_prefix + 'img/admin/icon_clock.gif', 'alt', gettext('Clock'));
50 53
         shortcuts_span.appendChild(document.createTextNode('\240'));
51 54
         shortcuts_span.appendChild(now_link);
@@ -69,17 +72,6 @@ var DateTimeShortcuts = {
69 72
         var clock_box = document.createElement('div');
70 73
         clock_box.style.display = 'none';
71 74
         clock_box.style.position = 'absolute';
72  
-        if (getStyle(document.body,'direction')!='rtl') {
73  
-            clock_box.style.left = findPosX(clock_link) + 17 + 'px';
74  
-        }
75  
-        else {
76  
-            // since style's width is in em, it'd be tough to calculate
77  
-            // px value of it. let's use an estimated px for now
78  
-            // TODO: IE returns wrong value for findPosX when in rtl mode
79  
-            //       (it returns as it was left aligned), needs to be fixed.
80  
-            clock_box.style.left = findPosX(clock_link) - 110 + 'px';
81  
-        }
82  
-        clock_box.style.top = findPosY(clock_link) - 30 + 'px';
83 75
         clock_box.className = 'clockbox module';
84 76
         clock_box.setAttribute('id', DateTimeShortcuts.clockDivName + num);
85 77
         document.body.appendChild(clock_box);
@@ -98,7 +90,25 @@ var DateTimeShortcuts = {
98 90
         quickElement('a', cancel_p, gettext('Cancel'), 'href', 'javascript:DateTimeShortcuts.dismissClock(' + num + ');');
99 91
     },
100 92
     openClock: function(num) {
101  
-        document.getElementById(DateTimeShortcuts.clockDivName + num).style.display = 'block';
  93
+        var clock_box = document.getElementById(DateTimeShortcuts.clockDivName+num)
  94
+        var clock_link = document.getElementById(DateTimeShortcuts.clockLinkName+num)
  95
+    
  96
+        // Recalculate the clockbox position
  97
+        // is it left-to-right or right-to-left layout ?
  98
+        if (getStyle(document.body,'direction')!='rtl') {
  99
+            clock_box.style.left = findPosX(clock_link) + 17 + 'px';
  100
+        }
  101
+        else {
  102
+            // since style's width is in em, it'd be tough to calculate
  103
+            // px value of it. let's use an estimated px for now
  104
+            // TODO: IE returns wrong value for findPosX when in rtl mode
  105
+            //       (it returns as it was left aligned), needs to be fixed.
  106
+            clock_box.style.left = findPosX(clock_link) - 110 + 'px';
  107
+        }
  108
+        clock_box.style.top = findPosY(clock_link) - 30 + 'px';
  109
+    
  110
+        // Show the clock box
  111
+        clock_box.style.display = 'block';
102 112
         addEvent(window, 'click', function() { DateTimeShortcuts.dismissClock(num); return true; });
103 113
     },
104 114
     dismissClock: function(num) {
@@ -123,6 +133,7 @@ var DateTimeShortcuts = {
123 133
         today_link.appendChild(document.createTextNode(gettext('Today')));
124 134
         var cal_link = document.createElement('a');
125 135
         cal_link.setAttribute('href', 'javascript:DateTimeShortcuts.openCalendar(' + num + ');');
  136
+        cal_link.id = DateTimeShortcuts.calendarLinkName + num;
126 137
         quickElement('img', cal_link, '', 'src', DateTimeShortcuts.admin_media_prefix + 'img/admin/icon_calendar.gif', 'alt', gettext('Calendar'));
127 138
         shortcuts_span.appendChild(document.createTextNode('\240'));
128 139
         shortcuts_span.appendChild(today_link);
@@ -149,18 +160,6 @@ var DateTimeShortcuts = {
149 160
         var cal_box = document.createElement('div');
150 161
         cal_box.style.display = 'none';
151 162
         cal_box.style.position = 'absolute';
152  
-        // is it left-to-right or right-to-left layout ?
153  
-        if (getStyle(document.body,'direction')!='rtl') {
154  
-            cal_box.style.left = findPosX(cal_link) + 17 + 'px';
155  
-        }
156  
-        else {
157  
-            // since style's width is in em, it'd be tough to calculate
158  
-            // px value of it. let's use an estimated px for now
159  
-            // TODO: IE returns wrong value for findPosX when in rtl mode
160  
-            //       (it returns as it was left aligned), needs to be fixed.
161  
-            cal_box.style.left = findPosX(cal_link) - 180 + 'px';
162  
-        }
163  
-        cal_box.style.top = findPosY(cal_link) - 75 + 'px';
164 163
         cal_box.className = 'calendarbox module';
165 164
         cal_box.setAttribute('id', DateTimeShortcuts.calendarDivName1 + num);
166 165
         document.body.appendChild(cal_box);
@@ -195,7 +194,24 @@ var DateTimeShortcuts = {
195 194
         quickElement('a', cancel_p, gettext('Cancel'), 'href', 'javascript:DateTimeShortcuts.dismissCalendar(' + num + ');');
196 195
     },
197 196
     openCalendar: function(num) {
198  
-        document.getElementById(DateTimeShortcuts.calendarDivName1+num).style.display = 'block';
  197
+        var cal_box = document.getElementById(DateTimeShortcuts.calendarDivName1+num)
  198
+        var cal_link = document.getElementById(DateTimeShortcuts.calendarLinkName+num)
  199
+    
  200
+        // Recalculate the clockbox position
  201
+        // is it left-to-right or right-to-left layout ?
  202
+        if (getStyle(document.body,'direction')!='rtl') {
  203
+            cal_box.style.left = findPosX(cal_link) + 17 + 'px';
  204
+        }
  205
+        else {
  206
+            // since style's width is in em, it'd be tough to calculate
  207
+            // px value of it. let's use an estimated px for now
  208
+            // TODO: IE returns wrong value for findPosX when in rtl mode
  209
+            //       (it returns as it was left aligned), needs to be fixed.
  210
+            cal_box.style.left = findPosX(cal_link) - 180 + 'px';
  211
+        }
  212
+        cal_box.style.top = findPosY(cal_link) - 75 + 'px';
  213
+    
  214
+        cal_box.style.display = 'block';
199 215
         addEvent(window, 'click', function() { DateTimeShortcuts.dismissCalendar(num); return true; });
200 216
     },
201 217
     dismissCalendar: function(num) {

0 notes on commit 97aa9b2

Please sign in to comment.
Something went wrong with that request. Please try again.