mirror of
https://github.com/django/django.git
synced 2024-12-22 09:05:43 +00:00
Refs #31032 -- Removed unsupported browsers workarounds and comments in admin's JavaScript.
Since 8b30360322
, the admin documentation
is explicit that only modern evergreen browsers are supported. This
allows removing several long standing workarounds for IE and Opera older
versions.
Since 2013, Opera is based on the Chromium blink engine.
This commit is contained in:
parent
e21788121b
commit
f982f0bdb8
@ -114,16 +114,11 @@
|
||||
SelectBox.cache[id].sort(function(a, b) {
|
||||
a = a.text.toLowerCase();
|
||||
b = b.text.toLowerCase();
|
||||
try {
|
||||
if (a > b) {
|
||||
return 1;
|
||||
}
|
||||
if (a < b) {
|
||||
return -1;
|
||||
}
|
||||
if (a > b) {
|
||||
return 1;
|
||||
}
|
||||
catch (e) {
|
||||
// silently fail on IE 'unknown' exception
|
||||
if (a < b) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
} );
|
||||
|
@ -166,15 +166,9 @@ Requires jQuery, core.js, and SelectBox.js.
|
||||
},
|
||||
any_selected: function(field) {
|
||||
var any_selected = false;
|
||||
try {
|
||||
// Temporarily add the required attribute and check validity.
|
||||
// This is much faster in WebKit browsers than the fallback.
|
||||
field.attr('required', 'required');
|
||||
any_selected = field.is(':valid');
|
||||
} catch (e) {
|
||||
// Browsers that don't support :valid (IE < 10)
|
||||
any_selected = field.find('option:selected').length > 0;
|
||||
}
|
||||
// Temporarily add the required attribute and check validity.
|
||||
field.attr('required', 'required');
|
||||
any_selected = field.is(':valid');
|
||||
field.removeAttr('required');
|
||||
return any_selected;
|
||||
},
|
||||
|
@ -203,8 +203,6 @@
|
||||
else {
|
||||
// since style's width is in em, it'd be tough to calculate
|
||||
// px value of it. let's use an estimated px for now
|
||||
// TODO: IE returns wrong value for findPosX when in rtl mode
|
||||
// (it returns as it was left aligned), needs to be fixed.
|
||||
clock_box.style.left = findPosX(clock_link) - 110 + 'px';
|
||||
}
|
||||
clock_box.style.top = Math.max(0, findPosY(clock_link) - 30) + 'px';
|
||||
@ -376,8 +374,6 @@
|
||||
else {
|
||||
// since style's width is in em, it'd be tough to calculate
|
||||
// px value of it. let's use an estimated px for now
|
||||
// TODO: IE returns wrong value for findPosX when in rtl mode
|
||||
// (it returns as it was left aligned), needs to be fixed.
|
||||
cal_box.style.left = findPosX(cal_link) - 180 + 'px';
|
||||
}
|
||||
cal_box.style.top = Math.max(0, findPosY(cal_link) - 75) + 'px';
|
||||
|
@ -5,25 +5,8 @@
|
||||
(function($) {
|
||||
'use strict';
|
||||
|
||||
// IE doesn't accept periods or dashes in the window name, but the element IDs
|
||||
// we use to generate popup window names may contain them, therefore we map them
|
||||
// to allowed characters in a reversible way so that we can locate the correct
|
||||
// element when the popup window is dismissed.
|
||||
function id_to_windowname(text) {
|
||||
text = text.replace(/\./g, '__dot__');
|
||||
text = text.replace(/\-/g, '__dash__');
|
||||
return text;
|
||||
}
|
||||
|
||||
function windowname_to_id(text) {
|
||||
text = text.replace(/__dot__/g, '.');
|
||||
text = text.replace(/__dash__/g, '-');
|
||||
return text;
|
||||
}
|
||||
|
||||
function showAdminPopup(triggeringLink, name_regexp, add_popup) {
|
||||
var name = triggeringLink.id.replace(name_regexp, '');
|
||||
name = id_to_windowname(name);
|
||||
var href = triggeringLink.href;
|
||||
if (add_popup) {
|
||||
if (href.indexOf('?') === -1) {
|
||||
@ -42,7 +25,7 @@
|
||||
}
|
||||
|
||||
function dismissRelatedLookupPopup(win, chosenId) {
|
||||
var name = windowname_to_id(win.name);
|
||||
var name = win.name;
|
||||
var elem = document.getElementById(name);
|
||||
if (elem.classList.contains('vManyToManyRawIdAdminField') && elem.value) {
|
||||
elem.value += ',' + chosenId;
|
||||
@ -74,7 +57,7 @@
|
||||
}
|
||||
|
||||
function dismissAddRelatedObjectPopup(win, newId, newRepr) {
|
||||
var name = windowname_to_id(win.name);
|
||||
var name = win.name;
|
||||
var elem = document.getElementById(name);
|
||||
if (elem) {
|
||||
var elemName = elem.nodeName.toUpperCase();
|
||||
@ -99,7 +82,7 @@
|
||||
}
|
||||
|
||||
function dismissChangeRelatedObjectPopup(win, objId, newRepr, newId) {
|
||||
var id = windowname_to_id(win.name).replace(/^edit_/, '');
|
||||
var id = win.name.replace(/^edit_/, '');
|
||||
var selectsSelector = interpolate('#%s, #%s_from, #%s_to', [id, id, id]);
|
||||
var selects = $(selectsSelector);
|
||||
selects.find('option').each(function() {
|
||||
@ -118,7 +101,7 @@
|
||||
}
|
||||
|
||||
function dismissDeleteRelatedObjectPopup(win, objId) {
|
||||
var id = windowname_to_id(win.name).replace(/^delete_/, '');
|
||||
var id = win.name.replace(/^delete_/, '');
|
||||
var selectsSelector = interpolate('#%s, #%s_from, #%s_to', [id, id, id]);
|
||||
var selects = $(selectsSelector);
|
||||
selects.find('option').each(function() {
|
||||
@ -129,10 +112,6 @@
|
||||
win.close();
|
||||
}
|
||||
|
||||
// Global for testing purposes
|
||||
window.id_to_windowname = id_to_windowname;
|
||||
window.windowname_to_id = windowname_to_id;
|
||||
|
||||
window.showRelatedObjectLookupPopup = showRelatedObjectLookupPopup;
|
||||
window.dismissRelatedLookupPopup = dismissRelatedLookupPopup;
|
||||
window.showRelatedObjectPopup = showRelatedObjectPopup;
|
||||
|
@ -1,9 +1,5 @@
|
||||
// Core javascript helper functions
|
||||
|
||||
// basic browser identification & version
|
||||
var isOpera = (navigator.userAgent.indexOf("Opera") >= 0) && parseFloat(navigator.appVersion);
|
||||
var isIE = ((document.all) && (!isOpera)) && parseFloat(navigator.appVersion.split("MSIE ")[1].split(";")[0]);
|
||||
|
||||
// quickElement(tagType, parentReference [, textInChildNode, attribute, attributeValue ...]);
|
||||
function quickElement() {
|
||||
'use strict';
|
||||
@ -37,12 +33,8 @@ function findPosX(obj) {
|
||||
var curleft = 0;
|
||||
if (obj.offsetParent) {
|
||||
while (obj.offsetParent) {
|
||||
curleft += obj.offsetLeft - ((isOpera) ? 0 : obj.scrollLeft);
|
||||
obj = obj.offsetParent;
|
||||
}
|
||||
// IE offsetParent does not include the top-level
|
||||
if (isIE && obj.parentElement) {
|
||||
curleft += obj.offsetLeft - obj.scrollLeft;
|
||||
obj = obj.offsetParent;
|
||||
}
|
||||
} else if (obj.x) {
|
||||
curleft += obj.x;
|
||||
@ -55,12 +47,8 @@ function findPosY(obj) {
|
||||
var curtop = 0;
|
||||
if (obj.offsetParent) {
|
||||
while (obj.offsetParent) {
|
||||
curtop += obj.offsetTop - ((isOpera) ? 0 : obj.scrollTop);
|
||||
obj = obj.offsetParent;
|
||||
}
|
||||
// IE offsetParent does not include the top-level
|
||||
if (isIE && obj.parentElement) {
|
||||
curtop += obj.offsetTop - obj.scrollTop;
|
||||
obj = obj.offsetParent;
|
||||
}
|
||||
} else if (obj.y) {
|
||||
curtop += obj.y;
|
||||
|
@ -1,16 +0,0 @@
|
||||
/* global QUnit, id_to_windowname,
|
||||
windowname_to_id */
|
||||
/* eslint strict: 0 */
|
||||
'use strict';
|
||||
|
||||
QUnit.module('admin.RelatedObjectLookups');
|
||||
|
||||
QUnit.test('id_to_windowname', function(assert) {
|
||||
assert.equal(id_to_windowname('.test'), '__dot__test');
|
||||
assert.equal(id_to_windowname('misc-test'), 'misc__dash__test');
|
||||
});
|
||||
|
||||
QUnit.test('windowname_to_id', function(assert) {
|
||||
assert.equal(windowname_to_id('__dot__test'), '.test');
|
||||
assert.equal(windowname_to_id('misc__dash__test'), 'misc-test');
|
||||
});
|
@ -90,7 +90,6 @@
|
||||
<script src='./admin/core.test.js'></script>
|
||||
|
||||
<script src='../django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js' data-cover></script>
|
||||
<script src='./admin/RelatedObjectLookups.test.js'></script>
|
||||
|
||||
<script src='./admin/DateTimeShortcuts.test.js'></script>
|
||||
<script src='../django/contrib/admin/static/admin/js/calendar.js' data-cover></script>
|
||||
|
Loading…
Reference in New Issue
Block a user