mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
59 lines
1.5 KiB
JavaScript
59 lines
1.5 KiB
JavaScript
import { DeleteModal } from "./components/DeleteModal.js";
|
|
|
|
export function initDeleteModal({
|
|
app = null,
|
|
deleteModalOverride = null,
|
|
container = null,
|
|
utilities = {},
|
|
callbacks = {},
|
|
eventTarget = null,
|
|
} = {}) {
|
|
const events = eventTarget instanceof EventTarget ? eventTarget : new EventTarget();
|
|
|
|
const {
|
|
removeTrackingScripts: removeTrackingScriptsFn = null,
|
|
setGlobalModalState: setGlobalModalStateFn = null,
|
|
truncateMiddle = null,
|
|
} = utilities;
|
|
|
|
const {
|
|
onConfirm = null,
|
|
onCancel = null,
|
|
} = callbacks;
|
|
|
|
const modal =
|
|
(typeof deleteModalOverride === "function"
|
|
? deleteModalOverride({ app, eventTarget: events })
|
|
: deleteModalOverride) ||
|
|
new DeleteModal({
|
|
removeTrackingScripts: removeTrackingScriptsFn,
|
|
setGlobalModalState: setGlobalModalStateFn,
|
|
truncateMiddle,
|
|
container,
|
|
eventTarget: events,
|
|
});
|
|
|
|
const boundConfirmHandler =
|
|
typeof onConfirm === "function" ? (event) => onConfirm(event) : null;
|
|
const boundCancelHandler = typeof onCancel === "function" ? () => onCancel() : null;
|
|
|
|
if (boundConfirmHandler && typeof modal?.addEventListener === "function") {
|
|
modal.addEventListener("video:delete-confirm", boundConfirmHandler);
|
|
}
|
|
|
|
if (boundCancelHandler && typeof modal?.addEventListener === "function") {
|
|
modal.addEventListener("video:delete-cancel", boundCancelHandler);
|
|
}
|
|
|
|
return {
|
|
modal,
|
|
events,
|
|
handlers: {
|
|
confirm: boundConfirmHandler,
|
|
cancel: boundCancelHandler,
|
|
},
|
|
};
|
|
}
|
|
|
|
export default initDeleteModal;
|