frayerjj-frontend 0.2.13 → 0.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/modal.js +21 -16
package/package.json
CHANGED
package/src/modal.js
CHANGED
|
@@ -23,14 +23,15 @@ export const modal = {
|
|
|
23
23
|
buttons = [{ text: 'OK' }];
|
|
24
24
|
else
|
|
25
25
|
buttons = [{ text: 'Save', class: 'btn-save' }, { text: 'Cancel' }];
|
|
26
|
+
let id = modal.randomId(el.getAttribute('data-bs-target').substring(1));
|
|
26
27
|
modal.show({
|
|
27
|
-
id:
|
|
28
|
+
id: id,
|
|
28
29
|
title: el.getAttribute('modal-title'),
|
|
29
30
|
body: '',
|
|
30
31
|
class: (el.getAttribute('modal-class') ?? ''),
|
|
31
32
|
buttons: buttons
|
|
32
33
|
});
|
|
33
|
-
let ajaxModal = document.
|
|
34
|
+
let ajaxModal = document.getElementById(id),
|
|
34
35
|
bsAjaxModal = bootstrap.Modal.getOrCreateInstance(ajaxModal),
|
|
35
36
|
ajaxModalBody = ajaxModal.querySelector('.modal-body');
|
|
36
37
|
ajaxModal.addEventListener('hidden.bs.modal', ev => {
|
|
@@ -97,7 +98,8 @@ export const modal = {
|
|
|
97
98
|
|
|
98
99
|
alert: (msg, title = "Alert", button = "OK") => {
|
|
99
100
|
message.verbose('Building Alert Modal');
|
|
100
|
-
|
|
101
|
+
let id = modal.randomId();
|
|
102
|
+
modal.show({ id: id, title, body: `<p>${msg}</p>`, buttons: [{ text: button }] });
|
|
101
103
|
},
|
|
102
104
|
|
|
103
105
|
build: {
|
|
@@ -258,8 +260,9 @@ export const modal = {
|
|
|
258
260
|
|
|
259
261
|
confirm: (msg, onConfirm, onCancel, title = "Are you sure?", buttonYes = "Yes", buttonNo = "No") => {
|
|
260
262
|
message.verbose('Building Confirm Modal');
|
|
263
|
+
let id = modal.randomId();
|
|
261
264
|
modal.show({
|
|
262
|
-
id:
|
|
265
|
+
id: id,
|
|
263
266
|
title,
|
|
264
267
|
body: `<p>${msg}</p>`,
|
|
265
268
|
buttons: [
|
|
@@ -271,22 +274,24 @@ export const modal = {
|
|
|
271
274
|
});
|
|
272
275
|
},
|
|
273
276
|
|
|
277
|
+
randomId: (base = 'modal') => {
|
|
278
|
+
return `${base}-${Date.now()}-${Math.random().toString(36).substr(2, 5)}`;
|
|
279
|
+
},
|
|
280
|
+
|
|
274
281
|
show: config => {
|
|
275
282
|
modal.close();
|
|
276
283
|
message.verbose('Showing Modal');
|
|
277
284
|
document.body.appendChild(modal.build.modal(config));
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
button.
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
bsModal.show();
|
|
289
|
-
}, 100); // Delay to allow DOM to update
|
|
285
|
+
let modalEl = document.getElementById(config.id);
|
|
286
|
+
let bsModal = new bootstrap.Modal(modalEl);
|
|
287
|
+
modalEl.addEventListener('hidden.bs.modal', () => modalEl.remove());
|
|
288
|
+
modalEl.querySelectorAll('[data-action]').forEach(button =>
|
|
289
|
+
button.addEventListener('click', () => {
|
|
290
|
+
if (config[button.dataset.action]) config[button.dataset.action]();
|
|
291
|
+
bsModal.hide();
|
|
292
|
+
})
|
|
293
|
+
);
|
|
294
|
+
bsModal.show();
|
|
290
295
|
}
|
|
291
296
|
|
|
292
297
|
};
|