Clean up JavaScript
This commit is contained in:
parent
42f96618e2
commit
b18903b59b
|
@ -22,7 +22,7 @@ $(function() {
|
|||
|
||||
function setField(id, value) {
|
||||
if (value && value != "") {
|
||||
var ele = $(id);
|
||||
const ele = $(id);
|
||||
ele.val(value);
|
||||
ele.trigger("change");
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@ $(function() {
|
|||
|
||||
$("#forums").on('paste', function(e) {
|
||||
try {
|
||||
var pasteData = e.originalEvent.clipboardData.getData('text')
|
||||
var url = new URL(pasteData);
|
||||
const pasteData = e.originalEvent.clipboardData.getData('text');
|
||||
const url = new URL(pasteData);
|
||||
if (url.hostname == "forum.minetest.net") {
|
||||
$(this).val(url.searchParams.get("t"));
|
||||
e.preventDefault();
|
||||
|
@ -42,7 +42,7 @@ $(function() {
|
|||
there's no need to use phrases such as \"adds X to the game\".`
|
||||
|
||||
$("#short_desc").on("change paste keyup", function() {
|
||||
var val = $(this).val().toLowerCase();
|
||||
const val = $(this).val().toLowerCase();
|
||||
if (val.indexOf("minetest") >= 0 || val.indexOf("mod") >= 0 ||
|
||||
val.indexOf("modpack") >= 0 || val.indexOf("mod pack") >= 0) {
|
||||
showHint($(this), hint_mtmods);
|
||||
|
@ -54,9 +54,9 @@ $(function() {
|
|||
}
|
||||
})
|
||||
|
||||
var btn = $("#forums").parent().find("label").append("<a class='ml-3 btn btn-sm btn-primary'>Open</a>");
|
||||
const btn = $("#forums").parent().find("label").append("<a class='ml-3 btn btn-sm btn-primary'>Open</a>");
|
||||
btn.click(function() {
|
||||
var id = $("#forums").val();
|
||||
const id = $("#forums").val();
|
||||
if (/^\d+$/.test(id)) {
|
||||
window.open("https://forum.minetest.net/viewtopic.php?t=" + id, "_blank");
|
||||
}
|
||||
|
|
|
@ -19,7 +19,8 @@ function getJSON(url, method) {
|
|||
|
||||
function pollTask(poll_url, disableTimeout) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var tries = 0;
|
||||
let tries = 0;
|
||||
|
||||
function retry() {
|
||||
tries++;
|
||||
if (!disableTimeout && tries > 30) {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
var min = $("#min_rel");
|
||||
var max = $("#max_rel");
|
||||
var none = $("#min_rel option:first-child").attr("value");
|
||||
var warning = $("#minmax_warning");
|
||||
const min = $("#min_rel");
|
||||
const max = $("#max_rel");
|
||||
const none = $("#min_rel option:first-child").attr("value");
|
||||
const warning = $("#minmax_warning");
|
||||
|
||||
function ver_check() {
|
||||
var minv = min.val();
|
||||
var maxv = max.val();
|
||||
const minv = min.val();
|
||||
const maxv = max.val();
|
||||
|
||||
if (minv != none && maxv != none && minv > maxv) {
|
||||
warning.show();
|
||||
|
|
|
@ -6,12 +6,12 @@
|
|||
*/
|
||||
(function($) {
|
||||
function hide_error(input) {
|
||||
var err = input.parent().parent().find(".invalid-remaining");
|
||||
const err = input.parent().parent().find(".invalid-remaining");
|
||||
err.hide();
|
||||
}
|
||||
|
||||
function show_error(input, msg) {
|
||||
var err = input.parent().parent().find(".invalid-remaining");
|
||||
const err = input.parent().parent().find(".invalid-remaining");
|
||||
console.log(err.length);
|
||||
err.text(msg);
|
||||
err.show();
|
||||
|
@ -19,12 +19,12 @@
|
|||
|
||||
$.fn.selectSelector = function(source, select) {
|
||||
return this.each(function() {
|
||||
var selector = $(this),
|
||||
const selector = $(this),
|
||||
input = $('input[type=text]', this);
|
||||
|
||||
selector.click(function() { input.focus(); })
|
||||
.delegate('.badge a', 'click', function() {
|
||||
var id = $(this).parent().data("id");
|
||||
const id = $(this).parent().data("id");
|
||||
select.find("option[value=" + id + "]").attr("selected", false)
|
||||
recreate();
|
||||
});
|
||||
|
@ -55,8 +55,8 @@
|
|||
}
|
||||
recreate();
|
||||
|
||||
input.focusout(function(e) {
|
||||
var value = input.val().trim()
|
||||
input.focusout(function() {
|
||||
const value = input.val().trim();
|
||||
if (value != "") {
|
||||
show_error(input, "Please select an existing tag, it;s not possible to add custom ones.");
|
||||
}
|
||||
|
@ -102,19 +102,19 @@
|
|||
|
||||
$.fn.csvSelector = function(source, name, result, allowSlash) {
|
||||
return this.each(function() {
|
||||
var selector = $(this),
|
||||
input = $('input[type=text]', this);
|
||||
const selector = $(this),
|
||||
input = $('input[type=text]', this);
|
||||
|
||||
var selected = [];
|
||||
var lookup = {};
|
||||
for (var i = 0; i < source.length; i++) {
|
||||
let selected = [];
|
||||
const lookup = {};
|
||||
for (var i = 0; i < source.length; i++) {
|
||||
lookup[source[i].id] = source[i];
|
||||
}
|
||||
|
||||
selector.click(function() { input.focus(); })
|
||||
.delegate('.badge a', 'click', function() {
|
||||
var id = $(this).parent().data("id");
|
||||
for (var i = 0; i < selected.length; i++) {
|
||||
const id = $(this).parent().data("id");
|
||||
for (let i = 0; i < selected.length; i++) {
|
||||
if (selected[i] == id) {
|
||||
selected.splice(i, 1);
|
||||
}
|
||||
|
@ -123,7 +123,7 @@
|
|||
});
|
||||
|
||||
function selectItem(id) {
|
||||
for (var i = 0; i < selected.length; i++) {
|
||||
for (let i = 0; i < selected.length; i++) {
|
||||
if (selected[i] == id) {
|
||||
return false;
|
||||
}
|
||||
|
@ -133,7 +133,7 @@
|
|||
}
|
||||
|
||||
function addTag(id, value) {
|
||||
var tag = $('<span class="badge badge-pill badge-primary"/>')
|
||||
const tag = $('<span class="badge badge-pill badge-primary"/>')
|
||||
.text(value)
|
||||
.data("id", id)
|
||||
.append(' <a>x</a>')
|
||||
|
@ -145,8 +145,8 @@
|
|||
|
||||
function recreate() {
|
||||
selector.find("span").remove();
|
||||
for (var i = 0; i < selected.length; i++) {
|
||||
var value = lookup[selected[i]] || { value: selected[i] };
|
||||
for (let i = 0; i < selected.length; i++) {
|
||||
const value = lookup[selected[i]] || {value: selected[i]};
|
||||
addTag(selected[i], value.value);
|
||||
}
|
||||
result.val(selected.join(","))
|
||||
|
@ -154,9 +154,9 @@
|
|||
|
||||
function readFromResult() {
|
||||
selected = [];
|
||||
var selected_raw = result.val().split(",");
|
||||
for (var i = 0; i < selected_raw.length; i++) {
|
||||
var raw = selected_raw[i].trim();
|
||||
const selected_raw = result.val().split(",");
|
||||
for (let i = 0; i < selected_raw.length; i++) {
|
||||
const raw = selected_raw[i].trim();
|
||||
if (lookup[raw] || raw.match(/^([a-z0-9_]+)$/)) {
|
||||
selected.push(raw);
|
||||
}
|
||||
|
@ -169,7 +169,7 @@
|
|||
result.change(readFromResult);
|
||||
|
||||
input.focusout(function() {
|
||||
var item = input.val();
|
||||
const item = input.val();
|
||||
if (item.length == 0) {
|
||||
input.data("ui-autocomplete").search("");
|
||||
} else if (item.match(/^([a-z0-9_]+)$/)) {
|
||||
|
@ -238,17 +238,17 @@
|
|||
|
||||
$(function() {
|
||||
$(".multichoice_selector").each(function() {
|
||||
var ele = $(this);
|
||||
var sel = ele.parent().find("select");
|
||||
const ele = $(this);
|
||||
const sel = ele.parent().find("select");
|
||||
sel.hide();
|
||||
|
||||
var options = [];
|
||||
const options = [];
|
||||
sel.find("option").each(function() {
|
||||
var text = $(this).text();
|
||||
const text = $(this).text();
|
||||
options.push({
|
||||
id: $(this).attr("value"),
|
||||
value: text,
|
||||
selected: $(this).attr("selected") ? true : false,
|
||||
selected: !!$(this).attr("selected"),
|
||||
toString: function() { return text; },
|
||||
});
|
||||
});
|
||||
|
@ -257,13 +257,13 @@
|
|||
});
|
||||
|
||||
$(".metapackage_selector").each(function() {
|
||||
var input = $(this).parent().children("input[type='text']");
|
||||
const input = $(this).parent().children("input[type='text']");
|
||||
input.hide();
|
||||
$(this).csvSelector(meta_packages, input.attr("name"), input);
|
||||
});
|
||||
|
||||
$(".deps_selector").each(function() {
|
||||
var input = $(this).parent().children("input[type='text']");
|
||||
const input = $(this).parent().children("input[type='text']");
|
||||
input.hide();
|
||||
$(this).csvSelector(all_packages, input.attr("name"), input);
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
$(".topic-discard").click(function() {
|
||||
var ele = $(this);
|
||||
var tid = ele.attr("data-tid");
|
||||
var discard = !ele.parent().parent().hasClass("discardtopic");
|
||||
const ele = $(this);
|
||||
const tid = ele.attr("data-tid");
|
||||
const discard = !ele.parent().parent().hasClass("discardtopic");
|
||||
fetch(new Request("/api/topic_discard/?tid=" + tid +
|
||||
"&discard=" + (discard ? "true" : "false"), {
|
||||
method: "post",
|
||||
|
|
|
@ -45,7 +45,8 @@
|
|||
<script src="/static/release_minmax.js?v=1"></script>
|
||||
<script>
|
||||
function setup_toggle(type) {
|
||||
var toggle = $("#set_" + type);
|
||||
const toggle = $("#set_" + type);
|
||||
|
||||
function on_change() {
|
||||
if (toggle.is(":checked")) {
|
||||
// $("#" + type + "_rel").removeAttr("disabled");
|
||||
|
|
|
@ -72,7 +72,7 @@
|
|||
|
||||
<script>
|
||||
$(".add-btn").click(function() {
|
||||
const row = $(this).parent().parent()
|
||||
$(this).parent().parent();
|
||||
|
||||
$(".modal select option").removeAttr("selected");
|
||||
$(".multichoice_selector").remove();
|
||||
|
@ -87,13 +87,13 @@
|
|||
$(".modal").modal("show");
|
||||
$(".modal input").focus();
|
||||
$(".multichoice_selector").each(function() {
|
||||
var ele = $(this);
|
||||
var sel = ele.parent().find("select");
|
||||
const ele = $(this);
|
||||
const sel = ele.parent().find("select");
|
||||
sel.hide();
|
||||
|
||||
var options = [];
|
||||
const options = [];
|
||||
sel.find("option").each(function() {
|
||||
var text = $(this).text();
|
||||
const text = $(this).text();
|
||||
options.push({
|
||||
id: $(this).attr("value"),
|
||||
value: text,
|
||||
|
|
|
@ -98,7 +98,7 @@ Topics to be Added
|
|||
|
||||
{% block scriptextra %}
|
||||
<script>
|
||||
var csrf_token = "{{ csrf_token() }}";
|
||||
const csrf_token = "{{ csrf_token() }}";
|
||||
</script>
|
||||
<script src="/static/topic_discard.js"></script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -242,7 +242,7 @@
|
|||
|
||||
{% block scriptextra %}
|
||||
<script>
|
||||
var csrf_token = "{{ csrf_token() }}";
|
||||
const csrf_token = "{{ csrf_token() }}";
|
||||
</script>
|
||||
<script src="/static/topic_discard.js"></script>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in New Issue