From e062d9c9ddb72ea34f2a41d0b9c1dec8ef70fb7f Mon Sep 17 00:00:00 2001 From: Peter Keating Date: Fri, 20 Jan 2023 17:19:49 +0000 Subject: [PATCH] Fix issues caused by upgrade to Bootstrap v5 Fixes #54. --- Views/GalleryPart.Edit.cshtml | 21 +++++++++---------- .../galleryEditor/sources/helpers/modal.ts | 16 +++++++------- .../sources/helpers/selectors.ts | 4 ++-- .../sources/mediaPicker/index.ts | 10 +++++++-- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/Views/GalleryPart.Edit.cshtml b/Views/GalleryPart.Edit.cshtml index 660110c..896edbc 100644 --- a/Views/GalleryPart.Edit.cshtml +++ b/Views/GalleryPart.Edit.cshtml @@ -1,4 +1,5 @@ -@using Etch.OrchardCore.Gallery.ViewModels; +@using Etch.OrchardCore.Gallery.ViewModels; + @model GalleryPartEditViewModel @@ -11,13 +12,13 @@ initializeGalleryEditor(document.getElementById('@Html.IdFor(m => m)')); - \ No newline at end of file + diff --git a/assets/js/admin/components/galleryEditor/sources/helpers/modal.ts b/assets/js/admin/components/galleryEditor/sources/helpers/modal.ts index 168b891..3864987 100644 --- a/assets/js/admin/components/galleryEditor/sources/helpers/modal.ts +++ b/assets/js/admin/components/galleryEditor/sources/helpers/modal.ts @@ -1,3 +1,4 @@ +import bootstrap from 'bootstrap'; import selectors from './selectors'; export interface IShowModalOptions { @@ -7,16 +8,16 @@ export interface IShowModalOptions { onComplete: () => Promise; } -export const hide = (modal: JQuery | null) => { +export const hide = (modal: bootstrap.Modal | null) => { if (modal !== null) { - modal.modal('hide'); + modal.hide(); } }; export const show = ($modal: JQuery, options: IShowModalOptions) => { const $cancelButtons = $modal.find(selectors.modalCancelButton); const $okButton = $modal.find(selectors.modalSubmitButton).first(); - let modal: JQuery | null = null; + const modal = new bootstrap.Modal($modal[0]); $modal.find(selectors.modalDialog).removeClass('media-modal'); @@ -26,22 +27,21 @@ export const show = ($modal: JQuery, options: IShowModalOptions) => { $cancelButtons.each((index: number) => { const $cancelButton = $($cancelButtons[index]); $cancelButton.off('click').on('click', () => { - hide(modal); + modal.hide(); }); }); $okButton.off('click').on('click', () => { if (!options.onComplete) { - hide(modal); + modal.hide(); } options.onComplete().then((isSuccess: Boolean) => { if (isSuccess) { - hide(modal); + modal.hide(); } }); }); - $modal.show(); - modal = $modal.modal(); + modal.show(); }; diff --git a/assets/js/admin/components/galleryEditor/sources/helpers/selectors.ts b/assets/js/admin/components/galleryEditor/sources/helpers/selectors.ts index 059a769..9394c52 100644 --- a/assets/js/admin/components/galleryEditor/sources/helpers/selectors.ts +++ b/assets/js/admin/components/galleryEditor/sources/helpers/selectors.ts @@ -1,8 +1,8 @@ export default { mediaApp: '#mediaApp', modalBody: '.modal-body', - modalCancelButton: 'button[data-dismiss="modal"]', + modalCancelButton: 'button[data-bs-dismiss="modal"]', modalDialog: '.modal-dialog', - modalSubmitButton: 'button[data-accept="modal"]', + modalSubmitButton: 'button[data-bs-accept="modal"]', modalTitle: '.modal-title', }; diff --git a/assets/js/admin/components/galleryEditor/sources/mediaPicker/index.ts b/assets/js/admin/components/galleryEditor/sources/mediaPicker/index.ts index 948bc2c..9b7540e 100644 --- a/assets/js/admin/components/galleryEditor/sources/mediaPicker/index.ts +++ b/assets/js/admin/components/galleryEditor/sources/mediaPicker/index.ts @@ -1,3 +1,4 @@ +import bootstrap from 'bootstrap'; import { EnumGalleryItemType, GalleryItemType, @@ -32,12 +33,17 @@ export default (id: string): IGallerySource => { $(selectors.mediaApp).show(); - const modal = $modal.modal(); + const modal = new bootstrap.Modal($modal[0]); + modal.show(); + + window.console.log($modal.find(selectors.modalSubmitButton)); $modal .find(selectors.modalSubmitButton) .off('click') .on('click', async () => { + window.console.log('here?!?'); + if (window.mediaApp.selectedMedias.length) { let items: IGalleryItem[] = []; let isValidImage = true; @@ -72,7 +78,7 @@ export default (id: string): IGallerySource => { window.mediaApp.selectedMedias = []; - modal.modal('hide'); + modal.hide(); return true; }); };