mirror of https://github.com/django/django.git
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:
parent
fef0d25bdc
commit
ea7df23395
|
@ -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');
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue