Fix some JSHint complaints

This commit is contained in:
Tom Hughes 2015-02-23 20:47:38 +00:00
parent 6671a934bf
commit 1596713871
22 changed files with 96 additions and 93 deletions

View file

@ -63,10 +63,10 @@ function updateLinks(loc, zoom, layers, object) {
args = querystring.parse(link.search.substring(1)),
editlink = $(link).hasClass("editlink");
delete args['node'];
delete args['way'];
delete args['relation'];
delete args['changeset'];
delete args.node;
delete args.way;
delete args.relation;
delete args.changeset;
if (object && editlink) {
args[object.type] = object.id;
@ -108,7 +108,7 @@ function escapeHTML(string) {
'"': '"',
"'": '''
};
return string == null ? '' : (string + '').replace(/[&<>"']/g, function(match) {
return string === null ? '' : (string + '').replace(/[&<>"']/g, function(match) {
return htmlEscapes[match];
});
}

View file

@ -14,15 +14,15 @@ window.onload = function () {
var map = L.map("map");
map.attributionControl.setPrefix('');
if (!args.layer || args.layer == "mapnik" || args.layer == "osmarender") {
if (!args.layer || args.layer === "mapnik" || args.layer === "osmarender") {
new L.OSM.Mapnik().addTo(map);
} else if (args.layer == "cyclemap" || args.layer == "cycle map") {
} else if (args.layer === "cyclemap" || args.layer === "cycle map") {
new L.OSM.CycleMap().addTo(map);
} else if (args.layer == "transportmap") {
} else if (args.layer === "transportmap") {
new L.OSM.TransportMap().addTo(map);
} else if (args.layer == "mapquest") {
} else if (args.layer === "mapquest") {
new L.OSM.MapQuestOpen().addTo(map);
} else if (args.layer == "hot") {
} else if (args.layer === "hot") {
new L.OSM.HOT().addTo(map);
}
@ -39,7 +39,7 @@ window.onload = function () {
if (args.bbox) {
var bbox = args.bbox.split(',');
map.fitBounds([L.latLng(bbox[1], bbox[0]),
L.latLng(bbox[3], bbox[2])])
L.latLng(bbox[3], bbox[2])]);
} else {
map.fitWorld();
}

View file

@ -34,9 +34,9 @@ $(document).ready(function () {
// IE<10 doesn't respect Vary: X-Requested-With header, so
// prevent caching the XHR response as a full-page URL.
if (path.indexOf('?') >= 0) {
path += '&xhr=1'
path += '&xhr=1';
} else {
path += '?xhr=1'
path += '?xhr=1';
}
$('#sidebar_content')
@ -136,7 +136,7 @@ $(document).ready(function () {
L.control.scale()
.addTo(map);
if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
if (OSM.STATUS !== 'api_offline' && OSM.STATUS !== 'database_offline') {
initializeNotes(map);
if (params.layers.indexOf(map.noteLayer.options.code) >= 0) {
map.addLayer(map.noteLayer);
@ -164,7 +164,7 @@ $(document).ready(function () {
$.cookie("_osm_location", OSM.locationCookie(map), { expires: expiry, path: "/" });
});
if ($.cookie('_osm_welcome') == 'hide') {
if ($.cookie('_osm_welcome') === 'hide') {
$('.welcome').hide();
}
@ -263,7 +263,7 @@ $(document).ready(function () {
};
function addObject(type, id, center) {
var bounds = map.addObject({type: type, id: parseInt(id)}, function(bounds) {
map.addObject({type: type, id: parseInt(id)}, function(bounds) {
if (!window.location.hash && bounds.isValid() &&
(center || !map.getBounds().contains(bounds))) {
OSM.router.withoutMoveListener(function () {
@ -300,7 +300,7 @@ $(document).ready(function () {
"/query": OSM.Query(map)
});
if (OSM.preferred_editor == "remote" && document.location.pathname == "/edit") {
if (OSM.preferred_editor === "remote" && document.location.pathname === "/edit") {
remoteEditHandler(map.getBounds(), params.object);
OSM.router.setCurrentPath("/");
}

View file

@ -17,7 +17,7 @@ OSM.Changeset = function (map) {
};
function addChangeset(id, center) {
var bounds = map.addObject({type: 'changeset', id: parseInt(id)}, function(bounds) {
map.addObject({type: 'changeset', id: parseInt(id)}, function(bounds) {
if (!window.location.hash && bounds.isValid() &&
(center || !map.getBounds().contains(bounds))) {
OSM.router.withoutMoveListener(function () {
@ -28,7 +28,10 @@ OSM.Changeset = function (map) {
}
function updateChangeset(form, method, url, include_data) {
var data;
$(form).find("input[type=submit]").prop("disabled", true);
if(include_data) {
data = {text: $(form.text).val()};
} else {
@ -62,7 +65,7 @@ OSM.Changeset = function (map) {
content.find("textarea").on("input", function (e) {
var form = e.target.form;
if ($(e.target).val() == "") {
if ($(e.target).val() === "") {
$(form.comment).prop("disabled", true);
} else {
$(form.comment).prop("disabled", false);
@ -70,11 +73,11 @@ OSM.Changeset = function (map) {
});
content.find("textarea").val('').trigger("input");
};
}
page.unload = function() {
map.removeObject();
};
return page;
};
};

View file

@ -42,7 +42,7 @@ OSM.Directions = function (map) {
});
endpoint.marker.on('drag dragend', function (e) {
dragging = (e.type == 'drag');
dragging = (e.type === 'drag');
if (dragging && !chosenEngine.draggable) return;
if (dragging && awaitingRoute) return;
endpoint.setLatLng(e.target.getLatLng());
@ -54,7 +54,7 @@ OSM.Directions = function (map) {
input.on("change", function (e) {
// make text the same in both text boxes
var value = e.target.value;
endpoint.setValue(value)
endpoint.setValue(value);
});
endpoint.setValue = function(value) {
@ -62,7 +62,7 @@ OSM.Directions = function (map) {
delete endpoint.latlng;
input.val(value);
endpoint.getGeocode();
}
};
endpoint.getGeocode = function() {
// if no one has entered a value yet, then we can't geocode, so don't
@ -76,7 +76,7 @@ OSM.Directions = function (map) {
$.getJSON(document.location.protocol + OSM.NOMINATIM_URL + 'search?q=' + encodeURIComponent(endpoint.value) + '&format=json', function (json) {
endpoint.awaitingGeocode = false;
endpoint.hasGeocode = true;
if (json.length == 0) {
if (json.length === 0) {
alert(I18n.t('javascripts.directions.errors.no_place'));
return;
}
@ -93,7 +93,7 @@ OSM.Directions = function (map) {
getRoute();
}
});
}
};
endpoint.setLatLng = function (ll) {
var precision = OSM.zoomPrecision(map.getZoom());
@ -137,7 +137,7 @@ OSM.Directions = function (map) {
function setEngine(id) {
engines.forEach(function(engine, i) {
if (engine.id == id) {
if (engine.id === id) {
chosenEngine = engine;
select.val(i);
}
@ -378,7 +378,7 @@ OSM.Directions = function (map) {
OSM.Directions.engines = [];
OSM.Directions.addEngine = function (engine, supportsHTTPS) {
if (document.location.protocol == "http:" || supportsHTTPS) {
if (document.location.protocol === "http:" || supportsHTTPS) {
OSM.Directions.engines.push(engine);
}
};

View file

@ -19,12 +19,12 @@ function GraphHopperEngine(id, vehicleParam) {
getRoute: function (points, callback) {
// documentation
// https://github.com/graphhopper/graphhopper/blob/master/docs/web/api-doc.md
var url = document.location.protocol + "//graphhopper.com/api/1/route?"
+ vehicleParam
+ "&locale=" + I18n.currentLocale()
+ "&key=LijBPDQGfu7Iiq80w3HzwB4RUDJbMbhs6BU0dEnn"
+ "&type=jsonp"
+ "&instructions=true";
var url = document.location.protocol + "//graphhopper.com/api/1/route?" +
vehicleParam +
"&locale=" + I18n.currentLocale() +
"&key=LijBPDQGfu7Iiq80w3HzwB4RUDJbMbhs6BU0dEnn" +
"&type=jsonp" +
"&instructions=true";
for (var i = 0; i < points.length; i++) {
url += "&point=" + points[i].lat + ',' + points[i].lng;
@ -34,7 +34,7 @@ function GraphHopperEngine(id, vehicleParam) {
url: url,
dataType: 'jsonp',
success: function (data) {
if (!data.paths || data.paths.length == 0)
if (!data.paths || data.paths.length === 0)
return callback(true);
var path = data.paths[0];
@ -70,5 +70,5 @@ function GraphHopperEngine(id, vehicleParam) {
};
}
OSM.Directions.addEngine(GraphHopperEngine("graphhopper_bicycle", "vehicle=bike"), true);
OSM.Directions.addEngine(GraphHopperEngine("graphhopper_foot", "vehicle=foot"), true);
OSM.Directions.addEngine(new GraphHopperEngine("graphhopper_bicycle", "vehicle=bike"), true);
OSM.Directions.addEngine(new GraphHopperEngine("graphhopper_foot", "vehicle=foot"), true);

View file

@ -45,7 +45,7 @@ function MapQuestEngine(id, vehicleParam) {
$.ajax({
url: url,
success: function (data) {
if (data.info.statuscode != 0)
if (data.info.statuscode !== 0)
return callback(true);
var line = [];
@ -63,7 +63,7 @@ function MapQuestEngine(id, vehicleParam) {
var d;
var linesegstart, linesegend, lineseg;
linesegstart = data.route.shape.maneuverIndexes[i];
if (i == mq.length - 1) {
if (i === mq.length - 1) {
d = 15;
linesegend = linesegstart + 1;
} else {
@ -81,7 +81,7 @@ function MapQuestEngine(id, vehicleParam) {
line: line,
steps: steps,
distance: data.route.distance * 1000,
time: data.route['time']
time: data.route.time
});
}
});
@ -89,6 +89,6 @@ function MapQuestEngine(id, vehicleParam) {
};
}
OSM.Directions.addEngine(MapQuestEngine("mapquest_bicycle", "routeType=bicycle"), true);
OSM.Directions.addEngine(MapQuestEngine("mapquest_foot", "routeType=pedestrian"), true);
OSM.Directions.addEngine(MapQuestEngine("mapquest_car", "routeType=fastest"), true);
OSM.Directions.addEngine(new MapQuestEngine("mapquest_bicycle", "routeType=bicycle"), true);
OSM.Directions.addEngine(new MapQuestEngine("mapquest_foot", "routeType=pedestrian"), true);
OSM.Directions.addEngine(new MapQuestEngine("mapquest_car", "routeType=fastest"), true);

View file

@ -48,7 +48,7 @@ function OSRMEngine() {
url: url,
dataType: 'json',
success: function (data) {
if (data.status == 207)
if (data.status === 207)
return callback(true);
previousPoints = points;
@ -68,7 +68,7 @@ function OSRMEngine() {
if (instCodes[1]) {
instText += "exit " + instCodes[1] + " ";
}
if (instCodes[0] != 15) {
if (instCodes[0] !== 15) {
instText += s[1] ? "<b>" + s[1] + "</b>" : I18n.t('javascripts.directions.instructions.unnamed');
}
if ((i + 1) < data.route_instructions.length) {
@ -91,4 +91,4 @@ function OSRMEngine() {
};
}
OSM.Directions.addEngine(OSRMEngine(), true);
OSM.Directions.addEngine(new OSRMEngine(), true);

View file

@ -62,7 +62,7 @@ OSM.History = function(map) {
url: window.location.pathname,
method: "GET",
data: data,
success: function(html, status, xhr) {
success: function(html) {
$('#sidebar_content .changesets').html(html);
updateMap();
}

View file

@ -81,7 +81,7 @@ OSM.NewNote = function(map) {
};
function newHalo(loc, a) {
if (a == 'dragstart' && map.hasLayer(halo)) {
if (a === 'dragstart' && map.hasLayer(halo)) {
map.removeLayer(halo);
} else {
if (map.hasLayer(halo)) map.removeLayer(halo);

View file

@ -60,7 +60,7 @@ OSM.Note = function (map) {
content.find("textarea").on("input", function (e) {
var form = e.target.form;
if ($(e.target).val() == "") {
if ($(e.target).val() === "") {
$(form.close).val(I18n.t("javascripts.notes.show.resolve"));
$(form.comment).prop("disabled", true);
} else {
@ -94,7 +94,7 @@ OSM.Note = function (map) {
map.addLayer(currentNote);
if (callback) callback();
};
}
function moveToNote() {
var data = $('.details').data(),

View file

@ -21,12 +21,12 @@ function initializeNotes(map) {
};
map.on("layeradd", function (e) {
if (e.layer == noteLayer) {
if (e.layer === noteLayer) {
loadNotes();
map.on("moveend", loadNotes);
}
}).on("layerremove", function (e) {
if (e.layer == noteLayer) {
if (e.layer === noteLayer) {
map.off("moveend", loadNotes);
noteLayer.clearLayers();
notes = {};

View file

@ -24,13 +24,13 @@ OSM.Query = function(map) {
} else if (!queryButton.hasClass("disabled")) {
enableQueryMode();
}
}).on("disabled", function (e) {
}).on("disabled", function () {
if (queryButton.hasClass("active")) {
map.off("click", clickHandler);
$(map.getContainer()).removeClass("query-active").addClass("query-disabled");
$(this).tooltip("show");
}
}).on("enabled", function (e) {
}).on("enabled", function () {
if (queryButton.hasClass("active")) {
map.on("click", clickHandler);
$(map.getContainer()).removeClass("query-disabled").addClass("query-active");
@ -40,20 +40,20 @@ OSM.Query = function(map) {
$("#sidebar_content")
.on("mouseover", ".query-results li.query-result", function () {
var geometry = $(this).data("geometry")
var geometry = $(this).data("geometry");
if (geometry) map.addLayer(geometry);
$(this).addClass("selected");
})
.on("mouseout", ".query-results li.query-result", function () {
var geometry = $(this).data("geometry")
var geometry = $(this).data("geometry");
if (geometry) map.removeLayer(geometry);
$(this).removeClass("selected");
})
.on("mousedown", ".query-results li.query-result", function (e) {
.on("mousedown", ".query-results li.query-result", function () {
var moved = false;
$(this).one("click", function (e) {
if (!moved) {
var geometry = $(this).data("geometry")
var geometry = $(this).data("geometry");
if (geometry) map.removeLayer(geometry);
if (!$(e.target).is('a')) {
@ -65,7 +65,7 @@ OSM.Query = function(map) {
});
});
function interestingFeature(feature, origin, radius) {
function interestingFeature(feature) {
if (feature.tags) {
for (var key in feature.tags) {
if (uninterestingTags.indexOf(key) < 0) {
@ -82,10 +82,9 @@ OSM.Query = function(map) {
var prefix = "";
if (tags.boundary === "administrative" && tags.admin_level) {
prefix =
I18n.t("geocoder.search_osm_nominatim.admin_levels.level" + tags.admin_level, {
prefix = I18n.t("geocoder.search_osm_nominatim.admin_levels.level" + tags.admin_level, {
defaultValue: I18n.t("geocoder.search_osm_nominatim.prefix.boundary.administrative")
})
});
} else {
var prefixes = I18n.t("geocoder.search_osm_nominatim.prefix");
@ -128,10 +127,10 @@ OSM.Query = function(map) {
}
}
if (tags["name"]) {
return tags["name"];
} else if (tags["ref"]) {
return tags["ref"];
if (tags.name) {
return tags.name;
} else if (tags.ref) {
return tags.ref;
} else if (tags["addr:housename"]) {
return tags["addr:housename"];
} else if (tags["addr:housenumber"] && tags["addr:street"]) {
@ -195,7 +194,7 @@ OSM.Query = function(map) {
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
if (interestingFeature(element, latlng, radius)) {
if (interestingFeature(element)) {
var $li = $("<li>")
.addClass("query-result")
.data("geometry", featureGeometry(element))
@ -211,7 +210,7 @@ OSM.Query = function(map) {
}
}
if ($ul.find("li").length == 0) {
if ($ul.find("li").length === 0) {
$("<li>")
.text(I18n.t("javascripts.query.nothing_found"))
.appendTo($ul);
@ -277,7 +276,7 @@ OSM.Query = function(map) {
marker = L.circle(latlng, radius, featureStyle).addTo(map);
$(document).everyTime(75, "fadeQueryMarker", function (i) {
if (i == 10) {
if (i === 10) {
map.removeLayer(marker);
} else {
marker.setStyle({

View file

@ -2,7 +2,7 @@
OSM.Search = function(map) {
$(".search_form input[name=query]").on("input", function(e) {
if ($(e.target).val() == "") {
if ($(e.target).val() === "") {
$(".describe_location").fadeIn(100);
} else {
$(".describe_location").fadeOut(100);
@ -68,7 +68,7 @@ OSM.Search = function(map) {
});
}
function showSearchResult(e) {
function showSearchResult() {
var marker = $(this).data("marker");
if (!marker) {
@ -84,7 +84,7 @@ OSM.Search = function(map) {
$(this).closest("li").addClass("selected");
}
function hideSearchResult(e) {
function hideSearchResult() {
var marker = $(this).data("marker");
if (marker) {

View file

@ -60,12 +60,13 @@ L.OSM.key = function (options) {
}
function updateButton() {
var disabled = map.getMapBaseLayerId() !== 'mapnik'
var disabled = map.getMapBaseLayerId() !== 'mapnik';
button
.toggleClass('disabled', disabled)
.attr('data-original-title', I18n.t(disabled ?
'javascripts.key.tooltip_disabled' :
'javascripts.key.tooltip'))
.attr('data-original-title',
I18n.t(disabled ?
'javascripts.key.tooltip_disabled' :
'javascripts.key.tooltip'));
}
function update() {
@ -74,7 +75,7 @@ L.OSM.key = function (options) {
$('.mapkey-table-entry').each(function () {
var data = $(this).data();
if (layer == data.layer && zoom >= data.zoomMin && zoom <= data.zoomMax) {
if (layer === data.layer && zoom >= data.zoomMin && zoom <= data.zoomMax) {
$(this).show();
} else {
$(this).hide();

View file

@ -107,7 +107,7 @@ L.OSM.layers = function(options) {
});
});
if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
if (OSM.STATUS !== 'api_offline' && OSM.STATUS !== 'database_offline') {
var overlaySection = $('<div>')
.attr('class', 'section overlay-layers')
.appendTo($ui);
@ -120,7 +120,7 @@ L.OSM.layers = function(options) {
var list = $('<ul>')
.appendTo(overlaySection);
function addOverlay(layer, name, maxArea) {
var addOverlay = function (layer, name, maxArea) {
var item = $('<li>')
.tooltip({
placement: 'top'
@ -170,7 +170,7 @@ L.OSM.layers = function(options) {
item.attr('data-original-title', disabled ?
I18n.t('javascripts.site.map_' + name + '_zoom_in_tooltip') : '');
});
}
};
addOverlay(map.noteLayer, 'notes', OSM.MAX_NOTE_REQUEST_AREA);
addOverlay(map.dataLayer, 'data', OSM.MAX_REQUEST_AREA);

View file

@ -64,7 +64,7 @@ L.OSM.Map = L.Map.extend({
if (layerParam.indexOf(this.baseLayers[i].options.code) >= 0) {
this.addLayer(this.baseLayers[i]);
layersAdded = layersAdded + this.baseLayers[i].options.code;
} else if (i == 0 && layersAdded == "") {
} else if (i === 0 && layersAdded === "") {
this.addLayer(this.baseLayers[i]);
} else {
this.removeLayer(this.baseLayers[i]);
@ -210,7 +210,7 @@ L.OSM.Map = L.Map.extend({
return true;
} else if (object.type === "relation") {
for (var i = 0; i < relations.length; i++)
if (relations[i].members.indexOf(node) != -1)
if (relations[i].members.indexOf(node) !== -1)
return true;
} else {
return false;
@ -236,7 +236,7 @@ L.OSM.Map = L.Map.extend({
center: this.getCenter().wrap(),
zoom: this.getZoom(),
layers: this.getLayersCode()
}
};
},
setState: function(state, options) {

View file

@ -13,8 +13,6 @@ L.OSM.note = function (options) {
map.on('zoomend', update);
update();
function update() {
var disabled = OSM.STATUS === "database_offline" || map.getZoom() < 12;
link
@ -24,6 +22,8 @@ L.OSM.note = function (options) {
'javascripts.site.createnote_tooltip'));
}
update();
return $container[0];
};

View file

@ -44,7 +44,7 @@ $(document).ready(function () {
var width = editor.outerWidth() - preview.outerWidth() + preview.width();
var minHeight = editor.outerHeight() - preview.outerHeight() + preview.height();
if (preview.contents().length == 0) {
if (preview.contents().length === 0) {
preview.oneTime(500, "loading", function () {
preview.addClass("loading");
});

View file

@ -86,7 +86,7 @@ OSM.Router = function(map, rts) {
var routes = [];
for (var r in rts)
routes.push(Route(r, rts[r]));
routes.push(new Route(r, rts[r]));
routes.recognize = function(path) {
for (var i = 0; i < this.length; i++) {

View file

@ -17,13 +17,13 @@ $(document).ready(function() {
$('.start-mapping').attr('href', url);
} else {
function geoSuccess(position) {
var geoSuccess = function (position) {
window.location = '/edit' + OSM.formatHash({
zoom: 17,
lat: position.coords.latitude,
lon: position.coords.longitude
});
}
};
$('.start-mapping').on('click', function(e) {
e.preventDefault();

View file

@ -17,16 +17,16 @@ var trim = require('trim');
*/
exports.parse = function(str){
if ('string' != typeof str) return {};
if ('string' !== typeof str) return {};
str = trim(str);
if ('' == str) return {};
if ('' === str) return {};
var obj = {};
var pairs = str.split('&');
for (var i = 0; i < pairs.length; i++) {
var parts = pairs[i].split('=');
obj[parts[0]] = null == parts[1]
obj[parts[0]] = null === parts[1]
? ''
: decodeURIComponent(parts[1]);
}
@ -68,4 +68,4 @@ exports.right = function(str){
};
},{}]},{},[])
;
;