frayerjj-frontend 0.2.13 → 0.2.26
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 +44 -34
package/package.json
CHANGED
package/src/modal.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Modal } from 'bootstrap';
|
|
2
2
|
import { ajax } from './ajax.js';
|
|
3
3
|
import { message } from './message.js';
|
|
4
4
|
|
|
@@ -23,19 +23,20 @@ export const modal = {
|
|
|
23
23
|
buttons = [{ text: 'OK' }];
|
|
24
24
|
else
|
|
25
25
|
buttons = [{ text: 'Save', class: 'btn-save' }, { text: 'Cancel' }];
|
|
26
|
-
modal.
|
|
27
|
-
|
|
26
|
+
let randomId = modal.randomId('ajax');
|
|
27
|
+
document.querySelector('body').insertAdjacentHTML('beforeend', modal.build.modal({
|
|
28
|
+
id: randomId,
|
|
28
29
|
title: el.getAttribute('modal-title'),
|
|
29
30
|
body: '',
|
|
30
31
|
class: (el.getAttribute('modal-class') ?? ''),
|
|
31
32
|
buttons: buttons
|
|
32
|
-
});
|
|
33
|
-
let ajaxModal = document.
|
|
34
|
-
bsAjaxModal = bootstrap.Modal.getOrCreateInstance(ajaxModal),
|
|
33
|
+
}));
|
|
34
|
+
let ajaxModal = document.getElementById(randomId),
|
|
35
35
|
ajaxModalBody = ajaxModal.querySelector('.modal-body');
|
|
36
36
|
ajaxModal.addEventListener('hidden.bs.modal', ev => {
|
|
37
37
|
ev.target.remove();
|
|
38
38
|
});
|
|
39
|
+
let bsAjaxModal = Modal.getOrCreateInstance(ajaxModal);
|
|
39
40
|
bsAjaxModal.show();
|
|
40
41
|
loading.start(1, ajaxModalBody);
|
|
41
42
|
message.verbose('Loading AJAX Modal');
|
|
@@ -97,7 +98,20 @@ export const modal = {
|
|
|
97
98
|
|
|
98
99
|
alert: (msg, title = "Alert", button = "OK") => {
|
|
99
100
|
message.verbose('Building Alert Modal');
|
|
100
|
-
modal.
|
|
101
|
+
let randomId = modal.randomId('confirm');
|
|
102
|
+
document.querySelector('body').insertAdjacentHTML('beforeend', modal.build.modal({
|
|
103
|
+
id: randomId,
|
|
104
|
+
title: title,
|
|
105
|
+
body: '<p>' + msg + '</p>',
|
|
106
|
+
buttons: [ { text: button } ]
|
|
107
|
+
}));
|
|
108
|
+
let alertModal = document.getElementById(randomId),
|
|
109
|
+
bsAlertModal = Modal.getOrCreateInstance(alertModal);
|
|
110
|
+
alertModal.addEventListener('hidden.bs.modal', ev => {
|
|
111
|
+
ev.target.remove();
|
|
112
|
+
});
|
|
113
|
+
modal.close();
|
|
114
|
+
bsAlertModal.show();
|
|
101
115
|
},
|
|
102
116
|
|
|
103
117
|
build: {
|
|
@@ -179,7 +193,6 @@ export const modal = {
|
|
|
179
193
|
modal.setAttribute('tabindex', '-1');
|
|
180
194
|
modal.setAttribute('role', 'dialog');
|
|
181
195
|
modal.setAttribute('aria-labelledby', vars.title);
|
|
182
|
-
modal.setAttribute('aria-hidden', 'true');
|
|
183
196
|
|
|
184
197
|
// Modal dialog
|
|
185
198
|
let modalDialog = document.createElement('div');
|
|
@@ -251,42 +264,39 @@ export const modal = {
|
|
|
251
264
|
close: () => {
|
|
252
265
|
message.verbose('Closing Modals');
|
|
253
266
|
document.querySelectorAll('.modal').forEach(modal => {
|
|
254
|
-
let bsModal =
|
|
267
|
+
let bsModal = Modal.getOrCreateInstance(modal);
|
|
255
268
|
if (bsModal) bsModal.hide();
|
|
256
269
|
});
|
|
257
270
|
},
|
|
258
271
|
|
|
259
272
|
confirm: (msg, onConfirm, onCancel, title = "Are you sure?", buttonYes = "Yes", buttonNo = "No") => {
|
|
260
273
|
message.verbose('Building Confirm Modal');
|
|
261
|
-
modal.
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
274
|
+
let randomId = modal.randomId('confirm');
|
|
275
|
+
document.querySelector('body').insertAdjacentHTML('beforeend', modal.build.modal({
|
|
276
|
+
id: randomId,
|
|
277
|
+
title: title,
|
|
278
|
+
body: '<p>' + msg + '</p>',
|
|
265
279
|
buttons: [
|
|
266
|
-
{ text: buttonYes, class: 'btn-confirm
|
|
267
|
-
{ text: buttonNo, class: 'btn-outline-danger'
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
280
|
+
{ text: buttonYes, class: 'btn-confirm' },
|
|
281
|
+
{ text: buttonNo, class: 'btn-outline-danger' } ]
|
|
282
|
+
}));
|
|
283
|
+
let confirmModal = document.getElementById(randomId),
|
|
284
|
+
bsConfirmModal = Modal.getOrCreateInstance(confirmModal);
|
|
285
|
+
confirmModal.addEventListener('hidden.bs.modal', ev => {
|
|
286
|
+
ev.target.remove();
|
|
287
|
+
});
|
|
288
|
+
confirmModal.querySelector('.btn-confirm').addEventListener('click', () => {
|
|
289
|
+
onConfirm();
|
|
271
290
|
});
|
|
291
|
+
confirmModal.querySelector('.btn-outline-danger').addEventListener('click', () => {
|
|
292
|
+
onCancel();
|
|
293
|
+
});
|
|
294
|
+
modal.close();
|
|
295
|
+
bsConfirmModal.show();
|
|
272
296
|
},
|
|
273
297
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
message.verbose('Showing Modal');
|
|
277
|
-
document.body.appendChild(modal.build.modal(config));
|
|
278
|
-
setTimeout(() => {
|
|
279
|
-
let modalEl = document.getElementById(config.id);
|
|
280
|
-
let bsModal = new bootstrap.Modal(modalEl);
|
|
281
|
-
modalEl.addEventListener('hidden.bs.modal', () => modalEl.remove());
|
|
282
|
-
modalEl.querySelectorAll('[data-action]').forEach(button =>
|
|
283
|
-
button.addEventListener('click', () => {
|
|
284
|
-
if (config[button.dataset.action]) config[button.dataset.action]();
|
|
285
|
-
bsModal.hide();
|
|
286
|
-
})
|
|
287
|
-
);
|
|
288
|
-
bsModal.show();
|
|
289
|
-
}, 100); // Delay to allow DOM to update
|
|
298
|
+
randomId: (base = 'modal') => {
|
|
299
|
+
return `${base}-${Date.now()}-${Math.random().toString(36).slice(2, 5)}`;
|
|
290
300
|
}
|
|
291
301
|
|
|
292
302
|
};
|