From be648d1c457a13af27bc310568c95ab6f08610dd Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sun, 15 Mar 2020 16:28:47 -0700 Subject: [PATCH] Fixed #31391 -- Removed jQuery usage in cancel.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now that cancel.js has no dependencies, it can be loaded asynchronously. Co-Authored-By: François Freitag --- .../contrib/admin/static/admin/js/cancel.js | 26 +++++++++++++++---- .../templates/admin/delete_confirmation.html | 2 +- .../admin/delete_selected_confirmation.html | 2 +- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/django/contrib/admin/static/admin/js/cancel.js b/django/contrib/admin/static/admin/js/cancel.js index 8809ee773f..fdf7495970 100644 --- a/django/contrib/admin/static/admin/js/cancel.js +++ b/django/contrib/admin/static/admin/js/cancel.js @@ -1,13 +1,29 @@ -(function($) { +(function() { 'use strict'; - $(function() { - $('.cancel-link').on('click', function(e) { - e.preventDefault(); + + // Call function fn when the DOM is loaded and ready. If it is already + // loaded, call the function now. + // http://youmightnotneedjquery.com/#ready + function ready(fn) { + if (document.readyState !== 'loading') { + fn(); + } else { + document.addEventListener('DOMContentLoaded', fn); + } + } + + ready(function() { + function handleClick(event) { + event.preventDefault(); if (window.location.search.indexOf('&_popup=1') === -1) { window.history.back(); // Go back if not a popup. } else { window.close(); // Otherwise, close the popup. } + } + + document.querySelectorAll('.cancel-link').forEach(function(el) { + el.addEventListener('click', handleClick); }); }); -})(django.jQuery); +})(); diff --git a/django/contrib/admin/templates/admin/delete_confirmation.html b/django/contrib/admin/templates/admin/delete_confirmation.html index bfece58ada..d4c9b295a1 100644 --- a/django/contrib/admin/templates/admin/delete_confirmation.html +++ b/django/contrib/admin/templates/admin/delete_confirmation.html @@ -4,7 +4,7 @@ {% block extrahead %} {{ block.super }} {{ media }} - + {% endblock %} {% block bodyclass %}{{ block.super }} app-{{ opts.app_label }} model-{{ opts.model_name }} delete-confirmation{% endblock %} diff --git a/django/contrib/admin/templates/admin/delete_selected_confirmation.html b/django/contrib/admin/templates/admin/delete_selected_confirmation.html index 346d280738..a49b6adeeb 100644 --- a/django/contrib/admin/templates/admin/delete_selected_confirmation.html +++ b/django/contrib/admin/templates/admin/delete_selected_confirmation.html @@ -4,7 +4,7 @@ {% block extrahead %} {{ block.super }} {{ media }} - + {% endblock %} {% block bodyclass %}{{ block.super }} app-{{ opts.app_label }} model-{{ opts.model_name }} delete-confirmation delete-selected-confirmation{% endblock %}