/
admin-add_module.es6.js
77 lines (63 loc) · 2.33 KB
/
admin-add_module.es6.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
Joomla = window.Joomla || {};
((document) => {
'use strict';
document.addEventListener('DOMContentLoaded', () => {
window.jSelectModuleType = () => {
const elements = document.querySelectorAll('#moduleDashboardAddModal .modal-footer .btn.hidden');
if (elements.length) {
setTimeout(() => {
elements.forEach((button) => {
button.classList.remove('hidden');
});
}, 1000);
}
};
const buttons = document.querySelectorAll('#moduleDashboardAddModal .modal-footer .btn');
const hideButtons = [];
let isSaving = false;
if (buttons.length) {
buttons.forEach((button) => {
if (button.classList.contains('hidden')) {
hideButtons.push(button);
}
button.addEventListener('click', (event) => {
let elem = event.currentTarget;
// There is some bug with events in iframe where currentTarget is "null"
// => prevent this here by bubble up
if (!elem) {
elem = event.target;
}
if (elem) {
const clickTarget = elem.getAttribute('data-target');
// We remember to be in the saving process
isSaving = clickTarget === '#saveBtn';
// Reset saving process, if e.g. the validation of the form fails
setTimeout(() => { isSaving = false; }, 1500);
const iframe = document.querySelector('#moduleDashboardAddModal iframe');
const content = iframe.contentDocument || iframe.contentWindow.document;
const targetBtn = content.querySelector(clickTarget);
if (targetBtn) {
targetBtn.click();
}
}
});
});
}
// @TODO remove jQuery dependency, when the modal is not bootstrap anymore
/* global jQuery */
jQuery('#moduleDashboardAddModal').on('hide.bs.modal', () => {
hideButtons.forEach((button) => {
button.classList.add('hidden');
});
});
jQuery('#moduleDashboardAddModal').on('hidden.bs.modal', () => {
if (isSaving) {
setTimeout(() => { window.parent.location.reload(); }, 1000);
}
});
});
})(document);