diff --git a/app/public/static/js/package_edit.js b/app/public/static/js/package_edit.js index 6eb7b743..0701171a 100644 --- a/app/public/static/js/package_edit.js +++ b/app/public/static/js/package_edit.js @@ -40,45 +40,55 @@ window.addEventListener("load", () => { window.open("https://forum.minetest.net/viewtopic.php?t=" + forumsField.value, "_blank"); }); - let hint = null; - function showHint(ele, text) { - if (hint) { - hint.remove(); + function setupHints(id, hints) { + function onChange(val) { + val = val.toLowerCase(); + Object.entries(hints).forEach(([key, func]) => { + if (func(val)) { + document.getElementById(key).classList.remove("d-none"); + } else { + document.getElementById(key).classList.add("d-none"); + } + }); } - 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: - Don't include Minetest, mod, or modpack anywhere in the short description. - It is unnecessary and wastes characters.`; - - 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\".`; - - 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(shortDescField, hint_mtmods); - } else if (val.indexOf("the game") >= 0) { - showHint(shortDescField, hint_thegame); - } else if (hint) { - hint.remove(); - hint = null; + const field = document.getElementById(id); + if (field.easy_mde) { + field.easy_mde.codemirror.on("change", () => { + const value = field.easy_mde.value(); + onChange(value); + }); + } else { + field.addEventListener("change", () => onChange(field.value)); + field.addEventListener("paste", () => onChange(field.value)); + field.addEventListener("keyup", () => onChange(field.value)); + field.addEventListener("input", () => onChange(field.value)); } + onChange(field.value); } - shortDescField.addEventListener("change", handleShortDescChange); - shortDescField.addEventListener("paste", handleShortDescChange); - shortDescField.addEventListener("keyup", handleShortDescChange); + setupHints("short_desc", { + "short_desc_mods": (val) => val.indexOf("minetest") >= 0 || val.indexOf("mod") >= 0 || + val.indexOf("modpack") >= 0 || val.indexOf("mod pack") >= 0, + }); + + setupHints("desc", { + "desc_page_link": (val) => { + let packageUrl = window.location.href.replace("/edit/", ""); + if (packageUrl.indexOf("/packages/new/") >= 0) { + const author = document.querySelector("form[data-author]").getAttribute("data-author"); + const name = document.getElementById("name").value; + packageUrl = `/packages/${author}/${name}/`; + } + return val.indexOf(packageUrl.toLowerCase()) >= 0; + }, + "desc_page_topic": (val) => { + const topicId = document.getElementById("forums").value; + return topicId && val.indexOf(`forum.minetest.net/viewtopic.php?t=${topicId}`) >= 0; + }, + "desc_page_repo": (val) => { + const repoUrl = document.getElementById("repo").value; + return repoUrl && val.indexOf(repoUrl.toLowerCase()) >= 0; + }, + }); }) diff --git a/app/templates/packages/create_edit.html b/app/templates/packages/create_edit.html index 92c3bc44..201260d9 100644 --- a/app/templates/packages/create_edit.html +++ b/app/templates/packages/create_edit.html @@ -21,7 +21,7 @@ {% endif %} - + {% endblock %} {% block content %} @@ -59,7 +59,7 @@ {{ package_lists() }} -
+ {{ form.hidden_tag() }}
@@ -76,6 +76,10 @@ {% endif %} {{ render_field(form.short_desc, class_="pkg_meta") }} +

+ {{ _("Tip: Don't include Minetest, mod, or modpack anywhere in the short description. It is unnecessary and wastes characters.") }} +

+ {{ render_field(form.dev_state, class_="pkg_meta", hint=_("Please choose 'Work in Progress' if your package is unstable, and shouldn't be recommended to all players")) }} {{ render_multiselect_field(form.tags, class_="pkg_meta") }} {{ render_multiselect_field(form.content_warnings, class_="pkg_meta") }} @@ -84,6 +88,15 @@ {{ render_field(form.media_license, class_="col-sm-6", hint=_("If there is no media, set the Media License to the same as the License.")) }} {{ render_field(form.desc, class_="pkg_meta", fieldclass="form-control markdown") }} + +

+ {{ _("There's no need to include the forum topic in the long description, it's already shown on the page.") }} +

+

+ {{ _("There's no need to include the repository URL in the long description, it's already shown on the page.") }} +

{{ _("What to write in the long description") }}