Move openBanWindow to its own separate file

It is now shared between the admin view and the inline view.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2022-06-23 22:58:31 -07:00
parent 4c5d8cee2a
commit 024f0c1290
5 changed files with 26 additions and 21 deletions

View File

@@ -1,25 +1,8 @@
function openBanWindow(e, postElement) {
e.preventDefault();
let banUrl = $(postElement).attr("data-ban-url");
if (window.top.banWindow) {
window.top.banWindow.close();
}
window.top.banWindow = new WinBox("New ban", {
url: banUrl,
x: "center",
y: "center",
root: document.body,
onclose: function (force) {
window.top.banWindow = null;
}
});
}
if (typeof window.menuItemFactories !== "undefined") {
window.menuItemFactories.push(
(postElement) => $("<a>")
.text("Ban")
.attr("href", "#")
.on("click", (e) => { return openBanWindow(e, postElement); })
.on("click", (e) => { openBanWindow(e, $(postElement).attr("data-ban-url")); })
)
}

View File

@@ -0,0 +1,18 @@
function openBanWindow(e, banUrl) {
e.preventDefault();
if (window.top.banWindow) {
window.top.banWindow.close();
}
window.top.banWindow = new WinBox("New ban", {
class: ["nobuttons"],
url: banUrl,
x: "center",
y: "center",
width: 475,
height: 475,
root: document.body,
onclose: function (force) {
window.top.banWindow = null;
}
});
}

View File

@@ -87,5 +87,5 @@ window.menuItemFactories.push(
$("<a>")
.text("Report")
.attr("href", "#")
.on("click", (e) => { return openReportWindow(e, postElement); })
.on("click", (e) => { openReportWindow(e, postElement); })
);

View File

@@ -32,13 +32,15 @@
{{block.super}}
<script src="{% static 'board/jquery.js' %}"></script>
<script src="{% static 'board/winbox.bundle.js' %}"></script>
<script src="{% static 'board/ban_window.js' %}"></script>
{% endblock extrahead %}
{% block footer %}
{{block.super}}
<script>
function openBanWindow(e) {
/*
function openBanWindow(e, banUrl) {
e.preventDefault();
let banUrl = e.target.getAttribute("data-ban-url");
if (window.banWindow) {
@@ -55,12 +57,13 @@ function openBanWindow(e) {
}
});
}
*/
function onLoad(e) {
window.banWindow = null;
}
$(".ban_link").on("click", openBanWindow);
$(".ban_link").on("click", (e) => { openBanWindow(e, $(e.target).attr("data-ban-url")); });
$(window).on("load", onLoad);
</script>
{% endblock %}

View File

@@ -12,6 +12,7 @@
<script src="{% static 'board/winbox.bundle.js' %}"></script>
<script src="{% static 'board/post.js' %}"></script>
{% if perms.board.create_ban %}
<script src="{% static 'board/ban_window.js' %}"></script>
<script src="{% static 'board/ban_menu.js' %}"></script>
{% endif %}
{% block extrajs %}{% endblock %}