Skip to content

Commit

Permalink
fix: Separate JS for base scoreboard and custom levels table (#1729)
Browse files Browse the repository at this point in the history
* fix: Separate JS for base scoreboard and custom levels table

* Load script only if RR
  • Loading branch information
faucomte97 authored Sep 16, 2024
1 parent 1346896 commit 1c6ef47
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 56 deletions.
38 changes: 19 additions & 19 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 0 additions & 37 deletions game/static/game/js/scoreboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,49 +69,12 @@ $(document).ready(function () {
$(".previous").removeClass("paginate_button");
});

// Setup shared levels table
let sharedLevelsTable = $("#sharedLevelsTable").DataTable({
scrollY: false,
scrollX: true,
scrollCollapse: false,
paging: true,
deferRender: true,
language: {
emptyTable: "No data available in table",
loadingRecords: "Loading...",
processing: "Processing...",
search: "Search:",
zeroRecords: "No matching records found"
},
columnDefs: [
{
orderable: false,
targets: "no-sort"
}
]
});

new $.fn.dataTable.FixedColumns(sharedLevelsTable, {
leftColumns: 2,
});

$("#sharedLevelsTable_next").append(" >");

sharedLevelsTable.on("draw", () => {
$("#sharedLevelsTable_next").append(" >");
$("#sharedLevelsTable_previous").prepend("< ");
$(".next").removeClass("paginate_button");
$(".previous").removeClass("paginate_button");
});

$("#scoreboardSearch").on("keyup", function () {
table.search(this.value).draw();
sharedLevelsTable.search(this.value).draw();
});

$(window).on("load", function () {
table.columns.adjust();
sharedLevelsTable.columns.adjust();
});
}

Expand Down
48 changes: 48 additions & 0 deletions game/static/game/js/scoreboardSharedLevels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
$(document).ready(function () {
let scoreboardPresent = document.getElementById("scoreboardTable") !== null;

if (scoreboardPresent) {
// Setup shared levels table
let sharedLevelsTable = $("#sharedLevelsTable").DataTable({
scrollY: false,
scrollX: true,
scrollCollapse: false,
paging: true,
deferRender: true,
language: {
emptyTable: "No data available in table",
loadingRecords: "Loading...",
processing: "Processing...",
search: "Search:",
zeroRecords: "No matching records found"
},
columnDefs: [
{
orderable: false,
targets: "no-sort"
}
]
});

new $.fn.dataTable.FixedColumns(sharedLevelsTable, {
leftColumns: 2,
});

$("#sharedLevelsTable_next").append(" >");

sharedLevelsTable.on("draw", () => {
$("#sharedLevelsTable_next").append(" >");
$("#sharedLevelsTable_previous").prepend("< ");
$(".next").removeClass("paginate_button");
$(".previous").removeClass("paginate_button");
});

$("#scoreboardSearch").on("keyup", function () {
sharedLevelsTable.search(this.value).draw();
});

$(window).on("load", function () {
sharedLevelsTable.columns.adjust();
});
}
});
3 changes: 3 additions & 0 deletions game/templates/game/scoreboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<script src="{% static 'game/js/pqselect.min.js' %}"></script>
<script src="{% static 'game/js/jquery.outerhtml.js' %}"></script>
<script src="{% static 'game/js/scoreboard.js' %}"></script>
{% if language == "blockly" %}
<script src="{% static 'game/js/scoreboardSharedLevels.js' %}"></script>
{% endif %}
{% endblock %}

{% block css %}
Expand Down

0 comments on commit 1c6ef47

Please sign in to comment.