From 3adb10ca6c89d70c8f3c69f91c266138b877c58d Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Thu, 4 Apr 2019 10:19:29 +0200 Subject: [PATCH] jshint first batch --- server/Makefile | 3 ++ server/static/js/.jshintrc | 12 +++++++ server/static/js/CoordinatesDisplay.js | 8 ++--- server/static/js/Hashroute.js | 22 ++++++------- server/static/js/LayerManager.js | 5 ++- server/static/js/Overlaysetup.js | 31 ++++++++++--------- server/static/js/RealtimeTileLayer.js | 2 +- server/static/js/SimpleCRS.js | 2 +- server/static/js/WebSocketChannel.js | 14 ++++++--- server/static/js/WorldInfoDisplay.js | 7 ++--- server/static/js/api.js | 2 ++ server/static/js/main.js | 4 +-- .../js/overlays/AbstractGeoJsonOverlay.js | 7 +++-- server/static/js/util/debounce.js | 7 +++-- 14 files changed, 73 insertions(+), 53 deletions(-) create mode 100644 server/static/js/.jshintrc diff --git a/server/Makefile b/server/Makefile index 2160057..6fe6cb9 100644 --- a/server/Makefile +++ b/server/Makefile @@ -30,6 +30,9 @@ clean: rm -rf $(STATIC_VFS) rm -rf $(OUT_DIR) +jshint: + jshint static/js/*.js static/js/util static/js/overlays + $(STATIC_VFS): go generate diff --git a/server/static/js/.jshintrc b/server/static/js/.jshintrc new file mode 100644 index 0000000..3eff30a --- /dev/null +++ b/server/static/js/.jshintrc @@ -0,0 +1,12 @@ +{ + "undef": true, + "unused": true, + "esversion": 6, + "browser": true, + "globals": { + "debounce": true, + "L": true, + "m": true, + "api": true + } +} diff --git a/server/static/js/CoordinatesDisplay.js b/server/static/js/CoordinatesDisplay.js index aa35473..222bb09 100644 --- a/server/static/js/CoordinatesDisplay.js +++ b/server/static/js/CoordinatesDisplay.js @@ -1,11 +1,11 @@ -'use strict'; +/* exported CoordinatesDisplay */ // coord display var CoordinatesDisplay = L.Control.extend({ onAdd: function(map) { var div = L.DomUtil.create('div', 'leaflet-bar leaflet-custom-display'); - var hoverCoord, clickCoord + var hoverCoord, clickCoord; function updateHover(ev){ hoverCoord = ev.latlng; @@ -33,8 +33,6 @@ var CoordinatesDisplay = L.Control.extend({ map.on('touch', updateClick); return div; - }, - - onRemove: function(map) { } + }); diff --git a/server/static/js/Hashroute.js b/server/static/js/Hashroute.js index 18fd2fc..645183d 100644 --- a/server/static/js/Hashroute.js +++ b/server/static/js/Hashroute.js @@ -1,26 +1,26 @@ -'use strict'; +/* exported Hashroute */ var Hashroute = { setup: function(map, layerMgr){ function updateHash(){ var center = map.getCenter(); - location.hash = + window.location.hash = layerMgr.getCurrentLayer().id + "/" + center.lng + "/" + center.lat + "/" + map.getZoom(); } - map.on('zoomend', updateHash) - map.on('moveend', updateHash) - map.on('baselayerchange', updateHash) + map.on('zoomend', updateHash); + map.on('moveend', updateHash); + map.on('baselayerchange', updateHash); updateHash(); }, getLayerId: function(){ - var hashParts = location.hash.substring(1).split("/"); + var hashParts = window.location.hash.substring(1).split("/"); if (hashParts.length == 4){ //new format - return +hashParts[0] + return +hashParts[0]; } @@ -28,14 +28,14 @@ var Hashroute = { }, getZoom: function(){ - var hashParts = location.hash.substring(1).split("/"); + var hashParts = window.location.hash.substring(1).split("/"); if (hashParts.length == 3){ //old format - return +hashParts[2] + return +hashParts[2]; } else if (hashParts.length == 4){ //new format - return +hashParts[3] + return +hashParts[3]; } @@ -43,7 +43,7 @@ var Hashroute = { }, getCenter: function(){ - var hashParts = location.hash.substring(1).split("/"); + var hashParts = window.location.hash.substring(1).split("/"); if (hashParts.length == 3){ //old format return [+hashParts[1], +hashParts[0]]; diff --git a/server/static/js/LayerManager.js b/server/static/js/LayerManager.js index 2aad0e9..5fb3647 100644 --- a/server/static/js/LayerManager.js +++ b/server/static/js/LayerManager.js @@ -1,4 +1,4 @@ -'use strict'; +/* exported LayerManager */ function LayerManager(layers, map){ this.listeners = []; @@ -8,7 +8,6 @@ function LayerManager(layers, map){ var self = this; map.on('baselayerchange', function (e) { - console.log("baselayerchange", e.layer); self.setLayerId(e.layer.layerId); }); @@ -25,7 +24,7 @@ LayerManager.prototype.setLayerId = function(layerId){ return; } }); -}, +}; LayerManager.prototype.addListener = function(listener){ diff --git a/server/static/js/Overlaysetup.js b/server/static/js/Overlaysetup.js index c731e48..ddf0b8b 100644 --- a/server/static/js/Overlaysetup.js +++ b/server/static/js/Overlaysetup.js @@ -1,24 +1,25 @@ -'use strict'; +/* jshint undef: false */ +/* exported Overlaysetup */ function Overlaysetup(cfg, map, overlays, wsChannel, layerMgr){ if (cfg.mapobjects.mapserver) { - overlays["Player"] = new PlayerOverlay(wsChannel, layerMgr); - overlays["POI"] = new PoiOverlay(wsChannel, layerMgr); - overlays["Label"] = new LabelOverlay(wsChannel, layerMgr); - overlays["Border"] = new BorderOverlay(wsChannel, layerMgr); + overlays.Player = new PlayerOverlay(wsChannel, layerMgr); + overlays.POI = new PoiOverlay(wsChannel, layerMgr); + overlays.Label = new LabelOverlay(wsChannel, layerMgr); + overlays.Border = new BorderOverlay(wsChannel, layerMgr); - map.addLayer(overlays["Player"]); - map.addLayer(overlays["POI"]); - map.addLayer(overlays["Labels"]); + map.addLayer(overlays.Player); + map.addLayer(overlays.POI); + map.addLayer(overlays.Labels); } if (cfg.mapobjects.travelnet) { - overlays["Travelnet"] = new TravelnetOverlay(wsChannel, layerMgr); + overlays.Travelnet = new TravelnetOverlay(wsChannel, layerMgr); } if (cfg.mapobjects.bones) { - overlays["Bones"] = new BonesOverlay(wsChannel, layerMgr); + overlays.Bones = new BonesOverlay(wsChannel, layerMgr); } if (cfg.mapobjects.digilines) { @@ -26,7 +27,7 @@ function Overlaysetup(cfg, map, overlays, wsChannel, layerMgr){ } if (cfg.mapobjects.digiterms) { - overlays["Digiterms"] = new DigitermOverlay(wsChannel, layerMgr); + overlays.Digiterms = new DigitermOverlay(wsChannel, layerMgr); } if (cfg.mapobjects.luacontroller) { @@ -40,7 +41,7 @@ function Overlaysetup(cfg, map, overlays, wsChannel, layerMgr){ } if (cfg.mapobjects.protector) { - overlays["Protector"] = new ProtectorOverlay(wsChannel, layerMgr); + overlays.Protector = new ProtectorOverlay(wsChannel, layerMgr); } if (cfg.mapobjects.xpprotector) { @@ -52,11 +53,11 @@ function Overlaysetup(cfg, map, overlays, wsChannel, layerMgr){ } if (cfg.mapobjects.mission) { - overlays["Missions"] = new MissionOverlay(wsChannel, layerMgr); + overlays.Missions = new MissionOverlay(wsChannel, layerMgr); } if (cfg.mapobjects.train) { - overlays["Trains"] = new TrainOverlay(wsChannel, layerMgr); - overlays["Trainlines"] = new TrainlineOverlay(wsChannel, layerMgr); + overlays.Trains = new TrainOverlay(wsChannel, layerMgr); + overlays.Trainlines = new TrainlineOverlay(wsChannel, layerMgr); } } diff --git a/server/static/js/RealtimeTileLayer.js b/server/static/js/RealtimeTileLayer.js index 7fb4a21..a0063d1 100644 --- a/server/static/js/RealtimeTileLayer.js +++ b/server/static/js/RealtimeTileLayer.js @@ -1,4 +1,4 @@ -'use strict'; +/* exported RealtimeTileLayer */ var RealtimeTileLayer = L.TileLayer.extend({ diff --git a/server/static/js/SimpleCRS.js b/server/static/js/SimpleCRS.js index d0f13f3..907c08d 100644 --- a/server/static/js/SimpleCRS.js +++ b/server/static/js/SimpleCRS.js @@ -1,4 +1,4 @@ -'use strict'; +/* exported SimpleCRS */ var SimpleCRS = L.Util.extend({}, L.CRS.Simple, { scale: function (zoom) { diff --git a/server/static/js/WebSocketChannel.js b/server/static/js/WebSocketChannel.js index 4cf1faf..320bbfd 100644 --- a/server/static/js/WebSocketChannel.js +++ b/server/static/js/WebSocketChannel.js @@ -1,7 +1,11 @@ -'use strict'; +/* exported WebSocketChannel */ function WebSocketChannel(){ - this.wsUrl = location.protocol.replace("http", "ws") + "//" + location.host + location.pathname.substring(0, location.pathname.lastIndexOf("/")) + "/api/ws"; + this.wsUrl = window.location.protocol.replace("http", "ws") + + "//" + window.location.host + + window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/")) + + "/api/ws"; + this.listenerMap = {/* type -> [listeners] */}; } @@ -18,7 +22,7 @@ WebSocketChannel.prototype.addListener = function(type, listener){ WebSocketChannel.prototype.removeListener = function(type, listener){ var list = this.listenerMap[type]; if (!list){ - return + return; } this.listenerMap[type] = list.filter(function(l){ @@ -40,10 +44,10 @@ WebSocketChannel.prototype.connect = function(){ listener(event.data); }); } - } + }; ws.onerror = function(){ //reconnect after some time setTimeout(self.connect.bind(self), 1000); - } + }; }; diff --git a/server/static/js/WorldInfoDisplay.js b/server/static/js/WorldInfoDisplay.js index b559694..eac70b6 100644 --- a/server/static/js/WorldInfoDisplay.js +++ b/server/static/js/WorldInfoDisplay.js @@ -1,4 +1,4 @@ -'use strict'; +/* exported WorldInfoDisplay */ // coord display var WorldInfoDisplay = L.Control.extend({ @@ -7,7 +7,7 @@ var WorldInfoDisplay = L.Control.extend({ this.wsChannel = wsChannel; }, - onAdd: function(map) { + onAdd: function() { var div = L.DomUtil.create('div', 'leaflet-bar leaflet-custom-display'); this.wsChannel.addListener("minetest-info", function(info){ @@ -15,8 +15,5 @@ var WorldInfoDisplay = L.Control.extend({ }); return div; - }, - - onRemove: function(map) { } }); diff --git a/server/static/js/api.js b/server/static/js/api.js index 8908dca..f7c7439 100644 --- a/server/static/js/api.js +++ b/server/static/js/api.js @@ -1,3 +1,5 @@ +/* exported api */ + var api = { getMapObjects: function(query){ diff --git a/server/static/js/main.js b/server/static/js/main.js index 6af4c59..014dc0e 100644 --- a/server/static/js/main.js +++ b/server/static/js/main.js @@ -1,4 +1,4 @@ -'use strict'; +/* jshint undef: false */ api.getConfig().then(function(cfg){ @@ -16,7 +16,7 @@ api.getConfig().then(function(cfg){ map.attributionControl.addAttribution('Minetest Mapserver'); var layers = {}; - var overlays = {} + var overlays = {}; var layerMgr = new LayerManager(cfg.layers, map); layerMgr.setLayerId( Hashroute.getLayerId() ); diff --git a/server/static/js/overlays/AbstractGeoJsonOverlay.js b/server/static/js/overlays/AbstractGeoJsonOverlay.js index ee15c00..bcb03ba 100644 --- a/server/static/js/overlays/AbstractGeoJsonOverlay.js +++ b/server/static/js/overlays/AbstractGeoJsonOverlay.js @@ -1,4 +1,5 @@ -'use strict'; +/* exported AbstractGeoJsonOverlay */ +/* jshint unused: false */ var AbstractGeoJsonOverlay = L.LayerGroup.extend({ initialize: function(wsChannel, layerMgr, type) { @@ -81,7 +82,7 @@ var AbstractGeoJsonOverlay = L.LayerGroup.extend({ var geoJsonLayer = self.createGeoJson(objects); geoJsonLayer.addTo(self); - }) + }); }, @@ -90,7 +91,7 @@ var AbstractGeoJsonOverlay = L.LayerGroup.extend({ map.on("zoomend", this.onMapMove); map.on("moveend", this.onMapMove); this.layerMgr.addListener(this.onLayerChange); - this.reDraw(true) + this.reDraw(true); }, onRemove: function(map) { diff --git a/server/static/js/util/debounce.js b/server/static/js/util/debounce.js index 8985c23..c71c0c9 100644 --- a/server/static/js/util/debounce.js +++ b/server/static/js/util/debounce.js @@ -1,3 +1,5 @@ +/* exported debounce */ + function debounce(func, wait, immediate) { var timeout; return function() { @@ -9,6 +11,7 @@ function debounce(func, wait, immediate) { var callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); - if (callNow) func.apply(context, args); + if (callNow) + func.apply(context, args); }; -}; +}