From 0f2885e3f6e0c73c9f455dcbc0326ac11ba4b84c Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Tue, 21 Apr 2020 21:13:58 -0700 Subject: [PATCH] Simplified collapse.js with Element.closest(). --- django/contrib/admin/static/admin/js/collapse.js | 12 +----------- django/contrib/admin/static/admin/js/collapse.min.js | 5 ++--- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/django/contrib/admin/static/admin/js/collapse.js b/django/contrib/admin/static/admin/js/collapse.js index 3f012a5b47..1d8f602d40 100644 --- a/django/contrib/admin/static/admin/js/collapse.js +++ b/django/contrib/admin/static/admin/js/collapse.js @@ -1,16 +1,6 @@ /*global gettext*/ (function() { 'use strict'; - var closestElem = function(elem, tagName) { - if (elem.nodeName === tagName.toUpperCase()) { - return elem; - } - if (elem.parentNode.nodeName === 'BODY') { - return null; - } - return elem.parentNode && closestElem(elem.parentNode, tagName); - }; - window.addEventListener('load', function() { // Add anchor tag for Show/Hide link var fieldsets = document.querySelectorAll('fieldset.collapse'); @@ -35,7 +25,7 @@ if (ev.target.matches('.collapse-toggle')) { ev.preventDefault(); ev.stopPropagation(); - var fieldset = closestElem(ev.target, 'fieldset'); + var fieldset = ev.target.closest('fieldset'); if (fieldset.classList.contains('collapsed')) { // Show ev.target.textContent = gettext('Hide'); diff --git a/django/contrib/admin/static/admin/js/collapse.min.js b/django/contrib/admin/static/admin/js/collapse.min.js index 33a93573bd..67b2d21335 100644 --- a/django/contrib/admin/static/admin/js/collapse.min.js +++ b/django/contrib/admin/static/admin/js/collapse.min.js @@ -1,3 +1,2 @@ -(function(){var e=function(b,a){return b.nodeName===a.toUpperCase()?b:"BODY"===b.parentNode.nodeName?null:b.parentNode&&e(b.parentNode,a)};window.addEventListener("load",function(){for(var b=document.querySelectorAll("fieldset.collapse"),a=0;a