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
This commit is contained in:
Jacob Kaplan-Moss 2010-04-19 18:37:12 +00:00
parent fef0d25bdc
commit ea7df23395
2 changed files with 9 additions and 9 deletions

View File

@ -14,15 +14,14 @@ var DateTimeShortcuts = {
shortCutsClass: 'datetimeshortcuts', // class of the clock and cal shortcuts shortCutsClass: 'datetimeshortcuts', // class of the clock and cal shortcuts
admin_media_prefix: '', admin_media_prefix: '',
init: function() { init: function() {
// Deduce admin_media_prefix by looking at the <script>s in the // Get admin_media_prefix by grabbing it off the window object. It's
// current document and finding the URL of *this* module. // set in the admin/base.html template, so if it's not there, someone's
var scripts = document.getElementsByTagName('script'); // overridden the template. In that case, we'll set a clearly-invalid
for (var i=0; i<scripts.length; i++) { // value in the hopes that someone will examine HTTP requests and see it.
if (scripts[i].src.match(/DateTimeShortcuts/)) { if (window.__admin_media_prefix__ != undefined) {
var idx = scripts[i].src.indexOf('js/admin/DateTimeShortcuts'); DateTimeShortcuts.admin_media_prefix = window.__admin_media_prefix__;
DateTimeShortcuts.admin_media_prefix = scripts[i].src.substring(0, idx); } else {
break; DateTimeShortcuts.admin_media_prefix = '/missing-admin-media-prefix/';
}
} }
var inputs = document.getElementsByTagName('input'); var inputs = document.getElementsByTagName('input');

View File

@ -6,6 +6,7 @@
{% block extrastyle %}{% endblock %} {% 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 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 %} {% 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 extrahead %}{% endblock %}
{% block blockbots %}<meta name="robots" content="NONE,NOARCHIVE" />{% endblock %} {% block blockbots %}<meta name="robots" content="NONE,NOARCHIVE" />{% endblock %}
</head> </head>