mirror of
https://github.com/aljazceru/CTFd.git
synced 2026-02-23 15:14:49 +01:00
Squashed 'CTFd/themes/core-beta/' changes from 9126d77d..5ce3003b
5ce3003b Merge pull request #47 from aCursedComrade/patch-1 c9887cb1 Fix team template git-subtree-dir: CTFd/themes/core-beta git-subtree-split: 5ce3003b4d68352e629ee2d390bc999e7d6b071e
This commit is contained in:
23
assets/js/utils/notifications/alerts.js
Normal file
23
assets/js/utils/notifications/alerts.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import Alpine from "alpinejs";
|
||||
import { Modal } from "bootstrap";
|
||||
|
||||
import CTFd from "../../index";
|
||||
|
||||
export default () => {
|
||||
Alpine.store("modal", { title: "", html: "" });
|
||||
|
||||
CTFd._functions.events.eventAlert = data => {
|
||||
Alpine.store("modal", data);
|
||||
let modal = new Modal(document.querySelector("[x-ref='modal']"));
|
||||
// TODO: Get rid of this private attribute access
|
||||
// See https://github.com/twbs/bootstrap/issues/31266
|
||||
modal._element.addEventListener(
|
||||
"hidden.bs.modal",
|
||||
event => {
|
||||
CTFd._functions.events.eventRead(data.id);
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
modal.show();
|
||||
};
|
||||
};
|
||||
19
assets/js/utils/notifications/read.js
Normal file
19
assets/js/utils/notifications/read.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import Alpine from "alpinejs";
|
||||
import CTFd from "../../index";
|
||||
|
||||
export default () => {
|
||||
CTFd._functions.events.eventCount = count => {
|
||||
Alpine.store("unread_count", count);
|
||||
};
|
||||
|
||||
CTFd._functions.events.eventRead = eventId => {
|
||||
CTFd.events.counter.read.add(eventId);
|
||||
let count = CTFd.events.counter.unread.getAll().length;
|
||||
CTFd.events.controller.broadcast("counter", { count: count });
|
||||
Alpine.store("unread_count", count);
|
||||
};
|
||||
|
||||
document.addEventListener("alpine:init", () => {
|
||||
CTFd._functions.events.eventCount(CTFd.events.counter.unread.getAll().length);
|
||||
});
|
||||
};
|
||||
28
assets/js/utils/notifications/toasts.js
Normal file
28
assets/js/utils/notifications/toasts.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import Alpine from "alpinejs";
|
||||
import { Toast } from "bootstrap";
|
||||
import CTFd from "../../index";
|
||||
|
||||
export default () => {
|
||||
Alpine.store("toast", { title: "", html: "" });
|
||||
|
||||
CTFd._functions.events.eventToast = data => {
|
||||
Alpine.store("toast", data);
|
||||
let toast = new Toast(document.querySelector("[x-ref='toast']"));
|
||||
// TODO: Get rid of this private attribute access
|
||||
// See https://github.com/twbs/bootstrap/issues/31266
|
||||
let close = toast._element.querySelector("[data-bs-dismiss='toast']");
|
||||
let handler = event => {
|
||||
CTFd._functions.events.eventRead(data.id);
|
||||
};
|
||||
close.addEventListener("click", handler, { once: true });
|
||||
toast._element.addEventListener(
|
||||
"hidden.bs.toast",
|
||||
event => {
|
||||
close.removeEventListener("click", handler);
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
|
||||
toast.show();
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user