Increase prettier maxwidth to 120
This commit is contained in:
parent
ce9e34283b
commit
d31be926d2
27 changed files with 248 additions and 956 deletions
|
|
@ -8,19 +8,12 @@ BR.Export = L.Class.extend({
|
|||
this.tracknameAllowedChars = BR.conf.tracknameAllowedChars;
|
||||
|
||||
if (this.tracknameAllowedChars) {
|
||||
this.tracknameMessage = document.getElementById(
|
||||
'trackname-message'
|
||||
);
|
||||
var patternRegex = new RegExp(
|
||||
'[' + this.tracknameAllowedChars + ']+'
|
||||
);
|
||||
this.tracknameMessage = document.getElementById('trackname-message');
|
||||
var patternRegex = new RegExp('[' + this.tracknameAllowedChars + ']+');
|
||||
|
||||
// warn about special characters getting removed by server quick fix (#194)
|
||||
trackname.pattern = patternRegex.toString().slice(1, -1);
|
||||
trackname.addEventListener(
|
||||
'input',
|
||||
L.bind(this._validationMessage, this)
|
||||
);
|
||||
trackname.addEventListener('input', L.bind(this._validationMessage, this));
|
||||
}
|
||||
|
||||
this.exportButton.on('click', L.bind(this._generateTrackname, this));
|
||||
|
|
@ -41,37 +34,14 @@ BR.Export = L.Class.extend({
|
|||
|
||||
_export: function() {
|
||||
var exportForm = document.forms['export'];
|
||||
var format =
|
||||
exportForm['format'].value ||
|
||||
$('#export-format input:radio:checked').val();
|
||||
var format = exportForm['format'].value || $('#export-format input:radio:checked').val();
|
||||
var name = encodeURIComponent(exportForm['trackname'].value);
|
||||
var includeWaypoints = exportForm['include-waypoints'].checked;
|
||||
|
||||
var uri = this.router.getUrl(
|
||||
this.latLngs,
|
||||
format,
|
||||
name,
|
||||
includeWaypoints
|
||||
);
|
||||
var uri = this.router.getUrl(this.latLngs, format, name, includeWaypoints);
|
||||
|
||||
var evt = document.createEvent('MouseEvents');
|
||||
evt.initMouseEvent(
|
||||
'click',
|
||||
true,
|
||||
true,
|
||||
window,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
0,
|
||||
null
|
||||
);
|
||||
evt.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
||||
var link = document.createElement('a');
|
||||
link.href = uri;
|
||||
link.dispatchEvent(evt);
|
||||
|
|
@ -79,16 +49,12 @@ BR.Export = L.Class.extend({
|
|||
|
||||
_validationMessage: function() {
|
||||
var trackname = this.trackname;
|
||||
var replaceRegex = new RegExp(
|
||||
'[^' + this.tracknameAllowedChars + ']',
|
||||
'g'
|
||||
);
|
||||
var replaceRegex = new RegExp('[^' + this.tracknameAllowedChars + ']', 'g');
|
||||
|
||||
if (trackname.validity.patternMismatch) {
|
||||
var replaced = trackname.value.replace(replaceRegex, '');
|
||||
var patternStr = this.tracknameAllowedChars.replace(/\\/g, '');
|
||||
this.tracknameMessage.textContent =
|
||||
'[' + patternStr + '] --> ' + replaced;
|
||||
this.tracknameMessage.textContent = '[' + patternStr + '] --> ' + replaced;
|
||||
} else {
|
||||
this.tracknameMessage.textContent = '';
|
||||
}
|
||||
|
|
@ -102,8 +68,7 @@ BR.Export = L.Class.extend({
|
|||
this._getCityAtPosition(
|
||||
this.latLngs[this.latLngs.length - 1],
|
||||
L.bind(function(to) {
|
||||
var distance = document.getElementById('distance')
|
||||
.innerHTML;
|
||||
var distance = document.getElementById('distance').innerHTML;
|
||||
if (this.tracknameAllowedChars) {
|
||||
distance = distance.replace(',', '.'); // temp. fix (#202)
|
||||
}
|
||||
|
|
@ -115,17 +80,16 @@ BR.Export = L.Class.extend({
|
|||
distance: distance
|
||||
});
|
||||
} else {
|
||||
trackname.value = i18next.t(
|
||||
'export.route-from-to',
|
||||
{ from: from, to: to, distance: distance }
|
||||
);
|
||||
trackname.value = i18next.t('export.route-from-to', {
|
||||
from: from,
|
||||
to: to,
|
||||
distance: distance
|
||||
});
|
||||
}
|
||||
|
||||
if (this.tracknameAllowedChars) {
|
||||
// temp. fix: replace and remove characters that will get removed by server quick fix (#194)
|
||||
trackname.value = trackname.value
|
||||
.replace(/[>)]/g, '')
|
||||
.replace(/ \(/g, ' - ');
|
||||
trackname.value = trackname.value.replace(/[>)]/g, '').replace(/ \(/g, ' - ');
|
||||
this._validationMessage();
|
||||
}
|
||||
}, this)
|
||||
|
|
@ -144,17 +108,9 @@ BR.Export = L.Class.extend({
|
|||
L.bind(function(err, response) {
|
||||
try {
|
||||
var addr = JSON.parse(response).address;
|
||||
cb(
|
||||
addr.village ||
|
||||
addr.town ||
|
||||
addr.hamlet ||
|
||||
addr.city_district ||
|
||||
addr.city
|
||||
);
|
||||
cb(addr.village || addr.town || addr.hamlet || addr.city_district || addr.city);
|
||||
} catch (err) {
|
||||
BR.message.showError(
|
||||
'Error getting position city "' + lonlat + '": ' + err
|
||||
);
|
||||
BR.message.showError('Error getting position city "' + lonlat + '": ' + err);
|
||||
return cb(null);
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -46,18 +46,9 @@ BR.Layers = L.Class.extend({
|
|||
for (var l in overlays) this._layers[l] = [overlays[l], true];
|
||||
for (var l in baseLayers) this._layers[l] = [baseLayers[l], false];
|
||||
|
||||
L.DomUtil.get('custom_layers_add_base').onclick = L.bind(
|
||||
this._addBaseLayer,
|
||||
this
|
||||
);
|
||||
L.DomUtil.get('custom_layers_add_overlay').onclick = L.bind(
|
||||
this._addOverlay,
|
||||
this
|
||||
);
|
||||
L.DomUtil.get('custom_layers_remove').onclick = L.bind(
|
||||
this._remove,
|
||||
this
|
||||
);
|
||||
L.DomUtil.get('custom_layers_add_base').onclick = L.bind(this._addBaseLayer, this);
|
||||
L.DomUtil.get('custom_layers_add_overlay').onclick = L.bind(this._addOverlay, this);
|
||||
L.DomUtil.get('custom_layers_remove').onclick = L.bind(this._remove, this);
|
||||
|
||||
this._loadLayers();
|
||||
this._loadTable();
|
||||
|
|
@ -95,8 +86,7 @@ BR.Layers = L.Class.extend({
|
|||
_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);
|
||||
if (layer_name.length > 0 && layer_url.length > 0) this._addLayer(layer_name, layer_url, isOverlay);
|
||||
},
|
||||
|
||||
_addBaseLayer: function(evt) {
|
||||
|
|
|
|||
|
|
@ -4,12 +4,7 @@ BR.LayersTab = BR.ControlLayers.extend({
|
|||
saveLayers: [],
|
||||
|
||||
initialize: function(layersConfig, baseLayers, overlays, options) {
|
||||
L.Control.Layers.prototype.initialize.call(
|
||||
this,
|
||||
baseLayers,
|
||||
overlays,
|
||||
options
|
||||
);
|
||||
L.Control.Layers.prototype.initialize.call(this, baseLayers, overlays, options);
|
||||
|
||||
this.layersConfig = layersConfig;
|
||||
},
|
||||
|
|
@ -30,21 +25,13 @@ BR.LayersTab = BR.ControlLayers.extend({
|
|||
onAdd: function(map) {
|
||||
BR.ControlLayers.prototype.onAdd.call(this, map);
|
||||
|
||||
map.on(
|
||||
'baselayerchange overlayadd overlayremove',
|
||||
this.storeActiveLayers,
|
||||
this
|
||||
);
|
||||
map.on('baselayerchange overlayadd overlayremove', this.storeActiveLayers, this);
|
||||
},
|
||||
|
||||
onRemove: function(map) {
|
||||
BR.ControlLayers.prototype.onRemove.call(this, map);
|
||||
|
||||
map.off(
|
||||
'baselayerchange overlayadd overlayremove',
|
||||
this.storeActiveLayers,
|
||||
this
|
||||
);
|
||||
map.off('baselayerchange overlayadd overlayremove', this.storeActiveLayers, this);
|
||||
},
|
||||
|
||||
initOpacitySlider: function(map) {
|
||||
|
|
@ -57,19 +44,14 @@ BR.LayersTab = BR.ControlLayers.extend({
|
|||
title: i18next.t('layers.opacity-slider'),
|
||||
callback: function(opacity) {
|
||||
for (var i = 0; i < self._layers.length; i++) {
|
||||
if (
|
||||
!self._layers[i].overlay ||
|
||||
!map.hasLayer(self._layers[i].layer)
|
||||
) {
|
||||
if (!self._layers[i].overlay || !map.hasLayer(self._layers[i].layer)) {
|
||||
continue;
|
||||
}
|
||||
self._layers[i].layer.setOpacity(opacity);
|
||||
}
|
||||
}
|
||||
});
|
||||
L.DomUtil.get(
|
||||
'leaflet-control-layers-overlays-opacity-slider'
|
||||
).appendChild(overlayOpacitySlider.getElement());
|
||||
L.DomUtil.get('leaflet-control-layers-overlays-opacity-slider').appendChild(overlayOpacitySlider.getElement());
|
||||
},
|
||||
|
||||
initButtons: function() {
|
||||
|
|
@ -95,15 +77,9 @@ BR.LayersTab = BR.ControlLayers.extend({
|
|||
};
|
||||
|
||||
L.DomUtil.get('expand_tree_button').onclick = L.bind(expandTree, this);
|
||||
L.DomUtil.get('collapse_tree_button').onclick = L.bind(
|
||||
collapseTree,
|
||||
this
|
||||
);
|
||||
L.DomUtil.get('collapse_tree_button').onclick = L.bind(collapseTree, this);
|
||||
|
||||
L.DomUtil.get('optional_layers_button').onclick = L.bind(
|
||||
toggleOptionalLayers,
|
||||
this
|
||||
);
|
||||
L.DomUtil.get('optional_layers_button').onclick = L.bind(toggleOptionalLayers, this);
|
||||
},
|
||||
|
||||
initJsTree: function() {
|
||||
|
|
@ -225,10 +201,7 @@ 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)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,10 +12,7 @@ BR.Message = L.Class.extend({
|
|||
|
||||
_show: function(msg, type) {
|
||||
var ele = L.DomUtil.get(this.id),
|
||||
iconClass =
|
||||
type === 'warning'
|
||||
? 'fa-exclamation-triangle'
|
||||
: 'fa-times-circle',
|
||||
iconClass = type === 'warning' ? 'fa-exclamation-triangle' : 'fa-times-circle',
|
||||
alertClass = type === 'warning' ? 'alert-warning' : 'alert-danger';
|
||||
|
||||
L.DomEvent.disableClickPropagation(ele);
|
||||
|
|
|
|||
|
|
@ -11,12 +11,8 @@ BR.OpacitySlider = L.Class.extend({
|
|||
initialize: function(options) {
|
||||
L.setOptions(this, options);
|
||||
|
||||
var input = (this.input = $(
|
||||
'<input id="slider-' + this.options.id + '" type="text"/>'
|
||||
)),
|
||||
item = BR.Util.localStorageAvailable()
|
||||
? localStorage['opacitySliderValue' + this.options.id]
|
||||
: null,
|
||||
var input = (this.input = $('<input id="slider-' + this.options.id + '" type="text"/>')),
|
||||
item = BR.Util.localStorageAvailable() ? localStorage['opacitySliderValue' + this.options.id] : null,
|
||||
value = item ? parseInt(item) : this.options.defaultValue * 100,
|
||||
minOpacity = (BR.conf.minOpacity || 0) * 100;
|
||||
|
||||
|
|
@ -41,9 +37,7 @@ BR.OpacitySlider = L.Class.extend({
|
|||
})
|
||||
.on('slideStop', { self: this }, function(evt) {
|
||||
if (BR.Util.localStorageAvailable()) {
|
||||
localStorage[
|
||||
'opacitySliderValue' + evt.data.self.options.id
|
||||
] = evt.value;
|
||||
localStorage['opacitySliderValue' + evt.data.self.options.id] = evt.value;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -13,10 +13,7 @@ BR.OpacitySliderControl = L.Control.extend({
|
|||
if (BR.Util.localStorageAvailable()) {
|
||||
var value = localStorage.getItem('opacitySliderValue');
|
||||
if (value !== null) {
|
||||
localStorage.setItem(
|
||||
'opacitySliderValue' + this.options.id,
|
||||
value
|
||||
);
|
||||
localStorage.setItem('opacitySliderValue' + this.options.id, value);
|
||||
localStorage.removeItem('opacitySliderValue');
|
||||
}
|
||||
}
|
||||
|
|
@ -31,11 +28,7 @@ BR.OpacitySliderControl = L.Control.extend({
|
|||
|
||||
var removeStopClickListeners = function() {
|
||||
document.removeEventListener('click', stopClickAfterSlide, true);
|
||||
document.removeEventListener(
|
||||
'mousedown',
|
||||
removeStopClickListeners,
|
||||
true
|
||||
);
|
||||
document.removeEventListener('mousedown', removeStopClickListeners, true);
|
||||
};
|
||||
|
||||
slider.input
|
||||
|
|
@ -52,11 +45,7 @@ BR.OpacitySliderControl = L.Control.extend({
|
|||
document.addEventListener('click', stopClickAfterSlide, true);
|
||||
// Firefox does not fire click event in this case, so make sure stop listener
|
||||
// is always removed on next mousedown.
|
||||
document.addEventListener(
|
||||
'mousedown',
|
||||
removeStopClickListeners,
|
||||
true
|
||||
);
|
||||
document.addEventListener('mousedown', removeStopClickListeners, true);
|
||||
});
|
||||
|
||||
return container;
|
||||
|
|
|
|||
|
|
@ -39,22 +39,14 @@ BR.Profile = L.Evented.extend({
|
|||
profileUrl,
|
||||
L.bind(function(err, profileText) {
|
||||
if (err) {
|
||||
console.warn(
|
||||
'Error getting profile from "' +
|
||||
profileUrl +
|
||||
'": ' +
|
||||
err
|
||||
);
|
||||
console.warn('Error getting profile from "' + profileUrl + '": ' + err);
|
||||
return;
|
||||
}
|
||||
|
||||
this.cache[profileName] = profileText;
|
||||
|
||||
// don't set when option has changed while loading
|
||||
if (
|
||||
!this.profileName ||
|
||||
this.profileName === profileName
|
||||
) {
|
||||
if (!this.profileName || this.profileName === profileName) {
|
||||
this._setValue(profileText);
|
||||
}
|
||||
}, this)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
BR.RoutingOptions = L.Evented.extend({
|
||||
initialize: function() {
|
||||
$('#profile-alternative').on(
|
||||
'changed.bs.select',
|
||||
this._getChangeHandler()
|
||||
);
|
||||
$('#profile-alternative').on('changed.bs.select', this._getChangeHandler());
|
||||
|
||||
// build option list from config
|
||||
var profiles = BR.conf.profiles;
|
||||
|
|
@ -55,12 +52,8 @@ BR.RoutingOptions = L.Evented.extend({
|
|||
|
||||
setOptions: function(options) {
|
||||
var values = [
|
||||
options.profile
|
||||
? options.profile
|
||||
: $('#profile option:selected').val(),
|
||||
options.alternative
|
||||
? options.alternative
|
||||
: $('#alternative option:selected').val()
|
||||
options.profile ? options.profile : $('#profile option:selected').val(),
|
||||
options.alternative ? options.alternative : $('#alternative option:selected').val()
|
||||
];
|
||||
$('.selectpicker').selectpicker('val', values);
|
||||
this.refreshUI();
|
||||
|
|
|
|||
|
|
@ -74,10 +74,7 @@ BR.TrackMessages = L.Class.extend({
|
|||
|
||||
// highlight track segment (graph edge) on row hover
|
||||
this._setEdges(polyline, segments);
|
||||
$('#datatable tbody tr').hover(
|
||||
L.bind(this._handleHover, this),
|
||||
L.bind(this._handleHoverOut, this)
|
||||
);
|
||||
$('#datatable tbody tr').hover(L.bind(this._handleHover, this), L.bind(this._handleHoverOut, this));
|
||||
},
|
||||
|
||||
show: function() {
|
||||
|
|
@ -198,10 +195,7 @@ BR.TrackMessages = L.Class.extend({
|
|||
endIndex = this._edges[row.index()],
|
||||
edgeLatLngs = trackLatLngs.slice(startIndex, endIndex + 1);
|
||||
|
||||
this._selectedEdge = L.polyline(
|
||||
edgeLatLngs,
|
||||
this.options.edgeStyle
|
||||
).addTo(this._map);
|
||||
this._selectedEdge = L.polyline(edgeLatLngs, this.options.edgeStyle).addTo(this._map);
|
||||
},
|
||||
|
||||
_handleHoverOut: function(evt) {
|
||||
|
|
|
|||
|
|
@ -14,36 +14,19 @@ 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(),
|
||||
length1 = L.Util.formatNum(stats.trackLength / 1000, 1).toLocaleString(),
|
||||
length3 = L.Util.formatNum(stats.trackLength / 1000, 3).toLocaleString(),
|
||||
formattedAscend = stats.filteredAscend.toLocaleString(),
|
||||
formattedPlainAscend = stats.plainAscend.toLocaleString(),
|
||||
formattedCost = stats.cost.toLocaleString(),
|
||||
meanCostFactor = stats.trackLength
|
||||
? L.Util.formatNum(
|
||||
stats.cost / stats.trackLength,
|
||||
2
|
||||
).toLocaleString()
|
||||
? L.Util.formatNum(stats.cost / stats.trackLength, 2).toLocaleString()
|
||||
: '0',
|
||||
formattedTime =
|
||||
Math.trunc(stats.totalTime / 3600) +
|
||||
':' +
|
||||
('0' + Math.trunc((stats.totalTime % 3600) / 60)).slice(-2),
|
||||
formattedEnergy = L.Util.formatNum(
|
||||
stats.totalEnergy / 3600000,
|
||||
2
|
||||
).toLocaleString(),
|
||||
Math.trunc(stats.totalTime / 3600) + ':' + ('0' + Math.trunc((stats.totalTime % 3600) / 60)).slice(-2),
|
||||
formattedEnergy = L.Util.formatNum(stats.totalEnergy / 3600000, 2).toLocaleString(),
|
||||
meanEnergy = stats.trackLength
|
||||
? L.Util.formatNum(
|
||||
stats.totalEnergy / 36 / stats.trackLength,
|
||||
2
|
||||
).toLocaleString()
|
||||
? L.Util.formatNum(stats.totalEnergy / 36 / stats.trackLength, 2).toLocaleString()
|
||||
: '0';
|
||||
|
||||
$('#distance').html(length1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue