Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #11967: use a different technique to get `ADMIN_MEDIA_PREFIX` i…

…n admin JS.

We now store ADMIN_MEDIA_PREFIX on the window object and let JS files read it
from there. The old technique -- looking a <script> tags and trying to deduce
the prefix -- broke with libraries like TineMCE that dynamically add <script>
tags to the <head>.

This is potentially backwards-incompatible for folks who've overridden
`admin/base.html`; they'll need to add the proper <script> line to
their new `admin/base.html`. For that reason, this changeset shouldn't
be backported to 1.1.X.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13002 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ea7df233958e2fd06989f6576b206f6a4cc65435 1 parent fef0d25
Jacob Kaplan-Moss authored April 19, 2010
17  django/contrib/admin/media/js/admin/DateTimeShortcuts.js
@@ -14,15 +14,14 @@ var DateTimeShortcuts = {
14 14
     shortCutsClass: 'datetimeshortcuts', // class of the clock and cal shortcuts
15 15
     admin_media_prefix: '',
16 16
     init: function() {
17  
-        // Deduce admin_media_prefix by looking at the <script>s in the
18  
-        // current document and finding the URL of *this* module.
19  
-        var scripts = document.getElementsByTagName('script');
20  
-        for (var i=0; i<scripts.length; i++) {
21  
-            if (scripts[i].src.match(/DateTimeShortcuts/)) {
22  
-                var idx = scripts[i].src.indexOf('js/admin/DateTimeShortcuts');
23  
-                DateTimeShortcuts.admin_media_prefix = scripts[i].src.substring(0, idx);
24  
-                break;
25  
-            }
  17
+        // Get admin_media_prefix by grabbing it off the window object. It's
  18
+        // set in the admin/base.html template, so if it's not there, someone's
  19
+        // overridden the template. In that case, we'll set a clearly-invalid
  20
+        // value in the hopes that someone will examine HTTP requests and see it.
  21
+        if (window.__admin_media_prefix__ != undefined) {
  22
+            DateTimeShortcuts.admin_media_prefix = window.__admin_media_prefix__;
  23
+        } else {
  24
+            DateTimeShortcuts.admin_media_prefix = '/missing-admin-media-prefix/';
26 25
         }
27 26
 
28 27
         var inputs = document.getElementsByTagName('input');
1  django/contrib/admin/templates/admin/base.html
@@ -6,6 +6,7 @@
6 6
 {% block extrastyle %}{% endblock %}
7 7
 <!--[if lte IE 7]><link rel="stylesheet" type="text/css" href="{% block stylesheet_ie %}{% load adminmedia %}{% admin_media_prefix %}css/ie.css{% endblock %}" /><![endif]-->
8 8
 {% if LANGUAGE_BIDI %}<link rel="stylesheet" type="text/css" href="{% block stylesheet_rtl %}{% admin_media_prefix %}css/rtl.css{% endblock %}" />{% endif %}
  9
+<script type="text/javascript">window.__admin_media_prefix__ = "{% filter escapejs %}{% admin_media_prefix %}{% endfilter %}";</script>
9 10
 {% block extrahead %}{% endblock %}
10 11
 {% block blockbots %}<meta name="robots" content="NONE,NOARCHIVE" />{% endblock %}
11 12
 </head>

0 notes on commit ea7df23

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