Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.0.X] Fixed #106 -- Refrain from generating popup window names that…

… IE refuses to pop up. Thanks for the reports and initial patches nbstrite and jsmullyan.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@9404 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a2e02a583052bb6061d8c55d5bbf264e85fba0e9 1 parent 8ec6b87
Karen Tracey authored November 12, 2008
25  django/contrib/admin/media/js/admin/RelatedObjectLookups.js
@@ -11,10 +11,25 @@ function html_unescape(text) {
11 11
     return text;
12 12
 }
13 13
 
  14
+// IE doesn't accept periods or dashes in the window name, but the element IDs
  15
+// we use to generate popup window names may contain them, therefore we map them
  16
+// to allowed characters in a reversible way so that we can locate the correct 
  17
+// element when the popup window is dismissed.
  18
+function id_to_windowname(text) {
  19
+    text = text.replace(/\./g, '__dot__');
  20
+    text = text.replace(/\-/g, '__dash__');
  21
+    return text;
  22
+}
  23
+
  24
+function windowname_to_id(text) {
  25
+    text = text.replace(/__dot__/g, '.');
  26
+    text = text.replace(/__dash__/g, '-');
  27
+    return text;
  28
+}
  29
+
14 30
 function showRelatedObjectLookupPopup(triggeringLink) {
15 31
     var name = triggeringLink.id.replace(/^lookup_/, '');
16  
-    // IE doesn't like periods in the window name, so convert temporarily.
17  
-    name = name.replace(/\./g, '___');
  32
+    name = id_to_windowname(name);
18 33
     var href;
19 34
     if (triggeringLink.href.search(/\?/) >= 0) {
20 35
         href = triggeringLink.href + '&pop=1';
@@ -27,7 +42,7 @@ function showRelatedObjectLookupPopup(triggeringLink) {
27 42
 }
28 43
 
29 44
 function dismissRelatedLookupPopup(win, chosenId) {
30  
-    var name = win.name.replace(/___/g, '.');
  45
+    var name = windowname_to_id(win.name);
31 46
     var elem = document.getElementById(name);
32 47
     if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) {
33 48
         elem.value += ',' + chosenId;
@@ -39,7 +54,7 @@ function dismissRelatedLookupPopup(win, chosenId) {
39 54
 
40 55
 function showAddAnotherPopup(triggeringLink) {
41 56
     var name = triggeringLink.id.replace(/^add_/, '');
42  
-    name = name.replace(/\./g, '___');
  57
+    name = id_to_windowname(name);
43 58
     href = triggeringLink.href
44 59
     if (href.indexOf('?') == -1) {
45 60
         href += '?_popup=1';
@@ -56,7 +71,7 @@ function dismissAddAnotherPopup(win, newId, newRepr) {
56 71
     // django.utils.html.escape.
57 72
     newId = html_unescape(newId);
58 73
     newRepr = html_unescape(newRepr);
59  
-    var name = win.name.replace(/___/g, '.');
  74
+    var name = windowname_to_id(win.name);
60 75
     var elem = document.getElementById(name);
61 76
     if (elem) {
62 77
         if (elem.nodeName == 'SELECT') {

0 notes on commit a2e02a5

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