aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2018-01-10 13:25:38 +0000
committerMatthew Somerville <matthew-github@dracos.co.uk>2018-01-10 13:25:38 +0000
commitf7f5918e7a9f9eb00e235232df9da43ebdd63944 (patch)
tree4e73609f8aabf9f1d2d12e8b423aadcf855ce162
parent70dacd4fe2de9eef582ae7e68ab9cc8ad2ead5ba (diff)
Add JSHint configuration, tidy up any warnings.
-rw-r--r--.jshintignore3
-rw-r--r--.jshintrc39
-rw-r--r--web/cobrands/fixmystreet/fixmystreet.js15
-rw-r--r--web/cobrands/fixmystreet/staff.js4
-rw-r--r--web/js/map-OpenLayers.js38
-rw-r--r--web/js/map-google-ol.js3
-rw-r--r--web/js/map-google.js2
7 files changed, 77 insertions, 27 deletions
diff --git a/.jshintignore b/.jshintignore
new file mode 100644
index 000000000..fa2e1bb4c
--- /dev/null
+++ b/.jshintignore
@@ -0,0 +1,3 @@
+**/vendor/
+web/jslib/
+**/*.auto.min.js
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 000000000..fd4468af6
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,39 @@
+{
+ "curly": true,
+ "forin": true,
+ "freeze": true,
+ "futurehostile": true,
+ "immed": true,
+ "indent": true,
+ "iterator": true,
+ "latedef": "nofunc",
+ "newcap": true,
+ "noarg": true,
+ "nocomma": true,
+ "noempty": true,
+ "nonbsp": true,
+ "nonew": true,
+ "undef": true,
+// "unused": true,
+
+ "browser": true,
+ "devel": true,
+ "jquery": true,
+
+ "globals": {
+ "fixmystreet": true,
+ "validation_rules": true,
+ "translation_strings": false,
+
+ "IntersectionObserver": false,
+
+ "accessibleAutocomplete": false,
+ "Chart": false,
+ "Dropzone": false,
+ "ga": false,
+ "google": false,
+ "Modernizr": false,
+ "OpenLayers": false,
+ "stamen": false
+ }
+}
diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js
index be8500729..a3ac5b71a 100644
--- a/web/cobrands/fixmystreet/fixmystreet.js
+++ b/web/cobrands/fixmystreet/fixmystreet.js
@@ -451,6 +451,10 @@ $.extend(fixmystreet.set_up, {
$category_select.val($(this).val()).change();
};
+ var add_option = function(el) {
+ $group_select.append($(el).clone());
+ };
+
var add_optgroup = function(el) {
var $el = $(el);
var $options = $el.find("option");
@@ -479,10 +483,6 @@ $.extend(fixmystreet.set_up, {
}
};
- var add_option = function(el) {
- $group_select.append($(el).clone());
- };
-
$category_select.hide();
$group_select.insertAfter($category_select);
$category_select.find("optgroup, > option").each(function() {
@@ -1235,7 +1235,10 @@ $(function() {
if (e.state === null) {
// Hashchange or whatever, we don't care.
- } else if ('initial' in e.state) {
+ return;
+ }
+
+ if ('initial' in e.state) {
// User has navigated Back from a pushStated state, presumably to
// see the list of all reports (which was shown on pageload). By
// this point, the browser has *already* updated the URL bar so
@@ -1266,7 +1269,7 @@ $(function() {
$('#filter_categories').add('#statuses')
.trigger('change.filters').trigger('change.multiselect');
fixmystreet.display.reports_list(location.href);
- } else if ('hashchange' in e.state) {
+ // } else if ('hashchange' in e.state) {
// This popstate was just here because the hash changed.
// (eg: mobile nav click.) We want to ignore it.
}
diff --git a/web/cobrands/fixmystreet/staff.js b/web/cobrands/fixmystreet/staff.js
index 2b7c5b010..e99af3c6b 100644
--- a/web/cobrands/fixmystreet/staff.js
+++ b/web/cobrands/fixmystreet/staff.js
@@ -233,8 +233,8 @@ $.extend(fixmystreet.set_up, {
function populateSelect($select, data, label_formatter) {
$select.find('option:gt(0)').remove();
$.each(data, function(k,v) {
- label = window.fixmystreet.utils[label_formatter](v);
- $opt = $('<option></option>').attr('value', v.id).text(label);
+ var label = window.fixmystreet.utils[label_formatter](v);
+ var $opt = $('<option></option>').attr('value', v.id).text(label);
if (v.state) {
$opt.attr('data-problem-state', v.state);
}
diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js
index 31f5f49d8..00f3e8e70 100644
--- a/web/js/map-OpenLayers.js
+++ b/web/js/map-OpenLayers.js
@@ -22,6 +22,23 @@ $.extend(fixmystreet.utils, {
fixmystreet.maps = fixmystreet.maps || {};
+ var drag = {
+ activate: function() {
+ this._drag = new OpenLayers.Control.DragFeatureFMS( fixmystreet.markers, {
+ onComplete: function(feature, e) {
+ fixmystreet.update_pin( feature.geometry );
+ }
+ } );
+ fixmystreet.map.addControl( this._drag );
+ this._drag.activate();
+ },
+ deactivate: function() {
+ if (this._drag) {
+ this._drag.deactivate();
+ }
+ }
+ };
+
$.extend(fixmystreet.maps, {
// This function might be passed either an OpenLayers.LonLat (so has
// lon and lat), or an OpenLayers.Geometry.Point (so has x and y).
@@ -215,23 +232,6 @@ $.extend(fixmystreet.utils, {
}
});
- var drag = {
- activate: function() {
- this._drag = new OpenLayers.Control.DragFeatureFMS( fixmystreet.markers, {
- onComplete: function(feature, e) {
- fixmystreet.update_pin( feature.geometry );
- }
- } );
- fixmystreet.map.addControl( this._drag );
- this._drag.activate();
- },
- deactivate: function() {
- if (this._drag) {
- this._drag.deactivate();
- }
- }
- };
-
/* Make sure pins aren't going to reload just because we're zooming out,
* we already have the pins when the page loaded */
function zoomToBounds(bounds) {
@@ -862,8 +862,9 @@ OpenLayers.Protocol.FixMyStreet = OpenLayers.Class(OpenLayers.Protocol.HTTP, {
options.params[key] = val;
}
});
+ var page;
if (this.use_page) {
- var page = $('.pagination').data('page');
+ page = $('.pagination').data('page');
this.use_page = false;
} else if (this.initial_page) {
page = 1;
@@ -883,6 +884,7 @@ OpenLayers.Format.FixMyStreet = OpenLayers.Class(OpenLayers.Format.JSON, {
// Remove loading indicator
$('#loading-indicator').addClass('hidden');
$('#loading-indicator').attr('aria-hidden', true);
+ var obj;
if (typeof json == 'string') {
obj = OpenLayers.Format.JSON.prototype.read.apply(this, [json, filter]);
} else {
diff --git a/web/js/map-google-ol.js b/web/js/map-google-ol.js
index 7369a8e9f..99670d4f2 100644
--- a/web/js/map-google-ol.js
+++ b/web/js/map-google-ol.js
@@ -10,6 +10,7 @@ $(function(){
fixmystreet.map.setBaseLayer(fixmystreet.map.layers[1]);
}
});
+ // jshint undef:false
if (typeof fixmystreet_google_default !== 'undefined' && fixmystreet_google_default == 'satellite') {
$('#map_layer_toggle').click();
}
@@ -36,7 +37,9 @@ fixmystreet.maps.config = function() {
var road_layer = {}; // Empty object defaults to standard road layer
function apply_map_styles() {
+ // jshint undef:false
var styledMapType = new google.maps.StyledMapType(fixmystreet_google_maps_custom_style);
+ // jshint undef:true
this.mapObject.mapTypes.set('styled', styledMapType);
this.mapObject.setMapTypeId('styled');
}
diff --git a/web/js/map-google.js b/web/js/map-google.js
index 75a1b25a1..bf9909f02 100644
--- a/web/js/map-google.js
+++ b/web/js/map-google.js
@@ -41,7 +41,7 @@ fixmystreet.maps = {};
});
fixmystreet.report_marker = marker;
google.maps.event.removeListener(fixmystreet.event_update_map);
- for (m=0; m<fixmystreet.markers.length; m++) {
+ for (var m=0; m<fixmystreet.markers.length; m++) {
fixmystreet.markers[m].setMap(null);
}
}