8000 fix: Remove need for timeout to close modal (#8183) · django-cms/django-cms@c37fa0b · GitHub
[go: up one dir, main page]

Skip to content

Commit c37fa0b

Browse files
authored
fix: Remove need for timeout to close modal (#8183)
* Remove need for timeout to close modal * remove unneded template tags * Fix js linting * Add try catch
1 parent 2a3712c commit c37fa0b

File tree

3 files changed

+18
-25
lines changed

3 files changed

+18
-25
lines changed

cms/static/cms/js/admin.base.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,3 @@ const CMS = {
1818
// in case some data is already attached to the global CMS
1919
// we must not override it
2020
window.CMS = CMS.$.extend(window.CMS || {}, CMS);
21-
22-
// Serve the data bridge:
23-
// We have a special case here cause the CMS namespace
24-
// can be either inside the current window or the parent
25-
if (document.querySelector('body.cms-close-frame script#data-bridge')) {
26-
(function (Window) {
27-
// the dataBridge is used to access plugin information from different resources
28-
// Do NOT move this!!!
29-
Window.CMS.API.Helpers.dataBridge = JSON.parse(document.getElementById('data-bridge').textContent);
30-
// make sure we're doing after the "modal" mechanism kicked in
31-
setTimeout(function () {
32-
// save current plugin
33-
Window.CMS.API.Helpers.onPluginSave();
34-
}, 100); // eslint-disable-line no-magic-numbers
35-
})(window.parent || window);
36-
}
37-

cms/static/cms/js/modules/cms.modal.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,12 +1006,25 @@ class Modal {
10061006
true
10071007
);
10081008
} else {
1009-
setTimeout(function() {
1009+
// Serve the data bridge:
1010+
// We have a special case here cause the CMS namespace
1011+
// can be either inside the current window or the parent
1012+
const dataBridge = body[0].querySelector('script#data-bridge');
1013+
1014+
if (dataBridge) {
10101015
// hello ckeditor
10111016
Helpers.removeEventListener('modal-close.text-plugin');
10121017
that.close();
1013-
// must be more than 100ms
1014-
}, 150); // eslint-disable-line
1018+
// the dataBridge is used to access plugin information from different resources
1019+
// Do NOT move this!!!
1020+
try {
1021+
CMS.API.Helpers.dataBridge = JSON.parse(dataBridge.textContent);
1022+
CMS.API.Helpers.onPluginSave();
1023+
} catch (e) {
1024+
// istanbul ignore next
1025+
Helpers.reloadBrowser();
1026+
}
1027+
}
10151028
}
10161029
} else {
10171030
if (that.ui.modal.hasClass('cms-modal-open')) {
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
{% load i18n l10n static cms_static %}{% spaceless %}
1+
{% spaceless %}
22
<!DOCTYPE html><html>
33
<body class="cms-close-frame">
44
{# trick for cms to understand that the plugin was actually correctly saved #}
55
<div class="messagelist">
66
<div class="success"></div>
77
</div>
8-
{% if data_bridge %}
9-
{{ data_bridge|json_script:"data-bridge" }}
10-
<script src="{% static_with_version "cms/js/dist/bundle.admin.base.min.js" %}" type="text/javascript"></script>
11-
{% endif %}
8+
{% if data_bridge %}{{ data_bridge|json_script:"data-bridge" }}{% endif %}
129
</body>
1310
</html>
1411
{% endspaceless %}

0 commit comments

Comments
 (0)
0