Fixed #25149 -- Replaced window.__admin_utc_offset__ with a data attribute.

This commit is contained in:
Tim Graham 2015-07-20 16:09:42 -04:00
parent 5aba3f0a45
commit 8eeb566aca
3 changed files with 12 additions and 9 deletions

View File

@ -18,8 +18,9 @@ var DateTimeShortcuts = {
timezoneWarningClass: 'timezonewarning', // class of the warning for timezone mismatch timezoneWarningClass: 'timezonewarning', // class of the warning for timezone mismatch
timezoneOffset: 0, timezoneOffset: 0,
init: function() { init: function() {
if (window.__admin_utc_offset__ !== undefined) { var body = document.getElementsByTagName('body')[0];
var serverOffset = window.__admin_utc_offset__; var serverOffset = body.getAttribute('data-admin-utc-offset');
if (serverOffset !== undefined) {
var localOffset = new Date().getTimezoneOffset() * -60; var localOffset = new Date().getTimezoneOffset() * -60;
DateTimeShortcuts.timezoneOffset = localOffset - serverOffset; DateTimeShortcuts.timezoneOffset = localOffset - serverOffset;
} }
@ -39,8 +40,9 @@ var DateTimeShortcuts = {
}, },
// Return the current time while accounting for the server timezone. // Return the current time while accounting for the server timezone.
now: function() { now: function() {
if (window.__admin_utc_offset__ !== undefined) { var body = document.getElementsByTagName('body')[0];
var serverOffset = window.__admin_utc_offset__; var serverOffset = body.getAttribute('data-admin-utc-offset');
if (serverOffset !== undefined) {
var localNow = new Date(); var localNow = new Date();
var localOffset = localNow.getTimezoneOffset() * -60; var localOffset = localNow.getTimezoneOffset() * -60;
localNow.setTime(localNow.getTime() + 1000 * (serverOffset - localOffset)); localNow.setTime(localNow.getTime() + 1000 * (serverOffset - localOffset));

View File

@ -6,13 +6,13 @@
<link rel="stylesheet" type="text/css" href="{% block stylesheet %}{% static "admin/css/base.css" %}{% endblock %}" /> <link rel="stylesheet" type="text/css" href="{% block stylesheet %}{% static "admin/css/base.css" %}{% endblock %}" />
{% block extrastyle %}{% endblock %} {% block extrastyle %}{% endblock %}
{% if LANGUAGE_BIDI %}<link rel="stylesheet" type="text/css" href="{% block stylesheet_rtl %}{% static "admin/css/rtl.css" %}{% endblock %}" />{% endif %} {% if LANGUAGE_BIDI %}<link rel="stylesheet" type="text/css" href="{% block stylesheet_rtl %}{% static "admin/css/rtl.css" %}{% endblock %}" />{% endif %}
<script type="text/javascript">window.__admin_utc_offset__ = "{% filter escapejs %}{% now "Z" %}{% 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>
{% load i18n %} {% load i18n %}
<body class="{% if is_popup %}popup {% endif %}{% block bodyclass %}{% endblock %}"> <body class="{% if is_popup %}popup {% endif %}{% block bodyclass %}{% endblock %}"
data-admin-utc-offset="{% filter escapejs %}{% now "Z" %}{% endfilter %}">
<!-- Container --> <!-- Container -->
<div id="container"> <div id="container">

View File

@ -846,9 +846,10 @@ Miscellaneous
* ``ValuesQuerySet`` and ``ValuesListQuerySet`` have been removed. * ``ValuesQuerySet`` and ``ValuesListQuerySet`` have been removed.
* The ``admin/base.html`` template no longer sets * The ``admin/base.html`` template no longer sets
``window.__admin_media_prefix__``. Image references in JavaScript that used ``window.__admin_media_prefix__`` or ``window.__admin_utc_offset__``. Image
that value to construct absolute URLs have been moved to CSS for easier references in JavaScript that used that value to construct absolute URLs have
customization. been moved to CSS for easier customization. The UTC offset is stored on a
data attribute of the ``<body>`` tag.
* ``CommaSeparatedIntegerField`` validation has been refined to forbid values * ``CommaSeparatedIntegerField`` validation has been refined to forbid values
like ``','``, ``',1'``, and ``'1,,2'``. like ``','``, ``',1'``, and ``'1,,2'``.