From f982f0bdb8317e75af416595c616943d5025da1e Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sun, 22 Mar 2020 22:19:10 -0700 Subject: [PATCH] Refs #31032 -- Removed unsupported browsers workarounds and comments in admin's JavaScript. Since 8b30360322d4de6687e17ab267a856db4e3c78a6, 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. --- .../admin/static/admin/js/SelectBox.js | 13 +++------ .../admin/static/admin/js/SelectFilter2.js | 12 ++------ .../admin/js/admin/DateTimeShortcuts.js | 4 --- .../admin/js/admin/RelatedObjectLookups.js | 29 +++---------------- django/contrib/admin/static/admin/js/core.js | 16 ++-------- js_tests/admin/RelatedObjectLookups.test.js | 16 ---------- js_tests/tests.html | 1 - 7 files changed, 13 insertions(+), 78 deletions(-) delete mode 100644 js_tests/admin/RelatedObjectLookups.test.js diff --git a/django/contrib/admin/static/admin/js/SelectBox.js b/django/contrib/admin/static/admin/js/SelectBox.js index 68e29d58283..0e92836414e 100644 --- a/django/contrib/admin/static/admin/js/SelectBox.js +++ b/django/contrib/admin/static/admin/js/SelectBox.js @@ -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; } ); diff --git a/django/contrib/admin/static/admin/js/SelectFilter2.js b/django/contrib/admin/static/admin/js/SelectFilter2.js index c1002b9c049..72ecc83aada 100644 --- a/django/contrib/admin/static/admin/js/SelectFilter2.js +++ b/django/contrib/admin/static/admin/js/SelectFilter2.js @@ -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; }, diff --git a/django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js b/django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js index f04dbc51bf9..6470d0fbf61 100644 --- a/django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js +++ b/django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js @@ -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'; diff --git a/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js b/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js index 4f507be4b2c..74298048fa6 100644 --- a/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js +++ b/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js @@ -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; diff --git a/django/contrib/admin/static/admin/js/core.js b/django/contrib/admin/static/admin/js/core.js index a90d185d7af..f575b2c186b 100644 --- a/django/contrib/admin/static/admin/js/core.js +++ b/django/contrib/admin/static/admin/js/core.js @@ -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; diff --git a/js_tests/admin/RelatedObjectLookups.test.js b/js_tests/admin/RelatedObjectLookups.test.js deleted file mode 100644 index 8585e9ada3e..00000000000 --- a/js_tests/admin/RelatedObjectLookups.test.js +++ /dev/null @@ -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'); -}); diff --git a/js_tests/tests.html b/js_tests/tests.html index 0bce71ab29c..c247abc755d 100644 --- a/js_tests/tests.html +++ b/js_tests/tests.html @@ -90,7 +90,6 @@ -