From 3f7b1e54e90246db3241656f0500c746b37742d7 Mon Sep 17 00:00:00 2001 From: Fabio Caccamo Date: Wed, 24 Oct 2018 17:27:42 +0200 Subject: [PATCH] Fixed #42 - Related modal does not dismiss on popup response. --- admin_interface/static/admin/js/cancel.js | 38 +++++++++++-------- .../static/admin/js/popup_response.js | 6 +-- .../related-modal/related-modal.js | 3 +- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/admin_interface/static/admin/js/cancel.js b/admin_interface/static/admin/js/cancel.js index 830942b..cfd8b86 100644 --- a/admin_interface/static/admin/js/cancel.js +++ b/admin_interface/static/admin/js/cancel.js @@ -1,16 +1,24 @@ -(function($) { - 'use strict'; - $(function() { - $('.cancel-link').click(function(e) { - e.preventDefault(); - var parentWindow = window.parent; - if (parentWindow && typeof(parentWindow.dismissRelatedObjectModal) === 'function') { - parentWindow.dismissRelatedObjectModal(); - } else { - // fallback to default behavior - history.back(); - } - return false; +if (typeof(django) !== 'undefined' && typeof(django.jQuery) !== 'undefined') +{ + (function($) { + + 'use strict'; + + $(document).ready(function() { + + $('.cancel-link').click(function(e) { + e.preventDefault(); + var parentWindow = window.parent; + if (parentWindow && typeof(parentWindow.dismissRelatedObjectModal) === 'function') { + parentWindow.dismissRelatedObjectModal(); + } else { + // fallback to default behavior + history.back(); + } + return false; + }); + }); - }); -})(django.jQuery); \ No newline at end of file + + })(django.jQuery); +} \ No newline at end of file diff --git a/admin_interface/static/admin/js/popup_response.js b/admin_interface/static/admin/js/popup_response.js index 8d3d018..5c498f6 100644 --- a/admin_interface/static/admin/js/popup_response.js +++ b/admin_interface/static/admin/js/popup_response.js @@ -1,5 +1,5 @@ -/* global opener */ -(function($) { +(function() { + 'use strict'; function getModalWindowData() @@ -48,5 +48,5 @@ } break; } -})(django.jQuery); +})(); \ No newline at end of file diff --git a/admin_interface/static/admin_interface/related-modal/related-modal.js b/admin_interface/static/admin_interface/related-modal/related-modal.js index 5118b5c..2d5fbd9 100644 --- a/admin_interface/static/admin_interface/related-modal/related-modal.js +++ b/admin_interface/static/admin_interface/related-modal/related-modal.js @@ -129,5 +129,4 @@ if (typeof(django) !== 'undefined' && typeof(django.jQuery) !== 'undefined') }); })(django.jQuery); -} - +} \ No newline at end of file