Author: russellm
Date: 2006-07-31 19:19:04 -0500 (Mon, 31 Jul 2006)
New Revision: 3504

Modified:
   django/trunk/django/contrib/admin/media/js/admin/DateTimeShortcuts.js
Log:
Modified Calendar and Clock javascript to evaluate popup position at time of 
display, rather than time of page load. 

Modified: django/trunk/django/contrib/admin/media/js/admin/DateTimeShortcuts.js
===================================================================
--- django/trunk/django/contrib/admin/media/js/admin/DateTimeShortcuts.js       
2006-07-31 21:31:35 UTC (rev 3503)
+++ django/trunk/django/contrib/admin/media/js/admin/DateTimeShortcuts.js       
2006-08-01 00:19:04 UTC (rev 3504)
@@ -8,7 +8,9 @@
     clockInputs: [],
     calendarDivName1: 'calendarbox', // name of calendar <div> that gets 
toggled
     calendarDivName2: 'calendarin',  // name of <div> that contains calendar
+    calendarLinkName: 'calendarlink',// name of the link that is used to toggle
     clockDivName: 'clockbox',        // name of clock <div> that gets toggled
+    clockLinkName: 'clocklink',      // name of the link that is used to toggle
     admin_media_prefix: '',
     init: function() {
         // Deduce admin_media_prefix by looking at the <script>s in the
@@ -46,6 +48,7 @@
         now_link.appendChild(document.createTextNode(gettext('Now')));
         var clock_link = document.createElement('a');
         clock_link.setAttribute('href', 
'javascript:DateTimeShortcuts.openClock(' + num + ');');
+        clock_link.id = DateTimeShortcuts.clockLinkName + num;
         quickElement('img', clock_link, '', 'src', 
DateTimeShortcuts.admin_media_prefix + 'img/admin/icon_clock.gif', 'alt', 
gettext('Clock'));
         shortcuts_span.appendChild(document.createTextNode('\240'));
         shortcuts_span.appendChild(now_link);
@@ -69,17 +72,6 @@
         var clock_box = document.createElement('div');
         clock_box.style.display = 'none';
         clock_box.style.position = 'absolute';
-        if (getStyle(document.body,'direction')!='rtl') {
-            clock_box.style.left = findPosX(clock_link) + 17 + 'px';
-        }
-        else {
-            // since style's width is in em, it'd be tough to calculate
-            // px value of it. let's use an estimated px for now
-            // TODO: IE returns wrong value for findPosX when in rtl mode
-            //       (it returns as it was left aligned), needs to be fixed.
-            clock_box.style.left = findPosX(clock_link) - 110 + 'px';
-        }
-        clock_box.style.top = findPosY(clock_link) - 30 + 'px';
         clock_box.className = 'clockbox module';
         clock_box.setAttribute('id', DateTimeShortcuts.clockDivName + num);
         document.body.appendChild(clock_box);
@@ -98,7 +90,25 @@
         quickElement('a', cancel_p, gettext('Cancel'), 'href', 
'javascript:DateTimeShortcuts.dismissClock(' + num + ');');
     },
     openClock: function(num) {
-        document.getElementById(DateTimeShortcuts.clockDivName + 
num).style.display = 'block';
+        var clock_box = 
document.getElementById(DateTimeShortcuts.clockDivName+num)
+        var clock_link = 
document.getElementById(DateTimeShortcuts.clockLinkName+num)
+    
+        // Recalculate the clockbox position
+        // is it left-to-right or right-to-left layout ?
+        if (getStyle(document.body,'direction')!='rtl') {
+            clock_box.style.left = findPosX(clock_link) + 17 + 'px';
+        }
+        else {
+            // since style's width is in em, it'd be tough to calculate
+            // px value of it. let's use an estimated px for now
+            // TODO: IE returns wrong value for findPosX when in rtl mode
+            //       (it returns as it was left aligned), needs to be fixed.
+            clock_box.style.left = findPosX(clock_link) - 110 + 'px';
+        }
+        clock_box.style.top = findPosY(clock_link) - 30 + 'px';
+    
+        // Show the clock box
+        clock_box.style.display = 'block';
         addEvent(window, 'click', function() { 
DateTimeShortcuts.dismissClock(num); return true; });
     },
     dismissClock: function(num) {
@@ -123,6 +133,7 @@
         today_link.appendChild(document.createTextNode(gettext('Today')));
         var cal_link = document.createElement('a');
         cal_link.setAttribute('href', 
'javascript:DateTimeShortcuts.openCalendar(' + num + ');');
+        cal_link.id = DateTimeShortcuts.calendarLinkName + num;
         quickElement('img', cal_link, '', 'src', 
DateTimeShortcuts.admin_media_prefix + 'img/admin/icon_calendar.gif', 'alt', 
gettext('Calendar'));
         shortcuts_span.appendChild(document.createTextNode('\240'));
         shortcuts_span.appendChild(today_link);
@@ -149,18 +160,6 @@
         var cal_box = document.createElement('div');
         cal_box.style.display = 'none';
         cal_box.style.position = 'absolute';
-        // is it left-to-right or right-to-left layout ?
-        if (getStyle(document.body,'direction')!='rtl') {
-            cal_box.style.left = findPosX(cal_link) + 17 + 'px';
-        }
-        else {
-            // since style's width is in em, it'd be tough to calculate
-            // px value of it. let's use an estimated px for now
-            // TODO: IE returns wrong value for findPosX when in rtl mode
-            //       (it returns as it was left aligned), needs to be fixed.
-            cal_box.style.left = findPosX(cal_link) - 180 + 'px';
-        }
-        cal_box.style.top = findPosY(cal_link) - 75 + 'px';
         cal_box.className = 'calendarbox module';
         cal_box.setAttribute('id', DateTimeShortcuts.calendarDivName1 + num);
         document.body.appendChild(cal_box);
@@ -195,7 +194,24 @@
         quickElement('a', cancel_p, gettext('Cancel'), 'href', 
'javascript:DateTimeShortcuts.dismissCalendar(' + num + ');');
     },
     openCalendar: function(num) {
-        
document.getElementById(DateTimeShortcuts.calendarDivName1+num).style.display = 
'block';
+        var cal_box = 
document.getElementById(DateTimeShortcuts.calendarDivName1+num)
+        var cal_link = 
document.getElementById(DateTimeShortcuts.calendarLinkName+num)
+    
+        // Recalculate the clockbox position
+        // is it left-to-right or right-to-left layout ?
+        if (getStyle(document.body,'direction')!='rtl') {
+            cal_box.style.left = findPosX(cal_link) + 17 + 'px';
+        }
+        else {
+            // since style's width is in em, it'd be tough to calculate
+            // px value of it. let's use an estimated px for now
+            // TODO: IE returns wrong value for findPosX when in rtl mode
+            //       (it returns as it was left aligned), needs to be fixed.
+            cal_box.style.left = findPosX(cal_link) - 180 + 'px';
+        }
+        cal_box.style.top = findPosY(cal_link) - 75 + 'px';
+    
+        cal_box.style.display = 'block';
         addEvent(window, 'click', function() { 
DateTimeShortcuts.dismissCalendar(num); return true; });
     },
     dismissCalendar: function(num) {


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates
-~----------~----~----~----~------~----~------~--~---

Reply via email to