diff --git a/app/flatpages/help/wtfpl.md b/app/flatpages/help/wtfpl.md index 6153c57c..008c1669 100644 --- a/app/flatpages/help/wtfpl.md +++ b/app/flatpages/help/wtfpl.md @@ -6,17 +6,17 @@ toc: False Please reconsider the choice of WTFPL as a license. - diff --git a/app/public/static/collection_editor.js b/app/public/static/collection_editor.js index d9569315..8adfba89 100644 --- a/app/public/static/collection_editor.js +++ b/app/public/static/collection_editor.js @@ -1,6 +1,8 @@ // @author rubenwardy // @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later +"use strict"; + function updateOrder() { const elements = [...document.querySelector(".sortable").children]; @@ -33,7 +35,9 @@ function restorePackage(id) { return false; } - const card = idElement.parentNode.parentNode; + const card = idElement.parentNode.parentNode.parentNode.parentNode; + console.assert(card.classList.contains("card")); + card.classList.remove("d-none"); card.querySelector("input[name^=package_removed]").value = "0"; card.scrollIntoView(); @@ -176,7 +180,9 @@ function onPackageQueryUpdate() { window.addEventListener("load", () => { document.querySelectorAll(".remove-package").forEach(button => { - const card = button.parentNode.parentNode; + const card = button.parentNode.parentNode.parentNode.parentNode; + console.assert(card.classList.contains("card")); + const field = card.querySelector("input[name^=package_removed]"); // Reloading/validation errors will cause this to be 1 at load @@ -191,6 +197,12 @@ window.addEventListener("load", () => { addPackageQuery.value = ""; addPackageQuery.classList.remove("d-none"); addPackageQuery.addEventListener("input", onPackageQueryUpdate); + addPackageQuery.addEventListener('keydown',(e)=>{ + if (e.key === "Enter") { + onPackageQueryUpdate(); + e.preventDefault(); + } + }) updateOrder(); $(".sortable").sortable({ diff --git a/app/public/static/markdowntextarea.js b/app/public/static/markdowntextarea.js index 73b36b22..5b970c2e 100644 --- a/app/public/static/markdowntextarea.js +++ b/app/public/static/markdowntextarea.js @@ -1,7 +1,9 @@ // @author rubenwardy // @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later -$("textarea.markdown").each(function() { +"use strict"; + +document.querySelectorAll("textarea.markdown").forEach((element) => { async function render(plainText, preview) { const response = await fetch(new Request("/api/markdown/", { method: "POST", @@ -16,18 +18,8 @@ $("textarea.markdown").each(function() { } let timeout_id = null; - - function urlInserter(url) { - return (editor) => { - var cm = editor.codemirror; - var stat = getState(cm); - var options = editor.options; - _replaceSelection(cm, stat.table, `[](${url})`); - }; - } - - this.easy_mde = new EasyMDE({ - element: this, + element.easy_mde = new EasyMDE({ + element: element, hideIcons: ["image"], showIcons: ["code", "table"], forceSync: true, @@ -49,20 +41,6 @@ $("textarea.markdown").each(function() { "fullscreen", "|", "guide", -// { -// name: "rules", -// className: "fa fa-book", -// title: "others buttons", -// children: [ -// { -// name: "rules", -// action: urlInserter("/policy_and_guidance/#2-accepted-content"), -// className: "fa fa-star", -// title: "2. Accepted content", -// text: "2. Accepted content", -// }, -// ] -// }, ], previewRender: (plainText, preview) => { if (timeout_id) { @@ -70,7 +48,7 @@ $("textarea.markdown").each(function() { } timeout_id = setTimeout(() => { - render(plainText, preview); + render(plainText, preview).catch(console.error); timeout_id = null; }, 500); diff --git a/app/public/static/package_charts.js b/app/public/static/package_charts.js index 6cfb8195..cc063c15 100644 --- a/app/public/static/package_charts.js +++ b/app/public/static/package_charts.js @@ -3,7 +3,6 @@ "use strict"; - const labelColor = "#bbb"; const annotationColor = "#bbb"; const annotationLabelBgColor = "#444"; @@ -304,4 +303,4 @@ function setup_chart(ctx, data, annotations) { } -$(load_data); +window.addEventListener("load", load_data); diff --git a/app/public/static/package_create.js b/app/public/static/package_create.js index ce82fb33..bd3b460d 100644 --- a/app/public/static/package_create.js +++ b/app/public/static/package_create.js @@ -1,36 +1,47 @@ // @author rubenwardy // @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later -$(function() { +"use strict"; + +function hide(sel) { + document.querySelectorAll(sel).forEach(x => x.classList.add("d-none")); +} + +function show(sel) { + document.querySelectorAll(sel).forEach(x => x.classList.remove("d-none")); +} + + +window.addEventListener("load", () => { function finish() { - $(".pkg_wiz_1").hide() - $(".pkg_wiz_2").hide() - $(".pkg_repo").show() - $(".pkg_meta").show() + hide(".pkg_wiz_1"); + hide(".pkg_wiz_2"); + show(".pkg_repo"); + show(".pkg_meta"); } - $(".pkg_meta").hide() - $(".pkg_wiz_1").show() + hide(".pkg_meta"); + show(".pkg_wiz_1"); - $("#pkg_wiz_1_skip").click(finish) - $("#pkg_wiz_1_next").click(function() { - const repoURL = $("#repo").val(); - if (repoURL.trim() != "") { - $(".pkg_wiz_1").hide() - $(".pkg_wiz_2").show() - $(".pkg_repo").hide() + document.getElementById("pkg_wiz_1_skip").addEventListener("click", finish); + document.getElementById("pkg_wiz_1_next").addEventListener("click", () => { + const repoURL = document.getElementById("repo").value; + if (repoURL.trim() !== "") { + hide(".pkg_wiz_1"); + show(".pkg_wiz_2"); + hide(".pkg_repo"); - function setField(id, value) { - if (value && value != "") { - const ele = $(id); - ele.val(value); - ele.trigger("change"); + function setField(sel, value) { + if (value && value !== "") { + const ele = document.querySelector(sel); + ele.value = value; + ele.dispatchEvent(new Event("change")); // EasyMDE doesn't always refresh the codemirror correctly - if (ele[0].easy_mde) { + if (ele.easy_mde) { setTimeout(() => { - ele[0].easy_mde.value(value); - ele[0].easy_mde.codemirror.refresh() + ele.easy_mde.value(value); + ele.easy_mde.codemirror.refresh() }, 100); } } @@ -45,19 +56,19 @@ $(function() { setField("#short_desc", result.short_desc); setField("#forums", result.forums); if (result.type && result.type.length > 2) { - $("#type").val(result.type); + setField("[name='type']", result.type); } finish(); }).catch(function(e) { alert(e); - $(".pkg_wiz_1").show(); - $(".pkg_wiz_2").hide(); - $(".pkg_repo").show(); + show(".pkg_wiz_1"); + hide(".pkg_wiz_2"); + show(".pkg_repo"); // finish() }); } else { - finish() + finish(); } }) }) diff --git a/app/public/static/package_edit.js b/app/public/static/package_edit.js index b52064dc..6eb7b743 100644 --- a/app/public/static/package_edit.js +++ b/app/public/static/package_edit.js @@ -1,20 +1,33 @@ // @author rubenwardy // @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later -$(function() { - $("#type").change(function() { - $(".not_mod, .not_game, .not_txp").show() - $(".not_" + this.value.toLowerCase()).hide() - }) - $(".not_mod, .not_game, .not_txp").show() - $(".not_" + $("#type").val().toLowerCase()).hide() +"use strict"; - $("#forums").on('paste', function(e) { +function hide(sel) { + document.querySelectorAll(sel).forEach(x => x.classList.add("d-none")); +} + +function show(sel) { + document.querySelectorAll(sel).forEach(x => x.classList.remove("d-none")); +} + + +window.addEventListener("load", () => { + const typeEle = document.getElementById("type"); + typeEle.addEventListener("change", () => { + show(".not_mod, .not_game, .not_txp"); + hide(".not_" + typeEle.value.toLowerCase()); + }) + show(".not_mod, .not_game, .not_txp"); + hide(".not_" + typeEle.value.toLowerCase()); + + const forumsField = document.getElementById("forums"); + forumsField.addEventListener("paste", function(e) { try { - const pasteData = e.originalEvent.clipboardData.getData('text'); + const pasteData = e.clipboardData.getData('text'); const url = new URL(pasteData); - if (url.hostname == "forum.minetest.net") { - $(this).val(url.searchParams.get("t")); + if (url.hostname === "forum.minetest.net") { + forumsField.value = url.searchParams.get("t"); e.preventDefault(); } } catch (e) { @@ -22,8 +35,9 @@ $(function() { } }); - $("#forums-button").click(function(e) { - window.open("https://forum.minetest.net/viewtopic.php?t=" + $("#forums").val(), "_blank"); + const openForums = document.getElementById("forums-button"); + openForums.addEventListener("click", () => { + window.open("https://forum.minetest.net/viewtopic.php?t=" + forumsField.value, "_blank"); }); let hint = null; @@ -32,9 +46,13 @@ $(function() { hint.remove(); } - hint = ele.parent() - .append(`
${text}
`) - .find(".alert"); + hint = document.createElement("div"); + hint.classList.add("alert"); + hint.classList.add("alert-warning"); + hint.classList.add("my-1"); + hint.innerHTML = text; + + ele.parentNode.appendChild(hint); } let hint_mtmods = `Tip: @@ -43,26 +61,24 @@ $(function() { let hint_thegame = `Tip: It's obvious that this adds something to Minetest, - there's no need to use phrases such as \"adds X to the game\".` + there's no need to use phrases such as \"adds X to the game\".`; - $("#short_desc").on("change paste keyup", function() { - const val = $(this).val().toLowerCase(); + const shortDescField = document.getElementById("short_desc"); + + function handleShortDescChange() { + const val = shortDescField.value.toLowerCase(); if (val.indexOf("minetest") >= 0 || val.indexOf("mod") >= 0 || val.indexOf("modpack") >= 0 || val.indexOf("mod pack") >= 0) { - showHint($(this), hint_mtmods); + showHint(shortDescField, hint_mtmods); } else if (val.indexOf("the game") >= 0) { - showHint($(this), hint_thegame); + showHint(shortDescField, hint_thegame); } else if (hint) { hint.remove(); hint = null; } - }) + } - const btn = $("#forums").parent().find("label").append("Open"); - btn.click(function() { - const id = $("#forums").val(); - if (/^\d+$/.test(id)) { - window.open("https://forum.minetest.net/viewtopic.php?t=" + id, "_blank"); - } - }); + shortDescField.addEventListener("change", handleShortDescChange); + shortDescField.addEventListener("paste", handleShortDescChange); + shortDescField.addEventListener("keyup", handleShortDescChange); }) diff --git a/app/public/static/polltask.js b/app/public/static/polltask.js index 5d7104f7..a1f62c24 100644 --- a/app/public/static/polltask.js +++ b/app/public/static/polltask.js @@ -1,16 +1,18 @@ // @author rubenwardy // @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later +"use strict"; + function getJSON(url, method) { - return new Promise(function(resolve, reject) { + return new Promise((resolve, reject) => { fetch(new Request(url, { method: method || "get", credentials: "same-origin", headers: { "Accept": "application/json", }, - })).then(function(response) { - response.text().then(function(txt) { + })).then((response) => { + response.text().then((txt) => { resolve(JSON.parse(txt)) }).catch(reject) }).catch(reject) @@ -18,7 +20,7 @@ function getJSON(url, method) { } function pollTask(poll_url, disableTimeout) { - return new Promise(function(resolve, reject) { + return new Promise((resolve, reject) => { let tries = 0; function retry() { @@ -32,11 +34,11 @@ function pollTask(poll_url, disableTimeout) { } } function step() { - getJSON(poll_url).then(function(res) { - if (res.status == "SUCCESS") { + getJSON(poll_url).then((res) => { + if (res.status === "SUCCESS") { console.log("Got result") resolve(res.result) - } else if (res.status == "FAILURE" || res.status == "REVOKED") { + } else if (res.status === "FAILURE" || res.status === "REVOKED") { reject(res.error || "Unknown server error") } else { retry() @@ -49,8 +51,8 @@ function pollTask(poll_url, disableTimeout) { function performTask(url) { - return new Promise(function(resolve, reject) { - getJSON(url, "post").then(function(startResult) { + return new Promise((resolve, reject) => { + getJSON(url, "post").then((startResult) => { console.log(startResult) if (typeof startResult.poll_url == "string") { pollTask(startResult.poll_url).then(resolve).catch(reject) diff --git a/app/public/static/release_bulk_change.js b/app/public/static/release_bulk_change.js new file mode 100644 index 00000000..6a00e8ba --- /dev/null +++ b/app/public/static/release_bulk_change.js @@ -0,0 +1,28 @@ +// @author rubenwardy +// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later + +"use strict"; + +window.addEventListener("load", () => { + function setup_toggle(type) { + const toggle = document.getElementById("set_" + type); + + function on_change() { + const rel = document.getElementById(type + "_rel"); + if (toggle.checked) { + rel.parentElement.style.opacity = "1"; + } else { + // $("#" + type + "_rel").attr("disabled", "disabled"); + rel.parentElement.style.opacity = "0.4"; + rel.value = document.querySelector(`#${type}_rel option:first-child`).value; + rel.dispatchEvent(new Event("change")); + } + } + + toggle.addEventListener("change", on_change); + on_change(); + } + + setup_toggle("min"); + setup_toggle("max"); +}); diff --git a/app/public/static/release_minmax.js b/app/public/static/release_minmax.js index d80a221f..80badc42 100644 --- a/app/public/static/release_minmax.js +++ b/app/public/static/release_minmax.js @@ -1,21 +1,25 @@ // @author rubenwardy // @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later -const min = $("#min_rel"); -const max = $("#max_rel"); -const none = parseInt($("#min_rel option:first-child").attr("value")); -const warning = $("#minmax_warning"); +"use strict"; -function ver_check() { - const minv = parseInt(min.val()); - const maxv = parseInt(max.val()); +window.addEventListener("load", () => { + const min = document.getElementById("min_rel"); + const max = document.getElementById("max_rel"); + const none = parseInt(document.querySelector("#min_rel option:first-child").value); + const warning = document.getElementById("minmax_warning"); - if (minv != none && maxv != none && minv > maxv) { - warning.show(); - } else { - warning.hide(); + function ver_check() { + const minv = parseInt(min.value); + const maxv = parseInt(max.value); + if (minv != none && maxv != none && minv > maxv) { + warning.style.display = "block"; + } else { + warning.style.display = "none"; + } } -} -min.change(ver_check); -max.change(ver_check); + min.addEventListener("change", ver_check); + max.addEventListener("change", ver_check); + ver_check(); +}); diff --git a/app/public/static/release_new.js b/app/public/static/release_new.js new file mode 100644 index 00000000..a4bab14d --- /dev/null +++ b/app/public/static/release_new.js @@ -0,0 +1,19 @@ +// @author rubenwardy +// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later + +"use strict"; + +window.addEventListener("load", () => { + function check_opt() { + if (document.querySelector("input[name='uploadOpt']:checked").value === "vcs") { + document.getElementById("file_upload").parentElement.classList.add("d-none"); + document.getElementById("vcsLabel").parentElement.classList.remove("d-none"); + } else { + document.getElementById("file_upload").parentElement.classList.remove("d-none"); + document.getElementById("vcsLabel").parentElement.classList.add("d-none"); + } + } + + document.querySelectorAll("input[name='uploadOpt']").forEach(x => x.addEventListener("change", check_opt)); + check_opt(); +}); diff --git a/app/public/static/screenshots_editor.js b/app/public/static/screenshots_editor.js new file mode 100644 index 00000000..d58b3079 --- /dev/null +++ b/app/public/static/screenshots_editor.js @@ -0,0 +1,17 @@ +// @author rubenwardy +// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later + +"use strict"; + +window.addEventListener("load", () => { + function update() { + const elements = [...document.querySelector(".sortable").children]; + const ids = elements.map(x => x.dataset.id).filter(x => x); + document.querySelector("input[name='order']").value = ids.join(","); + } + + update(); + $(".sortable").sortable({ + update: update + }); +}) diff --git a/app/public/static/tagselector.js b/app/public/static/tagselector.js index 66012830..0db9afa8 100644 --- a/app/public/static/tagselector.js +++ b/app/public/static/tagselector.js @@ -3,6 +3,9 @@ * License: MIT * https://petprojects.googlecode.com/svn/trunk/MIT-LICENSE.txt */ + +"use strict"; + (function($) { function make_bold(text) { const idx = text.indexOf(":"); diff --git a/app/public/static/topic_discard.js b/app/public/static/topic_discard.js index a27d3d7f..2b8116e9 100644 --- a/app/public/static/topic_discard.js +++ b/app/public/static/topic_discard.js @@ -1,10 +1,12 @@ // @author rubenwardy // @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later -$(".topic-discard").click(function() { - const ele = $(this); - const tid = ele.attr("data-tid"); - const discard = !ele.parent().parent().hasClass("discardtopic"); +"use strict"; + +document.querySelectorAll(".topic-discard").forEach(ele => ele.addEventListener("click", (e) => { + const row = ele.parentNode.parentNode; + const tid = ele.getAttribute("data-tid"); + const discard = !row.classList.contains("discardtopic"); fetch(new Request("/api/topic_discard/?tid=" + tid + "&discard=" + (discard ? "true" : "false"), { method: "post", @@ -15,18 +17,17 @@ $(".topic-discard").click(function() { }, })).then(function(response) { response.text().then(function(txt) { - console.log(JSON.parse(txt)); if (JSON.parse(txt).discarded) { - ele.parent().parent().addClass("discardtopic"); - ele.removeClass("btn-danger"); - ele.addClass("btn-success"); - ele.text("Show"); + row.classList.add("discardtopic"); + ele.classList.remove("btn-danger"); + ele.classList.add("btn-success"); + ele.innerText = "Show"; } else { - ele.parent().parent().removeClass("discardtopic"); - ele.removeClass("btn-success"); - ele.addClass("btn-danger"); - ele.text("Discard"); + row.classList.remove("discardtopic"); + ele.classList.remove("btn-success"); + ele.classList.add("btn-danger"); + ele.innerText = "Discard"; } - }).catch(console.log) - }).catch(console.log) -}); + }).catch(console.error); + }).catch(console.error); +})); diff --git a/app/public/static/video_embed.js b/app/public/static/video_embed.js index 799d58f0..53479f39 100644 --- a/app/public/static/video_embed.js +++ b/app/public/static/video_embed.js @@ -1,6 +1,8 @@ // @author rubenwardy // @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later +"use strict"; + document.querySelectorAll(".video-embed").forEach(ele => { try { const href = ele.getAttribute("href"); diff --git a/app/scss/packages.scss b/app/scss/packages.scss index 99f6d309..62c4cc8d 100644 --- a/app/scss/packages.scss +++ b/app/scss/packages.scss @@ -65,10 +65,6 @@ font-size: 120%; } -.pkg_wiz_1, .pkg_wiz_2 { - display: none; -} - .plsearchform { padding: 0.5em; } diff --git a/app/templates/base.html b/app/templates/base.html index 86b90db6..d56724d6 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -276,7 +276,6 @@ {% endif %} - diff --git a/app/templates/collections/create_edit.html b/app/templates/collections/create_edit.html index 7ba545c5..6dfd9abc 100644 --- a/app/templates/collections/create_edit.html +++ b/app/templates/collections/create_edit.html @@ -9,6 +9,7 @@ {% endblock %} {% block scriptextra %} + {% endblock %} diff --git a/app/templates/macros/forms.html b/app/templates/macros/forms.html index 33af3c85..1988818f 100644 --- a/app/templates/macros/forms.html +++ b/app/templates/macros/forms.html @@ -70,6 +70,7 @@ {% macro form_scripts() -%} + {% endmacro %} diff --git a/app/templates/packages/create_edit.html b/app/templates/packages/create_edit.html index 4dcb38e0..8892084d 100644 --- a/app/templates/packages/create_edit.html +++ b/app/templates/packages/create_edit.html @@ -88,7 +88,7 @@
{{ _("Repository and Links") }} -
+

{{ _("Enter the repo URL for the package. If the repo uses git then the metadata will be automatically imported.") }}

@@ -98,12 +98,12 @@ {{ render_field(form.website, class_="pkg_meta") }} {{ render_field(form.repo, class_="pkg_repo", hint=_("HTTP URL to a Git, Mercurial, or other repository")) }} -
+ -
+
{{ _("Importing... (This may take a while)") }}
diff --git a/app/templates/packages/release_bulk_change.html b/app/templates/packages/release_bulk_change.html index b3d10379..bbad0f4e 100644 --- a/app/templates/packages/release_bulk_change.html +++ b/app/templates/packages/release_bulk_change.html @@ -42,26 +42,5 @@ {% block scriptextra %} - + {% endblock %} diff --git a/app/templates/packages/release_new.html b/app/templates/packages/release_new.html index 37b2a6f6..2c4798d9 100644 --- a/app/templates/packages/release_new.html +++ b/app/templates/packages/release_new.html @@ -86,22 +86,9 @@ {{ render_submit_field(form.submit) }}

- {% endblock %} {% block scriptextra %} - + {% endblock %} diff --git a/app/templates/packages/screenshots.html b/app/templates/packages/screenshots.html index 17339263..af50d9bf 100644 --- a/app/templates/packages/screenshots.html +++ b/app/templates/packages/screenshots.html @@ -131,20 +131,7 @@ {% endblock %} {% block scriptextra %} + - + {% endblock %}