diff options
| author | Jacob Kaplan-Moss <jacob@jacobian.org> | 2010-04-19 18:37:12 +0000 |
|---|---|---|
| committer | Jacob Kaplan-Moss <jacob@jacobian.org> | 2010-04-19 18:37:12 +0000 |
| commit | ea7df233958e2fd06989f6576b206f6a4cc65435 (patch) | |
| tree | ded57ea80e3cda974d97be8aff576d53ee654520 | |
| parent | fef0d25bdccbb8f01314cf3a94651d3cfe67a34e (diff) | |
Fixed #11967: use a different technique to get `ADMIN_MEDIA_PREFIX` in 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
| -rw-r--r-- | django/contrib/admin/media/js/admin/DateTimeShortcuts.js | 17 | ||||
| -rw-r--r-- | django/contrib/admin/templates/admin/base.html | 1 |
2 files changed, 9 insertions, 9 deletions
diff --git a/django/contrib/admin/media/js/admin/DateTimeShortcuts.js b/django/contrib/admin/media/js/admin/DateTimeShortcuts.js index d840f78729..2e43a68674 100644 --- a/django/contrib/admin/media/js/admin/DateTimeShortcuts.js +++ b/django/contrib/admin/media/js/admin/DateTimeShortcuts.js @@ -14,15 +14,14 @@ var DateTimeShortcuts = { shortCutsClass: 'datetimeshortcuts', // class of the clock and cal shortcuts admin_media_prefix: '', init: function() { - // Deduce admin_media_prefix by looking at the <script>s in the - // current document and finding the URL of *this* module. - var scripts = document.getElementsByTagName('script'); - for (var i=0; i<scripts.length; i++) { - if (scripts[i].src.match(/DateTimeShortcuts/)) { - var idx = scripts[i].src.indexOf('js/admin/DateTimeShortcuts'); - DateTimeShortcuts.admin_media_prefix = scripts[i].src.substring(0, idx); - break; - } + // Get admin_media_prefix by grabbing it off the window object. It's + // set in the admin/base.html template, so if it's not there, someone's + // overridden the template. In that case, we'll set a clearly-invalid + // value in the hopes that someone will examine HTTP requests and see it. + if (window.__admin_media_prefix__ != undefined) { + DateTimeShortcuts.admin_media_prefix = window.__admin_media_prefix__; + } else { + DateTimeShortcuts.admin_media_prefix = '/missing-admin-media-prefix/'; } var inputs = document.getElementsByTagName('input'); diff --git a/django/contrib/admin/templates/admin/base.html b/django/contrib/admin/templates/admin/base.html index f3b403bdb3..3fd9eb3770 100644 --- a/django/contrib/admin/templates/admin/base.html +++ b/django/contrib/admin/templates/admin/base.html @@ -6,6 +6,7 @@ {% block extrastyle %}{% endblock %} <!--[if lte IE 7]><link rel="stylesheet" type="text/css" href="{% block stylesheet_ie %}{% load adminmedia %}{% admin_media_prefix %}css/ie.css{% endblock %}" /><![endif]--> {% if LANGUAGE_BIDI %}<link rel="stylesheet" type="text/css" href="{% block stylesheet_rtl %}{% admin_media_prefix %}css/rtl.css{% endblock %}" />{% endif %} +<script type="text/javascript">window.__admin_media_prefix__ = "{% filter escapejs %}{% admin_media_prefix %}{% endfilter %}";</script> {% block extrahead %}{% endblock %} {% block blockbots %}<meta name="robots" content="NONE,NOARCHIVE" />{% endblock %} </head> |
