Enforce consistent indentation in javascript code

This commit is contained in:
Tom Hughes 2019-07-14 10:52:18 +01:00
parent 807750023a
commit c4c0e8105a
20 changed files with 160 additions and 153 deletions

View file

@ -26,8 +26,8 @@ var qs = require("querystring-component");
window.updateLinks = function (loc, zoom, layers, object) {
$(".geolink").each(function (index, link) {
var href = link.href.split(/[?#]/)[0],
args = qs.parse(link.search.substring(1)),
editlink = $(link).hasClass("editlink");
args = qs.parse(link.search.substring(1)),
editlink = $(link).hasClass("editlink");
delete args.node;
delete args.way;

View file

@ -27,8 +27,8 @@ document.addEventListener("DOMContentLoaded", function () {
id.map().on("move.embed", parent.$.throttle(250, function () {
if (id.inIntro()) return;
var zoom = ~~id.map().zoom(),
center = id.map().center(),
llz = { lon: center[0], lat: center[1], zoom: zoom };
center = id.map().center(),
llz = { lon: center[0], lat: center[1], zoom: zoom };
parent.updateLinks(llz, zoom);

View file

@ -234,7 +234,7 @@ $(document).ready(function () {
e.preventDefault();
var data = $(this).data(),
center = L.latLng(data.lat, data.lon);
center = L.latLng(data.lat, data.lon);
map.setView(center, data.zoom);
L.marker(center, { icon: OSM.getUserIcon() }).addTo(map);
@ -260,13 +260,13 @@ $(document).ready(function () {
if (object) query.select = object.type + object.id;
var iframe = $("<iframe>")
.hide()
.appendTo("body")
.attr("src", url + querystring.stringify(query))
.on("load", function () {
$(this).remove();
loaded = true;
});
.hide()
.appendTo("body")
.attr("src", url + querystring.stringify(query))
.on("load", function () {
$(this).remove();
loaded = true;
});
setTimeout(function () {
if (!loaded) {

View file

@ -1,7 +1,7 @@
OSM.Changeset = function (map) {
var page = {},
content = $("#sidebar_content"),
currentChangesetId;
content = $("#sidebar_content"),
currentChangesetId;
page.pushstate = page.popstate = function (path, id) {
OSM.loadSidebarContent(path, function () {

View file

@ -260,11 +260,11 @@ OSM.Directions = function (map) {
// Add each row
route.steps.forEach(function (step) {
var ll = step[0],
direction = step[1],
instruction = step[2],
dist = step[3],
lineseg = step[4];
var ll = step[0],
direction = step[1],
instruction = step[2],
dist = step[3],
lineseg = step[4];
if (dist < 5) {
dist = "";

View file

@ -43,9 +43,9 @@ OSM.Export = function (map) {
$("#maxlat").val(bounds.getNorth().toFixed(precision));
$("#export_overpass").attr("href",
"https://overpass-api.de/api/map?bbox=" +
$("#minlon").val() + "," + $("#minlat").val() + "," +
$("#maxlon").val() + "," + $("#maxlat").val());
"https://overpass-api.de/api/map?bbox=" +
$("#minlon").val() + "," + $("#minlat").val() + "," +
$("#maxlon").val() + "," + $("#maxlat").val());
}
function validateControls() {

View file

@ -71,7 +71,7 @@ OSM.History = function (map) {
});
var feedLink = $("link[type=\"application/atom+xml\"]"),
feedHref = feedLink.attr("href").split("?")[0];
feedHref = feedLink.attr("href").split("?")[0];
feedLink.attr("href", feedHref + "?bbox=" + data.bbox);
}
@ -123,8 +123,8 @@ OSM.History = function (map) {
for (var i = 0; i < changesets.length; ++i) {
var changeset = changesets[i],
rect = L.rectangle(changeset.bounds,
{ weight: 2, color: "#FF9500", opacity: 1, fillColor: "#FFFFAF", fillOpacity: 0 });
rect = L.rectangle(changeset.bounds,
{ weight: 2, color: "#FF9500", opacity: 1, fillColor: "#FFFFAF", fillOpacity: 0 });
rect.id = changeset.id;
rect.addTo(group);
}

View file

@ -1,10 +1,10 @@
OSM.NewNote = function (map) {
var noteLayer = map.noteLayer,
content = $("#sidebar_content"),
page = {},
addNoteButton = $(".control-note .control-button"),
newNote,
halo;
content = $("#sidebar_content"),
page = {},
addNoteButton = $(".control-note .control-button"),
newNote,
halo;
var noteIcons = {
"new": L.icon({

View file

@ -1,7 +1,7 @@
OSM.Note = function (map) {
var content = $("#sidebar_content"),
page = {},
halo, currentNote;
page = {},
halo, currentNote;
var noteIcons = {
"new": L.icon({
@ -39,7 +39,7 @@ OSM.Note = function (map) {
OSM.loadSidebarContent(path, function () {
initialize(function () {
var data = $(".details").data(),
latLng = L.latLng(data.coordinates.split(","));
latLng = L.latLng(data.coordinates.split(","));
if (!map.getBounds().contains(latLng)) moveToNote();
});
});
@ -71,7 +71,7 @@ OSM.Note = function (map) {
content.find("textarea").val("").trigger("input");
var data = $(".details").data(),
latLng = L.latLng(data.coordinates.split(","));
latLng = L.latLng(data.coordinates.split(","));
if (!map.hasLayer(halo)) {
halo = L.circleMarker(latLng, {
@ -97,7 +97,7 @@ OSM.Note = function (map) {
function moveToNote() {
var data = $(".details").data(),
latLng = L.latLng(data.coordinates.split(","));
latLng = L.latLng(data.coordinates.split(","));
if (!window.location.hash || window.location.hash.match(/^#?c[0-9]+$/)) {
OSM.router.withoutMoveListener(function () {

View file

@ -2,9 +2,9 @@
OSM.Query = function (map) {
var url = OSM.OVERPASS_URL,
queryButton = $(".control-query .control-button"),
uninterestingTags = ["source", "source_ref", "source:ref", "history", "attribution", "created_by", "tiger:county", "tiger:tlid", "tiger:upload_uuid", "KSJ2:curve_id", "KSJ2:lat", "KSJ2:lon", "KSJ2:coordinate", "KSJ2:filename", "note:ja"],
marker;
queryButton = $(".control-query .control-button"),
uninterestingTags = ["source", "source_ref", "source:ref", "history", "attribution", "created_by", "tiger:county", "tiger:tlid", "tiger:upload_uuid", "KSJ2:curve_id", "KSJ2:lat", "KSJ2:lon", "KSJ2:coordinate", "KSJ2:filename", "note:ja"],
marker;
var featureStyle = {
color: "#FF6200",
@ -103,7 +103,7 @@ OSM.Query = function (map) {
if (prefixes[key]) {
var first = value.substr(0, 1).toUpperCase(),
rest = value.substr(1).replace(/_/g, " ");
rest = value.substr(1).replace(/_/g, " ");
return first + rest;
}
@ -119,7 +119,7 @@ OSM.Query = function (map) {
function featureName(feature) {
var tags = feature.tags,
locales = I18n.locales.get();
locales = I18n.locales.get();
for (var i = 0; i < locales.length; i++) {
if (tags["name:" + locales[i]]) {
@ -249,11 +249,11 @@ OSM.Query = function (map) {
function compareSize(feature1, feature2) {
var width1 = feature1.bounds.maxlon - feature1.bounds.minlon,
height1 = feature1.bounds.maxlat - feature1.bounds.minlat,
area1 = width1 * height1,
width2 = feature2.bounds.maxlat - feature2.bounds.minlat,
height2 = feature2.bounds.maxlat - feature2.bounds.minlat,
area2 = width2 * height2;
height1 = feature1.bounds.maxlat - feature1.bounds.minlat,
area1 = width1 * height1,
width2 = feature2.bounds.maxlat - feature2.bounds.minlat,
height2 = feature2.bounds.maxlat - feature2.bounds.minlat,
area2 = width2 * height2;
return area1 - area2;
}
@ -280,15 +280,15 @@ OSM.Query = function (map) {
*/
function queryOverpass(lat, lng) {
var latlng = L.latLng(lat, lng).wrap(),
bounds = map.getBounds().wrap(),
bbox = bounds.getSouth() + "," + bounds.getWest() + "," + bounds.getNorth() + "," + bounds.getEast(),
radius = 10 * Math.pow(1.5, 19 - map.getZoom()),
around = "around:" + radius + "," + lat + "," + lng,
nodes = "node(" + around + ")",
ways = "way(" + around + ")",
relations = "relation(" + around + ")",
nearby = "(" + nodes + ";" + ways + ";);out tags geom(" + bbox + ");" + relations + ";out geom(" + bbox + ");",
isin = "is_in(" + lat + "," + lng + ")->.a;way(pivot.a);out tags bb;out ids geom(" + bbox + ");relation(pivot.a);out tags bb;";
bounds = map.getBounds().wrap(),
bbox = bounds.getSouth() + "," + bounds.getWest() + "," + bounds.getNorth() + "," + bounds.getEast(),
radius = 10 * Math.pow(1.5, 19 - map.getZoom()),
around = "around:" + radius + "," + lat + "," + lng,
nodes = "node(" + around + ")",
ways = "way(" + around + ")",
relations = "relation(" + around + ")",
nearby = "(" + nodes + ";" + ways + ";);out tags geom(" + bbox + ");" + relations + ";out geom(" + bbox + ");",
isin = "is_in(" + lat + "," + lng + ")->.a;way(pivot.a);out tags bb;out ids geom(" + bbox + ");relation(pivot.a);out tags bb;";
$("#sidebar_content .query-intro")
.hide();
@ -313,9 +313,9 @@ OSM.Query = function (map) {
function clickHandler(e) {
var precision = OSM.zoomPrecision(map.getZoom()),
latlng = e.latlng.wrap(),
lat = latlng.lat.toFixed(precision),
lng = latlng.lng.toFixed(precision);
latlng = e.latlng.wrap(),
lat = latlng.lat.toFixed(precision),
lng = latlng.lng.toFixed(precision);
OSM.router.route("/query?lat=" + lat + "&lon=" + lng);
}
@ -343,7 +343,7 @@ OSM.Query = function (map) {
page.load = function (path, noCentre) {
var params = querystring.parse(path.substring(path.indexOf("?") + 1)),
latlng = L.latLng(params.lat, params.lon);
latlng = L.latLng(params.lat, params.lon);
if (!window.location.hash && !noCentre && !map.getBounds().contains(latlng)) {
OSM.router.withoutMoveListener(function () {

View file

@ -33,7 +33,7 @@ OSM.Search = function (map) {
$(".describe_location").on("click", function (e) {
e.preventDefault();
var center = map.getCenter().wrap(),
precision = OSM.zoomPrecision(map.getZoom());
precision = OSM.zoomPrecision(map.getZoom());
OSM.router.route("/search?whereami=1&query=" + encodeURIComponent(
center.lat.toFixed(precision) + "," + center.lng.toFixed(precision)
));

View file

@ -65,13 +65,13 @@ L.OSM.key = function (options) {
.toggleClass("disabled", disabled)
.attr("data-original-title",
I18n.t(disabled ?
"javascripts.key.tooltip_disabled" :
"javascripts.key.tooltip"));
"javascripts.key.tooltip_disabled" :
"javascripts.key.tooltip"));
}
function update() {
var layer = map.getMapBaseLayerId(),
zoom = map.getZoom();
zoom = map.getZoom();
$(".mapkey-table-entry").each(function () {
var data = $(this).data();

View file

@ -84,9 +84,9 @@ L.OSM.layers = function (options) {
.appendTo(item);
var input = $("<input>")
.attr("type", "radio")
.prop("checked", map.hasLayer(layer))
.appendTo(label);
.attr("type", "radio")
.prop("checked", map.hasLayer(layer))
.appendTo(label);
label.append(layer.options.name);

View file

@ -115,8 +115,8 @@ L.OSM.Map = L.Map.extend({
}
var url = window.location.protocol + "//" + OSM.SERVER_URL + "/",
query = querystring.stringify(params),
hash = OSM.formatHash(this);
query = querystring.stringify(params),
hash = OSM.formatHash(this);
if (query) url += "?" + query;
if (hash) url += hash;
@ -126,19 +126,19 @@ L.OSM.Map = L.Map.extend({
getShortUrl: function (marker) {
var zoom = this.getZoom(),
latLng = marker && this.hasLayer(marker) ? marker.getLatLng().wrap() : this.getCenter().wrap(),
str = window.location.hostname.match(/^www\.openstreetmap\.org/i) ?
window.location.protocol + "//osm.org/go/" :
window.location.protocol + "//" + window.location.hostname + "/go/",
char_array = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_~",
x = Math.round((latLng.lng + 180.0) * ((1 << 30) / 90.0)),
y = Math.round((latLng.lat + 90.0) * ((1 << 30) / 45.0)),
// JavaScript only has to keep 32 bits of bitwise operators, so this has to be
// done in two parts. each of the parts c1/c2 has 30 bits of the total in it
// and drops the last 4 bits of the full 64 bit Morton code.
c1 = interlace(x >>> 17, y >>> 17), c2 = interlace((x >>> 2) & 0x7fff, (y >>> 2) & 0x7fff),
digit,
i;
latLng = marker && this.hasLayer(marker) ? marker.getLatLng().wrap() : this.getCenter().wrap(),
str = window.location.hostname.match(/^www\.openstreetmap\.org/i) ?
window.location.protocol + "//osm.org/go/" :
window.location.protocol + "//" + window.location.hostname + "/go/",
char_array = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_~",
x = Math.round((latLng.lng + 180.0) * ((1 << 30) / 90.0)),
y = Math.round((latLng.lat + 90.0) * ((1 << 30) / 45.0)),
// JavaScript only has to keep 32 bits of bitwise operators, so this has to be
// done in two parts. each of the parts c1/c2 has 30 bits of the total in it
// and drops the last 4 bits of the full 64 bit Morton code.
c1 = interlace(x >>> 17, y >>> 17), c2 = interlace((x >>> 2) & 0x7fff, (y >>> 2) & 0x7fff),
digit,
i;
for (i = 0; i < Math.ceil((zoom + 8) / 3.0) && i < 5; ++i) {
digit = (c1 >> (24 - (6 * i))) & 0x3f;

View file

@ -17,7 +17,7 @@ L.OSM.query = function (options) {
function update() {
var wasDisabled = link.hasClass("disabled"),
isDisabled = map.getZoom() < 14;
isDisabled = map.getZoom() < 14;
link
.toggleClass("disabled", isDisabled)
.attr("data-original-title", I18n.t(isDisabled ?

View file

@ -1,10 +1,10 @@
L.OSM.share = function (options) {
var control = L.control(options),
marker = L.marker([0, 0], { draggable: true }),
locationFilter = new L.LocationFilter({
enableButton: false,
adjustButton: false
});
marker = L.marker([0, 0], { draggable: true }),
locationFilter = new L.LocationFilter({
enableButton: false,
adjustButton: false
});
control.onAdd = function (map) {
var $container = $("<div>")
@ -364,9 +364,9 @@ L.OSM.share = function (options) {
}
var scale = $("#mapnik_scale").val(),
size = L.bounds(L.CRS.EPSG3857.project(bounds.getSouthWest()),
L.CRS.EPSG3857.project(bounds.getNorthEast())).getSize(),
maxScale = Math.floor(Math.sqrt(size.x * size.y / 0.3136));
size = L.bounds(L.CRS.EPSG3857.project(bounds.getSouthWest()),
L.CRS.EPSG3857.project(bounds.getNorthEast())).getSize(),
maxScale = Math.floor(Math.sqrt(size.x * size.y / 0.3136));
$("#mapnik_minlon").val(bounds.getWest());
$("#mapnik_minlat").val(bounds.getSouth());
@ -396,11 +396,11 @@ L.OSM.share = function (options) {
function getScale() {
var bounds = map.getBounds(),
centerLat = bounds.getCenter().lat,
halfWorldMeters = 6378137 * Math.PI * Math.cos(centerLat * Math.PI / 180),
meters = halfWorldMeters * (bounds.getEast() - bounds.getWest()) / 180,
pixelsPerMeter = map.getSize().x / meters,
metersPerPixel = 1 / (92 * 39.3701);
centerLat = bounds.getCenter().lat,
halfWorldMeters = 6378137 * Math.PI * Math.cos(centerLat * Math.PI / 180),
meters = halfWorldMeters * (bounds.getEast() - bounds.getWest()) / 180,
pixelsPerMeter = map.getSize().x / meters,
metersPerPixel = 1 / (92 * 39.3701);
return Math.round(1 / (pixelsPerMeter * metersPerPixel));
}

View file

@ -1,9 +1,9 @@
L.OSM.sidebar = function (selector) {
var control = {},
sidebar = $(selector),
current = $(),
currentButton = $(),
map;
sidebar = $(selector),
current = $(),
currentButton = $(),
map;
control.addTo = function (_) {
map = _;

View file

@ -1,72 +1,72 @@
L.OSM.Zoom = L.Control.extend({
options: {
position: "topright"
},
options: {
position: "topright"
},
onAdd: function (map) {
var zoomName = "zoom",
container = L.DomUtil.create("div", zoomName);
onAdd: function (map) {
var zoomName = "zoom",
container = L.DomUtil.create("div", zoomName);
this._map = map;
this._map = map;
this._zoomInButton = this._createButton(
"", I18n.t("javascripts.map.zoom.in"), zoomName + "in", container, this._zoomIn, this);
this._zoomOutButton = this._createButton(
"", I18n.t("javascripts.map.zoom.out"), zoomName + "out", container, this._zoomOut, this);
this._zoomInButton = this._createButton(
"", I18n.t("javascripts.map.zoom.in"), zoomName + "in", container, this._zoomIn, this);
this._zoomOutButton = this._createButton(
"", I18n.t("javascripts.map.zoom.out"), zoomName + "out", container, this._zoomOut, this);
map.on("zoomend zoomlevelschange", this._updateDisabled, this);
map.on("zoomend zoomlevelschange", this._updateDisabled, this);
return container;
},
return container;
},
onRemove: function (map) {
map.off("zoomend zoomlevelschange", this._updateDisabled, this);
},
onRemove: function (map) {
map.off("zoomend zoomlevelschange", this._updateDisabled, this);
},
_zoomIn: function (e) {
this._map.zoomIn(e.shiftKey ? 3 : 1);
},
_zoomIn: function (e) {
this._map.zoomIn(e.shiftKey ? 3 : 1);
},
_zoomOut: function (e) {
this._map.zoomOut(e.shiftKey ? 3 : 1);
},
_zoomOut: function (e) {
this._map.zoomOut(e.shiftKey ? 3 : 1);
},
_createButton: function (html, title, className, container, fn, context) {
var link = L.DomUtil.create("a", "control-button " + className, container);
link.innerHTML = html;
link.href = "#";
link.title = title;
_createButton: function (html, title, className, container, fn, context) {
var link = L.DomUtil.create("a", "control-button " + className, container);
link.innerHTML = html;
link.href = "#";
link.title = title;
L.DomUtil.create("span", "icon " + className, link);
L.DomUtil.create("span", "icon " + className, link);
var stop = L.DomEvent.stopPropagation;
var stop = L.DomEvent.stopPropagation;
L.DomEvent
.on(link, "click", stop)
.on(link, "mousedown", stop)
.on(link, "dblclick", stop)
.on(link, "click", L.DomEvent.preventDefault)
.on(link, "click", fn, context);
L.DomEvent
.on(link, "click", stop)
.on(link, "mousedown", stop)
.on(link, "dblclick", stop)
.on(link, "click", L.DomEvent.preventDefault)
.on(link, "click", fn, context);
return link;
},
return link;
},
_updateDisabled: function () {
var map = this._map,
className = "disabled";
_updateDisabled: function () {
var map = this._map,
className = "disabled";
L.DomUtil.removeClass(this._zoomInButton, className);
L.DomUtil.removeClass(this._zoomOutButton, className);
L.DomUtil.removeClass(this._zoomInButton, className);
L.DomUtil.removeClass(this._zoomOutButton, className);
if (map._zoom === map.getMinZoom()) {
L.DomUtil.addClass(this._zoomOutButton, className);
}
if (map._zoom === map.getMaxZoom()) {
L.DomUtil.addClass(this._zoomInButton, className);
}
}
if (map._zoom === map.getMinZoom()) {
L.DomUtil.addClass(this._zoomOutButton, className);
}
if (map._zoom === map.getMaxZoom()) {
L.DomUtil.addClass(this._zoomInButton, className);
}
}
});
L.OSM.zoom = function (options) {
return new L.OSM.Zoom(options);
return new L.OSM.Zoom(options);
};

View file

@ -96,8 +96,8 @@ OSM.Router = function (map, rts) {
};
var currentPath = window.location.pathname.replace(/(.)\/$/, "$1") + window.location.search,
currentRoute = routes.recognize(currentPath),
currentHash = location.hash || OSM.formatHash(map);
currentRoute = routes.recognize(currentPath),
currentHash = location.hash || OSM.formatHash(map);
var router = {};
@ -105,7 +105,7 @@ OSM.Router = function (map, rts) {
$(window).on("popstate", function (e) {
if (!e.originalEvent.state) return; // Is it a real popstate event or just a hash change?
var path = window.location.pathname + window.location.search,
route = routes.recognize(path);
route = routes.recognize(path);
if (path === currentPath) return;
currentRoute.run("unload", null, route === currentRoute);
currentPath = path;
@ -116,7 +116,7 @@ OSM.Router = function (map, rts) {
router.route = function (url) {
var path = url.replace(/#.*/, ""),
route = routes.recognize(path);
route = routes.recognize(path);
if (!route) return false;
currentRoute.run("unload", null, route === currentRoute);
var state = OSM.parseHash(url);

View file

@ -33,6 +33,13 @@
"eol-last": "error",
"eqeqeq": ["error", "smart"],
"func-call-spacing": "error",
"indent": ["error", 2, {
"SwitchCase": 1,
"VariableDeclarator": "first",
"FunctionDeclaration": { "parameters": "first" },
"FunctionExpression": { "parameters": "first" },
"CallExpression": { "arguments": "first" }
}],
"key-spacing": "error",
"keyword-spacing": "error",
"no-alert": "warn",