inline #isArrayUtil, remove jQuery

This commit is contained in:
Nick Krecklow 2020-05-11 04:25:30 -05:00
parent e8b530bbb8
commit 59ec7d151f
No known key found for this signature in database
GPG Key ID: 5F149FDE156FFA94
4 changed files with 20 additions and 24 deletions

@ -1,8 +1,7 @@
{ {
"env": { "env": {
"browser": true, "browser": true,
"es6": true, "es6": true
"jquery": true
}, },
"extends": [ "extends": [
"standard" "standard"

@ -90,8 +90,6 @@
<span class="icon-code"></span> Powered by open source software - <a href="https://github.com/Cryptkeeper/Minetrack">make it your own!</a> <span class="icon-code"></span> Powered by open source software - <a href="https://github.com/Cryptkeeper/Minetrack">make it your own!</a>
</footer> </footer>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.slim.min.js"></script>
<script src="../js/main.js" defer></script> <script src="../js/main.js" defer></script>
</body> </body>

@ -1,5 +1,3 @@
import { isArrayEqual } from './util'
const SORT_OPTIONS = [ const SORT_OPTIONS = [
{ {
getName: () => 'Players', getName: () => 'Players',
@ -164,9 +162,22 @@ export class SortController {
// This avoids DOM updates and graphs being redrawn // This avoids DOM updates and graphs being redrawn
const sortedServerIds = sortedServers.map(server => server.serverId) const sortedServerIds = sortedServers.map(server => server.serverId)
if (isArrayEqual(sortedServerIds, this._lastSortedServers)) { if (this._lastSortedServers) {
let allMatch = true
// Test if the arrays have actually changed
// No need to length check, they are the same source data each time
for (let i = 0; i < sortedServerIds.length; i++) {
if (sortedServerIds[i] !== this._lastSortedServers[i]) {
allMatch = false
break
}
}
if (allMatch) {
return return
} }
}
this._lastSortedServers = sortedServerIds this._lastSortedServers = sortedServerIds
@ -176,7 +187,10 @@ export class SortController {
// Update the DOM structure // Update the DOM structure
sortedServers.forEach(function (serverRegistration) { sortedServers.forEach(function (serverRegistration) {
$('#container_' + serverRegistration.serverId).appendTo('#server-list') const parentElement = document.getElementById('server-list')
const serverElement = document.getElementById('container_' + serverRegistration.serverId)
parentElement.appendChild(serverElement)
// Set the ServerRegistration's rankIndex to its indexOf the normal sort // Set the ServerRegistration's rankIndex to its indexOf the normal sort
serverRegistration.updateServerRankIndex(rankIndexSort.indexOf(serverRegistration)) serverRegistration.updateServerRankIndex(rankIndexSort.indexOf(serverRegistration))

@ -120,21 +120,6 @@ export function formatNumber (x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
} }
export function isArrayEqual (a, b) {
if (typeof a === 'undefined' || typeof a !== typeof b) {
return false
}
if (a.length !== b.length) {
return false
}
for (let i = 0; i < a.length; i++) {
if (a[i] !== b[i]) {
return false
}
}
return true
}
// From http://detectmobilebrowsers.com/ // From http://detectmobilebrowsers.com/
export function isMobileBrowser () { export function isMobileBrowser () {
var check = false; var check = false;