|
1 | 1 | // src/app.ts |
2 | 2 | import { AlertAdaptation, DropdownAdaptation, FavouritesAdaptation, TabAdaptation, TableAdaptation } from './adaptations'; |
3 | | -import { Autocomplete, Toast as CmfiveToast, CodeMirror, InputWithOther, MultiFileUpload, Overlay, QuillEditor, Tags, TabbedPagination } from './components'; |
| 3 | +import { Autocomplete, Toast as CmfiveToast, CodeMirror, InputWithOther, MultiFileUpload, Overlay, QuillEditor, TabbedPagination, Tags } from './components'; |
4 | 4 |
|
5 | 5 | import { Modal, Tooltip } from 'bootstrap'; |
6 | 6 | import { Sortable } from './components/Sortable'; |
@@ -86,26 +86,32 @@ export class Cmfive { |
86 | 86 | } |
87 | 87 |
|
88 | 88 | static openModal(url: string, target: string = '#cmfive-modal') { |
89 | | - Cmfive.currentModal = new Modal(document.getElementById('cmfive-modal')) //, options |
| 89 | + const controller = new AbortController(); |
| 90 | + |
| 91 | + const container = document.getElementById('cmfive-modal'); |
| 92 | + Cmfive.currentModal = new Modal(container) //, options |
90 | 93 |
|
91 | 94 | let modalContent = document.querySelector(target + ' .modal-content'); |
92 | 95 | if (modalContent) { |
93 | 96 | modalContent.innerHTML = '<button type="button" class="btn-close" data-bs-dismiss="modal" data-bs-target="' + target + '" aria-label="Close"></button>'; |
94 | 97 | } |
| 98 | + |
| 99 | + container.addEventListener("hide.bs.modal", () => controller.abort()); |
95 | 100 |
|
96 | 101 | Cmfive.currentModal.show(); |
97 | 102 | fetch(url, { |
98 | 103 | headers: { |
99 | 104 | 'Content-Type': 'application/json' |
100 | | - } |
| 105 | + }, |
| 106 | + signal: controller.signal, |
101 | 107 | }).then((response) => { |
102 | 108 | return response.text() |
103 | 109 | }).then((content) => { |
104 | 110 | modalContent.innerHTML = content + modalContent.innerHTML; |
105 | 111 |
|
106 | 112 | // https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML#security_considerations |
107 | 113 | // Appending scripts to the DOM via innerHTML is not meant to execute them for security purposes |
108 | | - // Unfortunately, various modals however contian script tags we need to execute |
| 114 | + // Unfortunately, various modals however contain script tags we need to execute |
109 | 115 | modalContent.querySelectorAll("script").forEach(x => { |
110 | 116 | eval(x.innerHTML); |
111 | 117 | }); |
|
0 commit comments