Skip to content

Commit

Permalink
refact: use shorthand method and property syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
simon04 authored and bagage committed Oct 19, 2024
1 parent babd154 commit 76f31ae
Show file tree
Hide file tree
Showing 44 changed files with 520 additions and 514 deletions.
6 changes: 3 additions & 3 deletions js/Browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
touch = touchScreenDetectable ? touchScreen : L.Browser.touch;

BR.Browser = {
touchScreen: touchScreen,
touchScreenDetectable: touchScreenDetectable,
touch: touch,
touchScreen,
touchScreenDetectable,
touch,
download:
'Blob' in window &&
'FileReader' in window &&
Expand Down
54 changes: 27 additions & 27 deletions js/LayersConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BR.LayersConfig = L.Class.extend({
// hardcoded, built-in layers with an id set (for URL hash)
builtInLayers: ['route-quality'],

initialize: function (map) {
initialize(map) {
this._map = map;
this._overpassLoadingIndicator = new BR.Message('overpass_loading_indicator', { alert: false });
this._overpassActiveRequestCount = 0;
Expand All @@ -17,7 +17,7 @@ BR.LayersConfig = L.Class.extend({
this._addLanguageDefaultLayer();
},

loadDefaultLayers: function () {
loadDefaultLayers() {
if (BR.Util.localStorageAvailable()) {
var item = localStorage.getItem('map/defaultLayers');
if (item) {
Expand All @@ -28,29 +28,29 @@ BR.LayersConfig = L.Class.extend({
}
},

storeDefaultLayers: function (baseLayers, overlays) {
storeDefaultLayers(baseLayers, overlays) {
if (BR.Util.localStorageAvailable()) {
var defaultLayers = {
baseLayers: baseLayers,
overlays: overlays,
baseLayers,
overlays,
};
localStorage.setItem('map/defaultLayers', JSON.stringify(defaultLayers));
}
},

_replaceLegacyIds: function (idList) {
_replaceLegacyIds(idList) {
return idList.map((id) => (id in this.legacyNameToIdMap ? this.legacyNameToIdMap[id] : id));
},

_addLeafletProvidersLayers: function () {
_addLeafletProvidersLayers() {
var includeList = BR.confLayers.leafletProvidersIncludeList;

for (var i = 0; i < includeList.length; i++) {
var id = includeList[i];
var obj = {
geometry: null,
properties: {
id: id,
id,
name: id.replace('.', ' '),
dataSource: 'leaflet-providers',
},
Expand All @@ -60,7 +60,7 @@ BR.LayersConfig = L.Class.extend({
}
},

_customizeLayers: function () {
_customizeLayers() {
var propertyOverrides = BR.confLayers.getPropertyOverrides();

for (var id in propertyOverrides) {
Expand Down Expand Up @@ -92,7 +92,7 @@ BR.LayersConfig = L.Class.extend({
BR.layerIndex['ignf-scan25'].geometry = BR.confLayers.franceBbox;
},

_addLanguageDefaultLayer: function () {
_addLanguageDefaultLayer() {
// language code -> layer id
var languageLayersMap = {};
var i;
Expand Down Expand Up @@ -120,7 +120,7 @@ BR.LayersConfig = L.Class.extend({
}
},

isDefaultLayer: function (id, overlay) {
isDefaultLayer(id, overlay) {
var result = false;
if (overlay) {
result = this.defaultOverlays.indexOf(id) > -1;
Expand All @@ -130,15 +130,15 @@ BR.LayersConfig = L.Class.extend({
return result;
},

getBaseLayers: function () {
getBaseLayers() {
return this._getLayers(this.defaultBaseLayers);
},

getOverlays: function () {
getOverlays() {
return this._getLayers(this.defaultOverlays);
},

_getLayers: function (ids) {
_getLayers(ids) {
var layers = {};

for (var i = 0; i < ids.length; i++) {
Expand All @@ -161,7 +161,7 @@ BR.LayersConfig = L.Class.extend({

// own convention: key placeholder with prefix
// e.g. ?api_key={keys_openrouteservice}
getKeyName: function (url) {
getKeyName(url) {
var result = null;
// L.Util.template only matches [\w_-]
var prefix = 'keys_';
Expand All @@ -174,26 +174,26 @@ BR.LayersConfig = L.Class.extend({
if (found) {
name = found[1];
result = {
name: name,
name,
urlVar: prefix + name,
};
}

return result;
},

_showOverpassLoadingIndicator: function () {
_showOverpassLoadingIndicator() {
this._overpassActiveRequestCount++;
this._overpassLoadingIndicator.showLoading(i18next.t('layers.overpass-loading-indicator'));
},

_hideOverpassLoadingIndicator: function () {
_hideOverpassLoadingIndicator() {
if (--this._overpassActiveRequestCount === 0) {
this._overpassLoadingIndicator.hide();
}
},

getOverpassIconUrl: function (icon) {
getOverpassIconUrl(icon) {
const iconPrefix = /^(maki|temaki|fas)-/;
let iconUrl = null;

Expand All @@ -205,7 +205,7 @@ BR.LayersConfig = L.Class.extend({
return iconUrl;
},

createOverpassLayer: function (query, icon) {
createOverpassLayer(query, icon) {
let markerSign = '<i class="fa fa-search icon-white" style="width: 25px;"></i>';

const iconUrl = this.getOverpassIconUrl(icon);
Expand All @@ -216,7 +216,7 @@ BR.LayersConfig = L.Class.extend({
return Object.assign(
new OverpassLayer({
overpassFrontend: this.overpassFrontend,
query: query,
query,
minZoom: 12,
feature: {
title: '{{ tags.name }}',
Expand Down Expand Up @@ -244,7 +244,7 @@ BR.LayersConfig = L.Class.extend({
);
},

renderOverpassPopupBody: function (overpassData) {
renderOverpassPopupBody(overpassData) {
let output = '';

output += '<table class="overpass-tags">';
Expand Down Expand Up @@ -301,11 +301,11 @@ BR.LayersConfig = L.Class.extend({
return output;
},

createOpenStreetMapNotesLayer: function () {
createOpenStreetMapNotesLayer() {
return new leafletOsmNotes();
},

createMvtLayer: function (props, options) {
createMvtLayer(props, options) {
// remove key, only provided with local style to not add layer when not configured, see _getLayers
const styleId = props.url?.split('?')[0];
if (styleId in BR.layerIndex) {
Expand All @@ -322,7 +322,7 @@ BR.LayersConfig = L.Class.extend({
return BR.maplibreGlLazyLoader(options);
},

_replaceMvtTileKey: function (style) {
_replaceMvtTileKey(style) {
if (!style) return;

// Sources can be specified by `url` (string) or `tiles` (array), we handle
Expand All @@ -348,7 +348,7 @@ BR.LayersConfig = L.Class.extend({
}
},

createGeoJsonLayer: function (props) {
createGeoJsonLayer(props) {
const layer = L.geoJSON(undefined, BR.Track.getGeoJsonOptions());
fetch(props.url).then(async (response) => {
const geojson = await response.json();
Expand All @@ -357,7 +357,7 @@ BR.LayersConfig = L.Class.extend({
return layer;
},

createLayer: function (layerData) {
createLayer(layerData) {
var props = layerData.properties;
var url = props.url;
var layer;
Expand Down
10 changes: 5 additions & 5 deletions js/Map.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BR.Map = {
initMap: function () {
initMap() {
var map, layersControl;

L.setOptions(this, {
Expand All @@ -20,7 +20,7 @@ BR.Map = {
zoomControl: false, // add it manually so that we can translate it
worldCopyJump: true,
minZoom: 0,
maxZoom: maxZoom,
maxZoom,
});

if (BR.Util.getResponsiveBreakpoint() >= '3md') {
Expand Down Expand Up @@ -142,12 +142,12 @@ BR.Map = {
BR.debug.map = map;

return {
map: map,
layersControl: layersControl,
map,
layersControl,
};
},

_renderLayerCredits: function (layers) {
_renderLayerCredits(layers) {
var dl = document.getElementById('credits-maps');
var i, obj, dt, dd, attribution;

Expand Down
18 changes: 9 additions & 9 deletions js/Util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BR.Util = {
get: function (url, cb) {
get(url, cb) {
var xhr = new XMLHttpRequest();

xhr.open('GET', url, true);
Expand All @@ -20,7 +20,7 @@ BR.Util = {
}
},

getError: function (xhr) {
getError(xhr) {
var msg = i18next.t('warning.no-response');
if (xhr.responseText) {
msg = xhr.responseText;
Expand All @@ -30,7 +30,7 @@ BR.Util = {
return new Error(msg);
},

getJson: function (url, context, cb) {
getJson(url, context, cb) {
BR.Util.get(url, function (err, data) {
if (err) {
BR.message.showError('Error getting ' + context + ': ' + err);
Expand All @@ -48,7 +48,7 @@ BR.Util = {
});
},

getGeoJson: function (url, context, cb) {
getGeoJson(url, context, cb) {
BR.Util.getJson(url, context, function (err, data) {
if (err) return cb(err);

Expand All @@ -70,7 +70,7 @@ BR.Util = {
// https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API#Testing_for_support_vs_availability
// by Mozilla Contributors, with modifications;
// Any copyright is dedicated to the Public Domain. https://creativecommons.org/publicdomain/zero/1.0/
localStorageAvailable: function () {
localStorageAvailable() {
try {
var storage = window.localStorage,
x = '__storage_test__';
Expand All @@ -83,7 +83,7 @@ BR.Util = {
},

// see https://stackoverflow.com/a/37141090/1906123
getResponsiveBreakpoint: function () {
getResponsiveBreakpoint() {
var envs = { '1xs': 'd-none', '2sm': 'd-sm-none', '3md': 'd-md-none', '4lg': 'd-lg-none', '5xl': 'd-xl-none' };
var env = '';

Expand All @@ -101,7 +101,7 @@ BR.Util = {
return env;
},

keyboardShortcutsAllowed: function (keyEvent) {
keyboardShortcutsAllowed(keyEvent) {
// Skip auto-repeating key events
if (keyEvent.repeat) {
return false;
Expand Down Expand Up @@ -134,13 +134,13 @@ BR.Util = {
// this method must only be used to sanitize for textContent.
// do NOT use it to sanitize any attribute,
// see https://web.archive.org/web/20121208091505/http://benv.ca/2012/10/4/you-are-probably-misusing-DOM-text-methods/
sanitizeHTMLContent: function (str) {
sanitizeHTMLContent(str) {
var temp = document.createElement('div');
temp.textContent = str;
return temp.innerHTML;
},

isCountry: function (country, language) {
isCountry(country, language) {
// de-DE | fr-FR
var lang = i18next.languages[0].split('-');

Expand Down
12 changes: 6 additions & 6 deletions js/WhatsNew.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
BR.WhatsNew = {
newOnly: undefined,

init: function () {
init() {
var self = this;
self.dismissableMessage = new BR.Message('whats_new_message', {
onClosed: function () {
onClosed() {
document.getElementsByClassName('version')[0].classList.remove('version-new');
if (BR.Util.localStorageAvailable()) {
localStorage.setItem('changelogVersion', self.getLatestVersion());
Expand All @@ -29,21 +29,21 @@ BR.WhatsNew = {
}
},

getLatestVersion: function () {
getLatestVersion() {
return BR.changelog.match('<h2 id="(.*)">')[1];
},

getCurrentVersion: function () {
getCurrentVersion() {
if (!BR.Util.localStorageAvailable()) return null;

return localStorage.getItem('changelogVersion');
},

hasNewVersions: function () {
hasNewVersions() {
return this.getCurrentVersion() && this.getCurrentVersion() !== this.getLatestVersion();
},

prepare: function (newOnly) {
prepare(newOnly) {
if (newOnly === this.newOnly) {
// do not rebuild modal content unnecessarily
return;
Expand Down
Loading

0 comments on commit 76f31ae

Please sign in to comment.