Update prettier version

This commit is contained in:
Gautier P 2020-12-05 11:50:30 +01:00
parent c49b821db7
commit 25429b3c24
42 changed files with 2480 additions and 2490 deletions

View file

@ -1,5 +1,5 @@
BR.ControlLayers = L.Control.Layers.extend({
getActiveLayers: function() {
getActiveLayers: function () {
var result = [];
for (var i = 0; i < this._layers.length; i++) {
@ -16,7 +16,7 @@ BR.ControlLayers = L.Control.Layers.extend({
return result;
},
getActiveBaseLayer: function() {
getActiveBaseLayer: function () {
var activeLayers = this.getActiveLayers();
for (var i = 0; i < activeLayers.length; i++) {
var obj = activeLayers[i];
@ -28,7 +28,7 @@ BR.ControlLayers = L.Control.Layers.extend({
return null;
},
removeActiveLayers: function() {
removeActiveLayers: function () {
var removed = [];
for (var i = 0; i < this._layers.length; i++) {
@ -42,7 +42,7 @@ BR.ControlLayers = L.Control.Layers.extend({
return removed;
},
getLayer: function(name) {
getLayer: function (name) {
for (var i = 0; i < this._layers.length; i++) {
var obj = this._layers[i];
if (obj.name === name) {
@ -53,19 +53,19 @@ BR.ControlLayers = L.Control.Layers.extend({
return null;
},
getBaseLayers: function() {
return this._layers.filter(function(obj) {
getBaseLayers: function () {
return this._layers.filter(function (obj) {
return !obj.overlay;
});
},
activateLayer: function(obj) {
activateLayer: function (obj) {
if (!this._map.hasLayer(obj.layer)) {
this._map.addLayer(obj.layer);
}
},
activateFirstLayer: function() {
activateFirstLayer: function () {
for (var i = 0; i < this._layers.length; i++) {
var obj = this._layers[i];
if (!obj.overlay) {
@ -75,14 +75,14 @@ BR.ControlLayers = L.Control.Layers.extend({
}
},
activateBaseLayerIndex: function(index) {
activateBaseLayerIndex: function (index) {
var baseLayers = this.getBaseLayers();
var obj = baseLayers[index];
this.activateLayer(obj);
},
_addLayer: function(layer, name, overlay) {
_addLayer: function (layer, name, overlay) {
L.Control.Layers.prototype._addLayer.call(this, layer, name, overlay);
// override z-index assignment to fix that base layers added later
@ -95,5 +95,5 @@ BR.ControlLayers = L.Control.Layers.extend({
layer.setZIndex(0);
}
}
}
},
});

View file

@ -3,11 +3,11 @@ BR.Export = L.Class.extend({
options: {
shortcut: {
export: 88 // char code for 'x'
}
export: 88, // char code for 'x'
},
},
initialize: function(router, pois) {
initialize: function (router, pois) {
this.router = router;
this.pois = pois;
this.exportButton = $('#exportButton');
@ -31,7 +31,7 @@ BR.Export = L.Class.extend({
this.update([]);
},
update: function(latLngs) {
update: function (latLngs) {
this.latLngs = latLngs;
if (latLngs.length < 2) {
@ -41,7 +41,7 @@ BR.Export = L.Class.extend({
}
},
_export: function(e) {
_export: function (e) {
var exportForm = document.forms['export'];
var format = exportForm['format'].value || $('#export-format input:radio:checked').val();
var name = encodeURIComponent(exportForm['trackname'].value);
@ -58,7 +58,7 @@ BR.Export = L.Class.extend({
link.dispatchEvent(evt);
},
_validationMessage: function() {
_validationMessage: function () {
var trackname = this.trackname;
var replaceRegex = new RegExp('[^' + this.tracknameAllowedChars + ']', 'g');
@ -71,14 +71,14 @@ BR.Export = L.Class.extend({
}
},
_generateTrackname: function() {
_generateTrackname: function () {
var trackname = this.trackname;
this._getCityAtPosition(
this.latLngs[0],
L.bind(function(from) {
L.bind(function (from) {
this._getCityAtPosition(
this.latLngs[this.latLngs.length - 1],
L.bind(function(to) {
L.bind(function (to) {
var distance = document.getElementById('distance').innerHTML;
if (this.tracknameAllowedChars) {
distance = distance.replace(',', '.'); // temp. fix (#202)
@ -88,13 +88,13 @@ BR.Export = L.Class.extend({
} else if (from === to) {
trackname.value = i18next.t('export.route-loop', {
from: from,
distance: distance
distance: distance,
});
} else {
trackname.value = i18next.t('export.route-from-to', {
from: from,
to: to,
distance: distance
distance: distance,
});
}
@ -109,14 +109,14 @@ BR.Export = L.Class.extend({
);
},
_getCityAtPosition: function(lonlat, cb) {
_getCityAtPosition: function (lonlat, cb) {
var url = L.Util.template(
'https://nominatim.openstreetmap.org/reverse?lon={lng}&lat={lat}&format=json',
lonlat
);
BR.Util.get(
url,
L.bind(function(err, response) {
L.bind(function (err, response) {
try {
var addr = JSON.parse(response).address;
cb(addr.village || addr.town || addr.hamlet || addr.city_district || addr.city);
@ -128,7 +128,7 @@ BR.Export = L.Class.extend({
);
},
_keydownListener: function(e) {
_keydownListener: function (e) {
if (
BR.Util.keyboardShortcutsAllowed(e) &&
e.keyCode === this.options.shortcut.export &&
@ -137,9 +137,9 @@ BR.Export = L.Class.extend({
this._generateTrackname();
$('#export').modal('show');
}
}
},
});
BR.export = function() {
BR.export = function () {
return new BR.Export();
};

View file

@ -1,10 +1,10 @@
BR.Itinerary = L.Class.extend({
initialize: function() {
initialize: function () {
this._content = document.getElementById('itinerary');
this.update();
},
update: function(polyline, segments) {
update: function (polyline, segments) {
var i,
j,
iter,
@ -20,5 +20,5 @@ BR.Itinerary = L.Class.extend({
html += '</pre>';
this._content.innerHTML = html;
}
},
});

View file

@ -1,5 +1,5 @@
BR.Layers = L.Class.extend({
_loadLayers: function() {
_loadLayers: function () {
this._customLayers = {};
if (BR.Util.localStorageAvailable()) {
@ -10,13 +10,13 @@ BR.Layers = L.Class.extend({
}
},
_loadTable: function() {
_loadTable: function () {
var layersData = [];
for (layer in this._customLayers) {
layersData.push([
layer,
this._customLayers[layer].layer._url,
this._customLayers[layer].isOverlay ? 'Overlay' : 'Layer'
this._customLayers[layer].isOverlay ? 'Overlay' : 'Layer',
]);
}
if (this._layersTable != null) {
@ -29,17 +29,17 @@ BR.Layers = L.Class.extend({
searching: false,
paging: false,
language: {
emptyTable: i18next.t('sidebar.layers.table.empty')
emptyTable: i18next.t('sidebar.layers.table.empty'),
},
columns: [
{ title: i18next.t('sidebar.layers.table.name') },
{ title: i18next.t('sidebar.layers.table.URL') },
{ title: i18next.t('sidebar.layers.table.type') }
]
{ title: i18next.t('sidebar.layers.table.type') },
],
});
},
init: function(map, layersControl, baseLayers, overlays) {
init: function (map, layersControl, baseLayers, overlays) {
this._layersControl = layersControl;
this._map = map;
this._layers = {};
@ -54,7 +54,7 @@ BR.Layers = L.Class.extend({
this._loadTable();
var table = this._layersTable;
$('#custom_layers_table tbody').on('click', 'tr', function() {
$('#custom_layers_table tbody').on('click', 'tr', function () {
if ($(this).hasClass('selected')) {
$(this).removeClass('selected');
} else {
@ -63,40 +63,37 @@ BR.Layers = L.Class.extend({
}
});
L.DomUtil.get('custom_layers_button').onclick = function() {
L.DomUtil.get('custom_layers_button').onclick = function () {
$('#custom_layers').modal();
};
},
_remove: function(evt) {
_remove: function (evt) {
var row = this._layersTable.row('.selected').data();
if (row != null) {
var name = row[0];
this._layersControl.removeLayer(this._customLayers[name].layer);
this._map.removeLayer(this._customLayers[name].layer);
delete this._customLayers[name];
this._layersTable
.row('.selected')
.remove()
.draw(false);
this._layersTable.row('.selected').remove().draw(false);
this._sync();
}
},
_addFromInput: function(isOverlay) {
_addFromInput: function (isOverlay) {
var layer_name = L.DomUtil.get('layer_name').value;
var layer_url = L.DomUtil.get('layer_url').value;
if (layer_name.length > 0 && layer_url.length > 0) this._addLayer(layer_name, layer_url, isOverlay);
},
_addBaseLayer: function(evt) {
_addBaseLayer: function (evt) {
this._addFromInput(false);
},
_addOverlay: function(evt) {
_addOverlay: function (evt) {
this._addFromInput(true);
},
_addLayer: function(layerName, layerUrl, isOverlay) {
_addLayer: function (layerName, layerUrl, isOverlay) {
if (layerName in this._layers) return;
if (layerName in this._customLayers) return;
@ -106,7 +103,7 @@ BR.Layers = L.Class.extend({
this._customLayers[layerName] = {
layer: layer,
isOverlay: isOverlay
isOverlay: isOverlay,
};
if (isOverlay) {
@ -123,15 +120,15 @@ BR.Layers = L.Class.extend({
}
},
_sync: function() {
_sync: function () {
if (BR.Util.localStorageAvailable()) {
localStorage.setItem(
'map/customLayers',
JSON.stringify(this._customLayers, function(k, v) {
JSON.stringify(this._customLayers, function (k, v) {
// dont write Leaflet.Layer in localStorage; simply keep the URL
return v._url || v;
})
);
}
}
},
});

View file

@ -3,13 +3,13 @@ BR.LayersTab = BR.ControlLayers.extend({
previewBounds: null,
saveLayers: [],
initialize: function(layersConfig, baseLayers, overlays, options) {
initialize: function (layersConfig, baseLayers, overlays, options) {
L.Control.Layers.prototype.initialize.call(this, baseLayers, overlays, options);
this.layersConfig = layersConfig;
},
addTo: function(map) {
addTo: function (map) {
this._map = map;
this.onAdd(map);
@ -22,19 +22,19 @@ BR.LayersTab = BR.ControlLayers.extend({
return this;
},
onAdd: function(map) {
onAdd: function (map) {
BR.ControlLayers.prototype.onAdd.call(this, map);
map.on('baselayerchange overlayadd overlayremove', this.storeActiveLayers, this);
},
onRemove: function(map) {
onRemove: function (map) {
BR.ControlLayers.prototype.onRemove.call(this, map);
map.off('baselayerchange overlayadd overlayremove', this.storeActiveLayers, this);
},
initOpacitySlider: function(map) {
initOpacitySlider: function (map) {
var self = this;
var overlayOpacitySlider = new BR.OpacitySlider({
id: 'overlay',
@ -42,7 +42,7 @@ BR.LayersTab = BR.ControlLayers.extend({
orientation: 'horizontal',
defaultValue: 1,
title: i18next.t('layers.opacity-slider'),
callback: function(opacity) {
callback: function (opacity) {
for (var i = 0; i < self._layers.length; i++) {
if (!self._layers[i].overlay || !map.hasLayer(self._layers[i].layer)) {
continue;
@ -53,20 +53,20 @@ BR.LayersTab = BR.ControlLayers.extend({
self._layers[i].layer.setStyle({ opacity: opacity });
}
}
}
},
});
L.DomUtil.get('leaflet-control-layers-overlays-opacity-slider').appendChild(overlayOpacitySlider.getElement());
},
initButtons: function() {
var expandTree = function(e) {
initButtons: function () {
var expandTree = function (e) {
this.jstree.open_all();
};
var collapseTree = function(e) {
var collapseTree = function (e) {
this.jstree.close_all();
};
var toggleOptionalLayers = function(e) {
var toggleOptionalLayers = function (e) {
var button = L.DomUtil.get('optional_layers_button');
var treeButtons = L.DomUtil.get('tree-button-group');
var div = L.DomUtil.get('optional-layers');
@ -86,12 +86,12 @@ BR.LayersTab = BR.ControlLayers.extend({
L.DomUtil.get('optional_layers_button').onclick = L.bind(toggleOptionalLayers, this);
},
initJsTree: function() {
initJsTree: function () {
var layerIndex = BR.layerIndex;
var treeData = this.toJsTree(BR.confLayers.tree);
var oldSelected = null;
var onSelectNode = function(e, data) {
var onSelectNode = function (e, data) {
var layerData = layerIndex[data.node.id];
var selected = data.selected[0];
@ -103,12 +103,12 @@ BR.LayersTab = BR.ControlLayers.extend({
}
};
var onDeselectNode = function(e, data) {
var onDeselectNode = function (e, data) {
this.hidePreview();
oldSelected = null;
};
var onCheckNode = function(e, data) {
var onCheckNode = function (e, data) {
var layerData = layerIndex[data.node.id];
var layer = this.createLayer(layerData);
var name = layerData.properties.name;
@ -124,12 +124,12 @@ BR.LayersTab = BR.ControlLayers.extend({
var ele = document.getElementById(data.node.a_attr.id);
ele.classList.add('added');
setTimeout(function() {
setTimeout(function () {
ele.classList.remove('added');
}, 1000);
};
var onUncheckNode = function(e, data) {
var onUncheckNode = function (e, data) {
var obj = this.getLayerById(data.node.id);
if (!obj) return;
@ -146,7 +146,7 @@ BR.LayersTab = BR.ControlLayers.extend({
var ele = document.getElementById(data.node.a_attr.id);
ele.classList.add('removed');
setTimeout(function() {
setTimeout(function () {
ele.classList.remove('removed');
}, 1000);
};
@ -156,30 +156,30 @@ BR.LayersTab = BR.ControlLayers.extend({
.on('deselect_node.jstree', L.bind(onDeselectNode, this))
.on('check_node.jstree', L.bind(onCheckNode, this))
.on('uncheck_node.jstree', L.bind(onUncheckNode, this))
.on('ready.jstree', function(e, data) {
.on('ready.jstree', function (e, data) {
data.instance.open_all();
})
.jstree({
plugins: ['checkbox'],
checkbox: {
whole_node: false,
tie_selection: false
tie_selection: false,
},
core: {
multiple: false,
themes: {
icons: false,
dots: false
dots: false,
},
data: treeData
}
data: treeData,
},
});
this.jstree = $('#optional-layers-tree').jstree(true);
},
toJsTree: function(layerTree) {
toJsTree: function (layerTree) {
var data = {
children: []
children: [],
};
var self = this;
@ -187,9 +187,9 @@ BR.LayersTab = BR.ControlLayers.extend({
var rootNode = {
text: i18next.t('sidebar.layers.category.' + name, name),
state: {
disabled: true
disabled: true,
},
children: []
children: [],
};
return rootNode;
}
@ -217,8 +217,8 @@ BR.LayersTab = BR.ControlLayers.extend({
id: id,
text: getText(props, parent),
state: {
checked: self.layersConfig.isDefaultLayer(id, props.overlay)
}
checked: self.layersConfig.isDefaultLayer(id, props.overlay),
},
};
}
return childNode;
@ -262,7 +262,7 @@ BR.LayersTab = BR.ControlLayers.extend({
return data.children;
},
storeDefaultLayers: function() {
storeDefaultLayers: function () {
var baseLayers = [];
var overlays = [];
@ -284,7 +284,7 @@ BR.LayersTab = BR.ControlLayers.extend({
this.layersConfig.storeDefaultLayers(baseLayers, overlays);
},
createLayer: function(layerData) {
createLayer: function (layerData) {
var layer = this.layersConfig.createLayer(layerData);
var overlay = layerData.properties.overlay;
@ -294,7 +294,7 @@ BR.LayersTab = BR.ControlLayers.extend({
return layer;
},
getLayerById: function(id) {
getLayerById: function (id) {
for (var i = 0; i < this._layers.length; i++) {
var obj = this._layers[i];
if (obj.layer.id === id) {
@ -305,7 +305,7 @@ BR.LayersTab = BR.ControlLayers.extend({
return null;
},
getLayerByLegacyName: function(legacyName) {
getLayerByLegacyName: function (legacyName) {
var obj = null;
var id = this.layersConfig.legacyNameToIdMap[legacyName];
@ -316,7 +316,7 @@ BR.LayersTab = BR.ControlLayers.extend({
return obj;
},
activateDefaultBaseLayer: function() {
activateDefaultBaseLayer: function () {
var index = BR.conf.defaultBaseLayerIndex || 0;
var activeBaseLayer = this.getActiveBaseLayer();
if (!activeBaseLayer) {
@ -324,11 +324,11 @@ BR.LayersTab = BR.ControlLayers.extend({
}
},
saveRemoveActiveLayers: function() {
saveRemoveActiveLayers: function () {
this.saveLayers = this.removeActiveLayers();
},
restoreActiveLayers: function(overlaysOnly) {
restoreActiveLayers: function (overlaysOnly) {
for (var i = 0; i < this.saveLayers.length; i++) {
var obj = this.saveLayers[i];
@ -345,7 +345,7 @@ BR.LayersTab = BR.ControlLayers.extend({
this.saveLayers = [];
},
removePreviewLayer: function() {
removePreviewLayer: function () {
if (this.previewLayer && this._map.hasLayer(this.previewLayer)) {
this._map.removeLayer(this.previewLayer);
this.previewLayer = null;
@ -354,7 +354,7 @@ BR.LayersTab = BR.ControlLayers.extend({
return false;
},
showPreviewBounds: function(layerData) {
showPreviewBounds: function (layerData) {
if (layerData.geometry) {
this.previewBounds = L.geoJson(layerData.geometry, {
// fill/mask outside of bounds polygon with Leaflet.snogylop
@ -363,30 +363,30 @@ BR.LayersTab = BR.ControlLayers.extend({
renderer: L.svg({ padding: 1 }),
color: '#333',
fillOpacity: 0.4,
weight: 2
weight: 2,
}).addTo(this._map);
}
},
removePreviewBounds: function() {
removePreviewBounds: function () {
if (this.previewBounds && this._map.hasLayer(this.previewBounds)) {
this._map.removeLayer(this.previewBounds);
this.previewBounds = null;
}
},
deselectNode: function() {
deselectNode: function () {
var selected = this.jstree.get_selected();
if (selected.length > 0) {
this.jstree.deselect_node(selected[0]);
}
},
onBaselayerchange: function() {
onBaselayerchange: function () {
// execute after current input click handler,
// otherwise added overlay checkbox state doesn't update
setTimeout(
L.Util.bind(function() {
L.Util.bind(function () {
this.removePreviewBounds();
this.removePreviewLayer();
this.restoreActiveLayers(true);
@ -396,7 +396,7 @@ BR.LayersTab = BR.ControlLayers.extend({
);
},
showPreview: function(layerData) {
showPreview: function (layerData) {
var layer = this.createLayer(layerData);
this._map.addLayer(layer);
this.removePreviewBounds();
@ -411,7 +411,7 @@ BR.LayersTab = BR.ControlLayers.extend({
L.DomUtil.get('preview').hidden = false;
},
hidePreview: function(layer) {
hidePreview: function (layer) {
this._map.off('baselayerchange', this.onBaselayerchange, this);
this.removePreviewBounds();
this.removePreviewLayer();
@ -420,11 +420,11 @@ BR.LayersTab = BR.ControlLayers.extend({
L.DomUtil.get('preview').hidden = true;
},
toLayerString: function(obj) {
toLayerString: function (obj) {
return obj.layer.id ? obj.layer.id : obj.name;
},
getLayerFromString: function(layerString) {
getLayerFromString: function (layerString) {
var obj = this.getLayerById(layerString);
if (!obj) {
@ -440,11 +440,11 @@ BR.LayersTab = BR.ControlLayers.extend({
return obj;
},
storeActiveLayers: function() {
storeActiveLayers: function () {
if (BR.Util.localStorageAvailable()) {
var objList = this.getActiveLayers();
var idList = objList.map(
L.bind(function(obj) {
L.bind(function (obj) {
return this.toLayerString(obj);
}, this)
);
@ -454,7 +454,7 @@ BR.LayersTab = BR.ControlLayers.extend({
}
},
loadActiveLayers: function() {
loadActiveLayers: function () {
if (BR.Util.localStorageAvailable()) {
var item = localStorage.getItem('map/activeLayers');
@ -471,9 +471,9 @@ BR.LayersTab = BR.ControlLayers.extend({
}
}
}
}
},
});
BR.layersTab = function(baseLayers, overlays, options) {
BR.layersTab = function (baseLayers, overlays, options) {
return new BR.LayersTab(baseLayers, overlays, options);
};

View file

@ -2,15 +2,15 @@ BR.Message = L.Class.extend({
options: {
// true to manually attach click event to close button,
// Bootstrap data-api's auto-initialization doesn't work in Controls because of stopPropagation
alert: false
alert: false,
},
initialize: function(id, options) {
initialize: function (id, options) {
L.setOptions(this, options);
this.id = id;
},
_show: function(msg, type) {
_show: function (msg, type) {
var ele = L.DomUtil.get(this.id),
iconClass = type === 'warning' ? 'fa-exclamation-triangle' : 'fa-times-circle',
alertClass = type === 'warning' ? 'alert-warning' : 'alert-danger';
@ -35,11 +35,11 @@ BR.Message = L.Class.extend({
}
},
hide: function() {
hide: function () {
$('#' + this.id + ' .alert').alert('close');
},
showError: function(err) {
showError: function (err) {
if (err && err.message) err = err.message;
if (err == 'target island detected for section 0\n') {
@ -56,9 +56,9 @@ BR.Message = L.Class.extend({
this._show(err, 'error');
},
showWarning: function(msg) {
showWarning: function (msg) {
this._show(msg, 'warning');
}
},
});
// static instance as global control

View file

@ -5,10 +5,10 @@ BR.OpacitySlider = L.Class.extend({
orientation: 'vertical',
defaultValue: BR.conf.defaultOpacity,
title: '',
callback: function(opacity) {}
callback: function (opacity) {},
},
initialize: function(options) {
initialize: function (options) {
L.setOptions(this, options);
var input = (this.input = $('<input id="slider-' + this.options.id + '" type="text"/>')),
@ -30,12 +30,12 @@ BR.OpacitySlider = L.Class.extend({
orientation: this.options.orientation,
reversed: this.options.reversed,
selection: this.options.reversed ? 'before' : 'after', // inverted, serves as track style, see css
tooltip: 'hide'
tooltip: 'hide',
})
.on('slide slideStop', { self: this }, function(evt) {
.on('slide slideStop', { self: this }, function (evt) {
evt.data.self.options.callback(evt.value / 100);
})
.on('slideStop', { self: this }, function(evt) {
.on('slideStop', { self: this }, function (evt) {
if (BR.Util.localStorageAvailable()) {
localStorage['opacitySliderValue' + evt.data.self.options.id] = evt.value;
}
@ -51,19 +51,19 @@ BR.OpacitySlider = L.Class.extend({
}
},
_keydownListener: function(e) {
_keydownListener: function (e) {
if (BR.Util.keyboardShortcutsAllowed(e) && e.keyCode === this.options.muteKeyCode) {
this.options.callback(0);
}
},
_keyupListener: function(e) {
_keyupListener: function (e) {
if (BR.Util.keyboardShortcutsAllowed(e) && e.keyCode === this.options.muteKeyCode) {
this.options.callback(this.input.val() / 100);
}
},
getElement: function() {
getElement: function () {
return this.input.slider('getElement');
}
},
});

View file

@ -1,9 +1,9 @@
BR.OpacitySliderControl = L.Control.extend({
options: {
position: 'topleft'
position: 'topleft',
},
onAdd: function(map) {
onAdd: function (map) {
var container = L.DomUtil.create('div', 'leaflet-bar control-slider');
// prevent also dragging map in Chrome
@ -21,22 +21,22 @@ BR.OpacitySliderControl = L.Control.extend({
var slider = new BR.OpacitySlider(this.options);
container.appendChild(slider.getElement());
var stopClickAfterSlide = function(evt) {
var stopClickAfterSlide = function (evt) {
L.DomEvent.stop(evt);
removeStopClickListeners();
};
var removeStopClickListeners = function() {
var removeStopClickListeners = function () {
document.removeEventListener('click', stopClickAfterSlide, true);
document.removeEventListener('mousedown', removeStopClickListeners, true);
};
slider.input
.on('slideStart', function(evt) {
.on('slideStart', function (evt) {
// dragging beyond slider control selects zoom control +/- text in Firefox
L.DomUtil.disableTextSelection();
})
.on('slideStop', { self: this }, function(evt) {
.on('slideStop', { self: this }, function (evt) {
L.DomUtil.enableTextSelection();
// When dragging outside slider and over map, click event after mouseup
@ -49,5 +49,5 @@ BR.OpacitySliderControl = L.Control.extend({
});
return container;
}
},
});

View file

@ -2,15 +2,15 @@ BR.Profile = L.Evented.extend({
cache: {},
saveWarningShown: false,
initialize: function() {
initialize: function () {
var textArea = L.DomUtil.get('profile_upload');
this.editor = CodeMirror.fromTextArea(textArea, {
lineNumbers: true
lineNumbers: true,
});
$('#profileEditorTabs a[data-toggle="tab"]').on(
'shown.bs.tab',
L.bind(function(e) {
L.bind(function (e) {
this._activateSecondaryTab();
}, this)
);
@ -22,11 +22,11 @@ BR.Profile = L.Evented.extend({
this.pinned = L.DomUtil.get('profile-pinned');
this.message = new BR.Message('profile_message', {
alert: true
alert: true,
});
},
clear: function(evt) {
clear: function (evt) {
var button = evt.target || evt.srcElement;
evt.preventDefault();
@ -38,7 +38,7 @@ BR.Profile = L.Evented.extend({
button.blur();
},
update: function(options) {
update: function (options) {
var profileName = options.profile,
profileUrl,
empty = !this.editor.getValue(),
@ -53,7 +53,7 @@ BR.Profile = L.Evented.extend({
profileUrl = BR.conf.profilesUrl + profileName + '.brf';
BR.Util.get(
profileUrl,
L.bind(function(err, profileText) {
L.bind(function (err, profileText) {
if (err) {
console.warn('Error getting profile from "' + profileUrl + '": ' + err);
return;
@ -82,15 +82,15 @@ BR.Profile = L.Evented.extend({
}
},
show: function() {
show: function () {
this.editor.refresh();
},
onResize: function() {
onResize: function () {
this.editor.refresh();
},
_upload: function(evt) {
_upload: function (evt) {
var button = evt.target || evt.srcElement,
profile = this.editor.getValue();
@ -99,7 +99,7 @@ BR.Profile = L.Evented.extend({
this.fire('update', {
profileText: profile,
callback: L.bind(function(err, profileId, profileText) {
callback: L.bind(function (err, profileId, profileText) {
$(button).blur();
if (!err) {
this.profileName = profileId;
@ -110,12 +110,12 @@ BR.Profile = L.Evented.extend({
this.saveWarningShown = true;
}
}
}, this)
}, this),
});
},
_buildCustomProfile: function(profileText) {
document.querySelectorAll('#profile_params input, #profile_params select').forEach(function(input) {
_buildCustomProfile: function (profileText) {
document.querySelectorAll('#profile_params input, #profile_params select').forEach(function (input) {
var name = input.name;
var value;
if (input.type == 'checkbox') {
@ -129,28 +129,28 @@ BR.Profile = L.Evented.extend({
name +
'\\s*=?\\s*)([\\w.]*)(\\s*#\\s*%(.*)%\\s*(\\|\\s*(.*)\\s*\\|\\s*(.*)\\s*)?[\\r\\n])'
);
profileText = profileText.replace(re, function(match, p1, p2, p3) {
profileText = profileText.replace(re, function (match, p1, p2, p3) {
return p1 + value + p3;
});
});
return profileText;
},
_save: function(evt) {
_save: function (evt) {
var profileText = this._buildCustomProfile(this.editor.getValue());
var that = this;
this.fire('update', {
profileText: profileText,
callback: function(err, profileId, profileText) {
callback: function (err, profileId, profileText) {
if (!err) {
that.profileName = profileId;
that.cache[profileId] = profileText;
}
}
},
});
},
_setValue: function(profileText) {
_setValue: function (profileText) {
profileText = profileText || '';
var clean = this.editor.isClean();
@ -169,12 +169,12 @@ BR.Profile = L.Evented.extend({
}
},
_buildParamsForm: function(profileText) {
_buildParamsForm: function (profileText) {
if (!profileText) return;
// Otherwise, create user friendly form
var params = {};
var global = profileText.split('---context:').filter(function(e) {
var global = profileText.split('---context:').filter(function (e) {
return e.startsWith('global');
});
if (global && global.length > 0) {
@ -183,7 +183,7 @@ BR.Profile = L.Evented.extend({
// Comment is mandatory
var assignRegex = /assign\s*(\w*)\s*=?\s*([\w\.]*)\s*#\s*%(.*)%\s*(\|\s*(.*)\s*\|\s*(.*)\s*)?$/;
global.forEach(function(item) {
global.forEach(function (item) {
var match = item.match(assignRegex);
var value;
if (match) {
@ -198,7 +198,7 @@ BR.Profile = L.Evented.extend({
paramType
.slice(1, -1)
.split(',')
.forEach(function(option) {
.forEach(function (option) {
var splitOption = option.split('=');
var value = (splitOption[0] || '').replace(/^\s+|\s+$/g, '');
var description = (splitOption[1] || '').replace(/^\s+|\s+$/g, '');
@ -230,7 +230,7 @@ BR.Profile = L.Evented.extend({
description: description,
type: paramType,
value: value,
possible_values: paramValues
possible_values: paramValues,
};
}
});
@ -242,7 +242,7 @@ BR.Profile = L.Evented.extend({
paramsSection.append(i18next.t('sidebar.profile.no_easy_configuration_warning'));
}
Object.keys(params).forEach(function(param) {
Object.keys(params).forEach(function (param) {
var div = document.createElement('div');
var label = document.createElement('label');
@ -257,7 +257,7 @@ BR.Profile = L.Evented.extend({
label.htmlFor = select.id = 'customize-profile-' + paramName;
var paramValues = params[param].possible_values;
Object.keys(paramValues).forEach(function(paramValue) {
Object.keys(paramValues).forEach(function (paramValue) {
var option = document.createElement('option');
option.value = paramValue;
if (paramValue == params[param].value) {
@ -308,11 +308,11 @@ BR.Profile = L.Evented.extend({
});
},
_isParamsFormActive: function() {
_isParamsFormActive: function () {
return L.DomUtil.get('profile_params_container').classList.contains('active');
},
_activateSecondaryTab: function() {
_activateSecondaryTab: function () {
var profileText = this.editor.getValue();
if (this._isParamsFormActive()) {
@ -320,5 +320,5 @@ BR.Profile = L.Evented.extend({
} else {
this._setValue(this._buildCustomProfile(profileText));
}
}
},
});

View file

@ -1,11 +1,11 @@
BR.RoutingOptions = L.Evented.extend({
options: {
shortcut: {
switch: 71 // char code for 'g'
}
switch: 71, // char code for 'g'
},
},
initialize: function() {
initialize: function () {
$('#profile-alternative').on('changed.bs.select', this._getChangeHandler());
// build option list from config
@ -25,17 +25,17 @@ BR.RoutingOptions = L.Evented.extend({
L.DomEvent.addListener(document, 'keydown', this._keydownListener, this);
},
refreshUI: function() {
refreshUI: function () {
// we do not allow to select more than one profile and/or alternative at a time
// so we disable the current selected items
$('#profile-alternative')
.find('option:disabled')
.each(function(index) {
.each(function (index) {
$(this).prop('disabled', false);
});
$('#profile-alternative')
.find('option:selected')
.each(function(index) {
.each(function (index) {
$(this).prop('disabled', true);
});
@ -51,21 +51,21 @@ BR.RoutingOptions = L.Evented.extend({
button.title = button.title + i18next.t('navbar.profile-tooltip', { key: 'G' });
},
getOptions: function() {
getOptions: function () {
var profile = $('#profile option:selected'),
alternative = $('#alternative option:selected');
this.refreshUI();
return {
profile: profile.val(),
alternative: alternative.val()
alternative: alternative.val(),
};
},
setOptions: function(options) {
setOptions: function (options) {
var values = [
options.profile ? options.profile : $('#profile option:selected').val(),
options.alternative ? options.alternative : $('#alternative option:selected').val()
options.alternative ? options.alternative : $('#alternative option:selected').val(),
];
$('.selectpicker').selectpicker('val', values);
this.refreshUI();
@ -76,7 +76,7 @@ BR.RoutingOptions = L.Evented.extend({
}
},
setCustomProfile: function(profile, noUpdate) {
setCustomProfile: function (profile, noUpdate) {
var profiles_grp, option;
profiles_grp = L.DomUtil.get('profile');
@ -87,7 +87,7 @@ BR.RoutingOptions = L.Evented.extend({
if (profile) {
$('#profile')
.find('option:selected')
.each(function(index) {
.each(function (index) {
$(this).prop('selected', false);
});
} else if (option.selected) {
@ -102,7 +102,7 @@ BR.RoutingOptions = L.Evented.extend({
}
},
getCustomProfile: function() {
getCustomProfile: function () {
var profiles_grp = L.DomUtil.get('profile'),
option = profiles_grp.children[0],
profile = null;
@ -113,17 +113,17 @@ BR.RoutingOptions = L.Evented.extend({
return profile;
},
_getChangeHandler: function() {
return L.bind(function(evt) {
_getChangeHandler: function () {
return L.bind(function (evt) {
this.fire('update', { options: this.getOptions() });
}, this);
},
_keydownListener: function(e) {
_keydownListener: function (e) {
if (BR.Util.keyboardShortcutsAllowed(e) && e.keyCode === this.options.shortcut.switch) {
if (!$('#profile-alternative-form .dropdown').hasClass('show')) {
$('#profile-alternative-form button').click();
}
}
}
},
});

View file

@ -20,8 +20,8 @@ BR.TrackAnalysis = L.Class.extend({
opacity: 0.8,
weight: 8,
// show above quality coding (pane defined in RoutingPathQuality.js)
pane: 'routingQualityPane'
}
pane: 'routingQualityPane',
},
},
/**
@ -35,7 +35,7 @@ BR.TrackAnalysis = L.Class.extend({
* @param {Map} map
* @param {object} options
*/
initialize: function(map, options) {
initialize: function (map, options) {
this.map = map;
L.setOptions(this, options);
},
@ -60,7 +60,7 @@ BR.TrackAnalysis = L.Class.extend({
/**
* Called by BR.Sidebar when tab is activated
*/
show: function() {
show: function () {
this.active = true;
this.options.requestUpdate(this);
},
@ -68,7 +68,7 @@ BR.TrackAnalysis = L.Class.extend({
/**
* Called by BR.Sidebar when tab is deactivated
*/
hide: function() {
hide: function () {
this.active = false;
},
@ -84,7 +84,7 @@ BR.TrackAnalysis = L.Class.extend({
* @param {Polyline} polyline
* @param {Array} segments
*/
update: function(polyline, segments) {
update: function (polyline, segments) {
if (!this.active) {
return;
}
@ -121,11 +121,11 @@ BR.TrackAnalysis = L.Class.extend({
* @param segments
* @returns {Object}
*/
calcStats: function(polyline, segments) {
calcStats: function (polyline, segments) {
var analysis = {
highway: {},
surface: {},
smoothness: {}
smoothness: {},
};
this.totalRouteDistance = 0.0;
@ -158,7 +158,7 @@ BR.TrackAnalysis = L.Class.extend({
),
name: wayTagParts[1],
subtype: trackType,
distance: 0.0
distance: 0.0,
};
}
analysis.highway[highwayType].distance += parseFloat(
@ -175,7 +175,7 @@ BR.TrackAnalysis = L.Class.extend({
),
name: wayTagParts[1],
subtype: '',
distance: 0.0
distance: 0.0,
};
}
analysis[wayTagParts[0]][wayTagParts[1]].distance += parseFloat(
@ -198,7 +198,7 @@ BR.TrackAnalysis = L.Class.extend({
*
* @returns {Object}
*/
sortAnalysisData: function(analysis) {
sortAnalysisData: function (analysis) {
var analysisSortable = {};
var result = {};
@ -217,7 +217,7 @@ BR.TrackAnalysis = L.Class.extend({
analysisSortable[type].push(analysis[type][name]);
}
analysisSortable[type].sort(function(a, b) {
analysisSortable[type].sort(function (a, b) {
return b.distance - a.distance;
});
@ -236,7 +236,7 @@ BR.TrackAnalysis = L.Class.extend({
* @param {string[]} wayTags
* @returns {string}
*/
getTrackType: function(wayTags) {
getTrackType: function (wayTags) {
for (var i = 0; i < wayTags.length; i++) {
var wayTagParts = wayTags[i].split('=');
if (wayTagParts[0] === 'tracktype') {
@ -250,7 +250,7 @@ BR.TrackAnalysis = L.Class.extend({
/**
* @param {Object} analysis
*/
render: function(analysis) {
render: function (analysis) {
var $content = $('#track_statistics');
$content.html('');
@ -275,7 +275,7 @@ BR.TrackAnalysis = L.Class.extend({
* @param {Array} data
* @returns {jQuery}
*/
renderTable: function(type, data) {
renderTable: function (type, data) {
var index;
var $table = $(
'<table data-type="' + type + '" class="mini cell-border stripe dataTable track-analysis-table"></table>'
@ -366,11 +366,11 @@ BR.TrackAnalysis = L.Class.extend({
* @param {number} meters
* @returns {string}
*/
formatDistance: function(meters) {
formatDistance: function (meters) {
return (meters / 1000).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 });
},
handleHover: function(event) {
handleHover: function (event) {
var $tableRow = $(event.currentTarget);
var $table = $tableRow.parents('table').first();
var dataType = $table.data('type');
@ -382,15 +382,13 @@ BR.TrackAnalysis = L.Class.extend({
this.highlightedSegments = L.layerGroup(polylinesForDataType).addTo(this.map);
},
handleHoverOut: function() {
handleHoverOut: function () {
this.map.removeLayer(this.highlightedSegments);
},
toggleSelected: function(event) {
toggleSelected: function (event) {
var tableRow = event.currentTarget;
var $table = $(tableRow)
.parents('table')
.first();
var $table = $(tableRow).parents('table').first();
var dataType = $table.data('type');
var dataName = $(tableRow).data('name');
var trackType = $(tableRow).data('subtype');
@ -426,7 +424,7 @@ BR.TrackAnalysis = L.Class.extend({
*
* @returns {Polyline[]}
*/
getPolylinesForDataType: function(dataType, dataName, trackType) {
getPolylinesForDataType: function (dataType, dataName, trackType) {
var polylines = [];
var trackLatLngs = this.trackPolyline.getLatLngs();
@ -461,7 +459,7 @@ BR.TrackAnalysis = L.Class.extend({
*
* @returns {boolean}
*/
wayTagsMatchesData: function(wayTags, dataType, dataName, trackType) {
wayTagsMatchesData: function (wayTags, dataType, dataName, trackType) {
var parsed = this.parseWayTags(wayTags);
switch (dataType) {
@ -502,7 +500,7 @@ BR.TrackAnalysis = L.Class.extend({
*
* @returns {object}
*/
parseWayTags: function(wayTags) {
parseWayTags: function (wayTags) {
var result = {};
var wayTagPairs = wayTags.feature.wayTags.split(' ');
@ -512,5 +510,5 @@ BR.TrackAnalysis = L.Class.extend({
}
return result;
}
},
});

View file

@ -5,10 +5,10 @@ BR.TrackMessages = L.Class.extend({
opacity: 0.8,
weight: 8,
// show above quality coding (pane defined in RoutingPathQuality.js)
pane: 'routingQualityPane'
pane: 'routingQualityPane',
},
// center hovered edge (way segment) on map
syncMap: true
syncMap: true,
},
// true when tab is shown, false when hidden
@ -23,7 +23,7 @@ BR.TrackMessages = L.Class.extend({
ElevCost: { title: 'elev$', className: 'dt-body-right' },
TurnCost: { title: 'turn$', className: 'dt-body-right' },
NodeCost: { title: 'node$', className: 'dt-body-right' },
InitialCost: { title: 'initial$', className: 'dt-body-right' }
InitialCost: { title: 'initial$', className: 'dt-body-right' },
},
/**
@ -36,7 +36,7 @@ BR.TrackMessages = L.Class.extend({
*/
trackPolyline: null,
initialize: function(map, options) {
initialize: function (map, options) {
L.setOptions(this, options);
this._map = map;
@ -48,7 +48,7 @@ BR.TrackMessages = L.Class.extend({
L.DomEvent.on(syncButton, 'click', this._toggleSyncMap, this);
},
update: function(polyline, segments) {
update: function (polyline, segments) {
var i,
messages,
columns,
@ -89,7 +89,7 @@ BR.TrackMessages = L.Class.extend({
// (^= minimum height with flexbox?)
scrollY: 50,
scrollX: true,
order: []
order: [],
});
// highlight track segment (graph edge) on row hover
@ -98,23 +98,21 @@ BR.TrackMessages = L.Class.extend({
$('#datatable tbody').on('click', 'tr', L.bind(this._toggleSelected, this));
},
show: function() {
show: function () {
this.active = true;
this.options.requestUpdate(this);
},
hide: function() {
hide: function () {
this.active = false;
},
_destroyTable: function() {
_destroyTable: function () {
var ele;
if ($.fn.DataTable.isDataTable('#datatable')) {
// destroy option too slow on update, really remove elements with destroy method
$('#datatable')
.DataTable()
.destroy(true);
$('#datatable').DataTable().destroy(true);
// recreate original table element, destroy removes all
ele = document.createElement('table');
@ -126,7 +124,7 @@ BR.TrackMessages = L.Class.extend({
return ele || document.getElementById('datatable');
},
_getColumns: function(headings, data) {
_getColumns: function (headings, data) {
var columns = [],
defaultOptions,
options,
@ -135,7 +133,7 @@ BR.TrackMessages = L.Class.extend({
for (k = 0; k < headings.length; k++) {
defaultOptions = {
title: headings[k],
visible: !emptyColumns[k]
visible: !emptyColumns[k],
};
options = L.extend(defaultOptions, this.columnOptions[headings[k]]);
columns.push(options);
@ -143,7 +141,7 @@ BR.TrackMessages = L.Class.extend({
return columns;
},
_getEmptyColumns: function(data) {
_getEmptyColumns: function (data) {
var empty = new Array(data[0].length),
i;
@ -151,8 +149,8 @@ BR.TrackMessages = L.Class.extend({
empty[i] = true;
}
data.forEach(function(row) {
row.forEach(function(val, i) {
data.forEach(function (row) {
row.forEach(function (val, i) {
empty[i] = empty[i] && !val;
});
});
@ -160,7 +158,7 @@ BR.TrackMessages = L.Class.extend({
return empty;
},
_getRowEdge: function(tr) {
_getRowEdge: function (tr) {
var row = this._table.row($(tr)),
trackLatLngs = this.trackPolyline.getLatLngs(),
startIndex = row.index() > 0 ? this.trackEdges.edges[row.index() - 1] : 0,
@ -170,7 +168,7 @@ BR.TrackMessages = L.Class.extend({
return L.polyline(edgeLatLngs, this.options.edgeStyle);
},
_handleHover: function(evt) {
_handleHover: function (evt) {
var tr = evt.currentTarget;
this._hoveredEdge = this._getRowEdge(tr).addTo(this._map);
@ -179,12 +177,12 @@ BR.TrackMessages = L.Class.extend({
}
},
_handleHoverOut: function(evt) {
_handleHoverOut: function (evt) {
this._map.removeLayer(this._hoveredEdge);
this._hoveredEdge = null;
},
_toggleSelected: function(evt) {
_toggleSelected: function (evt) {
var tr = evt.currentTarget;
if (tr.classList.toggle('selected')) {
@ -205,10 +203,10 @@ BR.TrackMessages = L.Class.extend({
}
},
_toggleSyncMap: function(evt) {
_toggleSyncMap: function (evt) {
var button = evt.currentTarget;
button.classList.toggle('active');
this.options.syncMap = !this.options.syncMap;
}
},
});

View file

@ -1,5 +1,5 @@
BR.TrackStats = L.Class.extend({
update: function(polyline, segments) {
update: function (polyline, segments) {
if (segments.length == 0) {
$('#stats-container').hide();
$('#stats-info').show();
@ -12,7 +12,7 @@ BR.TrackStats = L.Class.extend({
var stats = this.calcStats(polyline, segments),
length1 = L.Util.formatNum(stats.trackLength / 1000, 1).toLocaleString(),
length3 = L.Util.formatNum(stats.trackLength / 1000, 3).toLocaleString(undefined, {
minimumFractionDigits: 3
minimumFractionDigits: 3,
}),
formattedAscend = stats.filteredAscend.toLocaleString(),
formattedPlainAscend = stats.plainAscend.toLocaleString(),
@ -39,14 +39,14 @@ BR.TrackStats = L.Class.extend({
$('#meanenergy').html(meanEnergy);
},
calcStats: function(polyline, segments) {
calcStats: function (polyline, segments) {
var stats = {
trackLength: 0,
filteredAscend: 0,
plainAscend: 0,
totalTime: 0,
totalEnergy: 0,
cost: 0
cost: 0,
};
var i, props;
@ -61,5 +61,5 @@ BR.TrackStats = L.Class.extend({
}
return stats;
}
},
});