Browse Source

Fix some linting errors; remove debug messages

master
parent
commit
87326a86b0
  1. 3
      package.json
  2. 14
      src/CategoryBase.js
  3. 12
      src/CategoryIndex.js
  4. 17
      src/CategoryOverpass.js
  5. 24
      src/OpenStreetBrowserLoader.js
  6. 4
      src/categories.js
  7. 4
      src/fullscreen.js
  8. 71
      src/index.js
  9. 21
      src/language.js
  10. 4
      src/location.js
  11. 4
      src/mapLayers.js
  12. 15
      src/options.js
  13. 2
      src/overpassChooser.js
  14. 18
      src/state.js
  15. 14
      src/tagTranslations.js
  16. 8
      src/twigFunctions.js

3
package.json

@ -33,5 +33,8 @@
"browserify": "^14.4.0",
"standard": "^10.0.2",
"watchify": "^3.9.0"
},
"standard": {
"global": [ "lang", "ui_lang", "config", "options", "alert", "L", "register_hook", "call_hooks", "call_hooks_callback", "XMLHttpRequest", "map", "overpassFrontend", "location", "baseCategory", "currentPath", "overpassUrl" ]
}
}

14
src/CategoryBase.js

@ -1,3 +1,4 @@
/* global lang, ui_lang, options, alert */
var OpenStreetBrowserLoader = require('./OpenStreetBrowserLoader')
function CategoryBase (id, data) {
@ -9,6 +10,7 @@ function CategoryBase (id, data) {
this.dom = document.createElement('div')
this.dom.className = 'category category-' + data.type
var name
var a
if (this.id !== 'index') {
var domHeader = document.createElement('header')
@ -26,14 +28,14 @@ function CategoryBase (id, data) {
name = lang('category:' + this.id)
}
var a = document.createElement('a')
a = document.createElement('a')
a.appendChild(document.createTextNode(name))
a.href = '#'
a.onclick = this.toggle.bind(this)
domHeader.appendChild(a)
if (options.debug) {
var a = document.createElement('a')
a = document.createElement('a')
a.appendChild(document.createTextNode('⟳'))
a.title = lang('reload')
a.className = 'reload'
@ -84,8 +86,9 @@ CategoryBase.prototype.setParentDom = function (parentDom) {
}
CategoryBase.prototype.open = function () {
if (this.isOpen)
if (this.isOpen) {
return
}
if (this.parentCategory) {
this.parentCategory.open()
@ -105,8 +108,9 @@ CategoryBase.prototype.open = function () {
}
CategoryBase.prototype.close = function () {
if (!this.isOpen)
if (!this.isOpen) {
return
}
this.dom.classList.remove('open')
@ -153,7 +157,6 @@ CategoryBase.prototype.recalc = function () {
}
CategoryBase.prototype.notifyChildLoadStart = function (category) {
console.log(this.id, this.childrenLoadingCount)
if (this.childrenLoadingCount === 0 && this.parentCategory) {
this.parentCategory.notifyChildLoadStart(this)
} else {
@ -163,7 +166,6 @@ CategoryBase.prototype.notifyChildLoadStart = function (category) {
}
CategoryBase.prototype.notifyChildLoadEnd = function (category) {
console.log(this.id, this.childrenLoadingCount)
this.childrenLoadingCount--
if (this.childrenLoadingCount === 0 && this.parentCategory) {
this.parentCategory.notifyChildLoadEnd(this)

12
src/CategoryIndex.js

@ -1,3 +1,4 @@
/* global alert */
var async = require('async')
var OpenStreetBrowserLoader = require('./OpenStreetBrowserLoader')
var CategoryBase = require('./CategoryBase')
@ -10,20 +11,22 @@ function CategoryIndex (id, data) {
this.childrenDoms = {}
this.childrenCategories = null
this._loadChildrenCategories(function (err) {
if (err) {
console.log('error loading child categories:', err)
}
})
}
CategoryIndex.prototype.open = function () {
if (this.isOpen)
if (this.isOpen) {
return
}
CategoryBase.prototype.open.call(this)
if (this.childrenCategories !== null) {
this.isOpen = true
return
}
}
@ -75,8 +78,9 @@ CategoryIndex.prototype._loadChildCategory = function (callback, err, category)
}
CategoryIndex.prototype.close = function () {
if (!this.isOpen)
if (!this.isOpen) {
return
}
CategoryBase.prototype.close.call(this)

17
src/CategoryOverpass.js

@ -6,7 +6,7 @@ var state = require('./state')
var defaultValues = {
feature: {
title: "{{ localizedTag(tags, 'name') |default(localizedTag(tags, 'operator')) | default(localizedTag(tags, 'ref')) | default(trans('unnamed')) }}",
markerSign: "",
markerSign: '',
'style:hover': {
color: 'black',
weight: 3,
@ -23,6 +23,8 @@ var defaultValues = {
CategoryOverpass.prototype = Object.create(CategoryBase.prototype)
CategoryOverpass.prototype.constructor = CategoryOverpass
function CategoryOverpass (id, data) {
var p
CategoryBase.call(this, id, data)
data.id = this.id
@ -94,12 +96,12 @@ function CategoryOverpass (id, data) {
this.updatePopupContent(ob, ob.popup)
}.bind(this)
var p = document.createElement('div')
p = document.createElement('div')
p.className = 'loadingIndicator'
p.innerHTML = '<i class="fa fa-spinner fa-pulse fa-fw"></i><span class="sr-only">Loading...</span>'
this.dom.appendChild(p)
var p = document.createElement('div')
p = document.createElement('div')
p.className = 'loadingIndicator2'
p.innerHTML = '<div class="bounce1"></div><div class="bounce2"></div><div class="bounce3"></div>'
this.dom.appendChild(p)
@ -170,8 +172,9 @@ CategoryOverpass.prototype.updateStatus = function () {
}
CategoryOverpass.prototype.open = function () {
if (this.isOpen)
if (this.isOpen) {
return
}
CategoryBase.prototype.open.call(this)
@ -191,8 +194,9 @@ CategoryOverpass.prototype.recalc = function () {
}
CategoryOverpass.prototype.close = function () {
if (!this.isOpen)
if (!this.isOpen) {
return
}
CategoryBase.prototype.close.call(this)
@ -220,7 +224,6 @@ CategoryOverpass.prototype.updatePopupContent = function (object, popup) {
div.className = 'description'
div.innerHTML = object.data.popupDescription || object.data.description
popup._contentNode.insertBefore(div, popup._contentNode.firstChild.nextSibling)
}
if (this.popupBodyTemplate) {
@ -242,7 +245,7 @@ CategoryOverpass.prototype.updatePopupContent = function (object, popup) {
CategoryOverpass.prototype.renderTemplate = function (object, templateId, callback) {
OpenStreetBrowserLoader.getTemplate(templateId, function (err, template) {
if (err) {
err = "can't load " + templateId + ": " + err
err = "can't load " + templateId + ': ' + err
return callback(err, null)
}

24
src/OpenStreetBrowserLoader.js

@ -47,10 +47,9 @@ OpenStreetBrowserLoader.prototype.getCategory = function (id, callback) {
}
var req = new XMLHttpRequest()
req.addEventListener("load", reqListener.bind(this, req))
req.open("GET", config.categoriesDir + '/' + id + ".json?" + config.categoriesRev)
req.addEventListener('load', reqListener.bind(this, req))
req.open('GET', config.categoriesDir + '/' + id + '.json?' + config.categoriesRev)
req.send()
}
OpenStreetBrowserLoader.prototype.getTemplate = function (id, callback) {
@ -71,20 +70,20 @@ OpenStreetBrowserLoader.prototype.getTemplate = function (id, callback) {
}
var req = new XMLHttpRequest()
req.addEventListener("load", reqListener.bind(this, req))
req.open("GET", config.categoriesDir + '/' + id + ".html?" + config.categoriesRev)
req.addEventListener('load', reqListener.bind(this, req))
req.open('GET', config.categoriesDir + '/' + id + '.html?' + config.categoriesRev)
req.send()
}
OpenStreetBrowserLoader.prototype.getCategoryFromData = function (id, data, callback) {
if (!data.type) {
callback('no type defined', null)
return
} else if (!(data.type in this.types)) {
callback('unknown type', null)
return
} else {
return callback(new Error('no type defined'), null)
}
if (!(data.type in this.types)) {
return callback(new Error('unknown type'), null)
}
var layer = new this.types[data.type](id, data)
layer.setMap(this.map)
@ -99,7 +98,6 @@ OpenStreetBrowserLoader.prototype.getCategoryFromData = function (id, data, call
callback(null, layer)
}
}
}
OpenStreetBrowserLoader.prototype.forget = function (id) {
this.categories[id].remove()

4
src/categories.js

@ -9,7 +9,7 @@ register_hook('state-apply', function (state) {
list.forEach(function (id) {
OpenStreetBrowserLoader.getCategory(id, function (err, category) {
if (err) {
console.log("Can't load category " + id + ": ", err)
console.log("Can't load category " + id + ': ', err)
return
}
@ -22,4 +22,4 @@ register_hook('state-apply', function (state) {
}
})
})
}.bind(this))
})

4
src/fullscreen.js

@ -1,4 +1,4 @@
var fullscreenControl = L.Control.extend({
var FullscreenControl = L.Control.extend({
options: {
position: 'topleft'
// control position - allowed: 'topleft', 'topright', 'bottomleft', 'bottomright'
@ -19,7 +19,7 @@ var fullscreenControl = L.Control.extend({
})
register_hook('init', function (callback) {
map.addControl(new fullscreenControl())
map.addControl(new FullscreenControl())
})
register_hook('show', function (url, options) {

71
src/index.js

@ -1,22 +1,21 @@
/* globals map:true, overpassFrontend:true, currentPath:true, options:true, baseCategory:true, overpassUrl:true */
var LeafletGeoSearch = require('leaflet-geosearch')
var OverpassLayer = require('overpass-layer')
var OverpassLayerList = require('overpass-layer').List
var OverpassFrontend = require('overpass-frontend')
var OpenStreetBrowserLoader = require('./OpenStreetBrowserLoader')
var state = require('./state')
var hash = require('sheet-router/hash')
var queryString = require('query-string')
window.OpenStreetBrowserLoader = OpenStreetBrowserLoader
global.OpenStreetBrowserLoader = OpenStreetBrowserLoader
require('./CategoryIndex')
require('./CategoryOverpass')
global.map
window.baseCategory
window.overpassUrl
window.overpassFrontend
window.currentPath = null
global.map = null
global.baseCategory = null
global.overpassUrl = null
global.overpassFrontend = null
global.currentPath = null
var lastPopupClose = 0
// Optional modules
@ -54,9 +53,9 @@ function onload2 (initState) {
drawCircle: false,
drawMarker: false,
showPopup: false
}).addTo(map);
}).addTo(map)
if (typeof overpassUrl === 'undefined') {
if (!overpassUrl) {
overpassUrl = config.overpassUrl
if (Array.isArray(overpassUrl) && overpassUrl.length) {
overpassUrl = overpassUrl[0]
@ -99,16 +98,18 @@ function onload2 (initState) {
if (e.popup.object) {
var url = e.popup.object.layer_id + '/' + e.popup.object.id
if (location.hash.substr(1) !== url && location.hash.substr(1, url.length + 1) !== url + '/') {
currentPath = url
// only push state, when last popup close happened >1sec earlier
state.update(null, Date.now() - lastPopupClose > 1000)
}
OpenStreetBrowserLoader.getCategory(e.popup.object.layer_id, function (err, category) {
category.notifyPopupOpen(e.popup.object, e.popup)
if (err) {
alert(err)
return
}
category.notifyPopupOpen(e.popup.object, e.popup)
})
}
})
@ -160,12 +161,12 @@ function show (id, options, callback) {
id = id.split('/')
if (id.length < 2) {
return callback('unknown request')
return callback(new Error('unknown request'))
}
OpenStreetBrowserLoader.getCategory(id[0], function (err, category) {
if (err) {
return callback('error loading category "' + id[0] + '": ' + err)
return callback(new Error('error loading category "' + id[0] + '": ' + err))
}
if (!category.parentDom) {
@ -178,7 +179,7 @@ function show (id, options, callback) {
},
function (err, data) {
if (err) {
return callback('error loading object "' + id[0] + '/' + id[1] +'": ' + err)
return callback(new Error('error loading object "' + id[0] + '/' + id[1] + '": ' + err))
}
if (!map._popup || map._popup !== data.popup) {
@ -198,58 +199,61 @@ function show (id, options, callback) {
}
function showDetails (data, category) {
var div, h, dt, dd
var k
var dom = document.getElementById('contentDetails')
dom.innerHTML = ''
var div = document.createElement('h1')
div = document.createElement('h1')
div.className = 'title'
div.innerHTML = data.data.title
dom.appendChild(div)
var div = document.createElement('div')
div = document.createElement('div')
div.className = 'description'
div.innerHTML = data.data.description
dom.appendChild(div)
var div = document.createElement('div')
div = document.createElement('div')
div.className = 'body'
div.innerHTML = data.data.body
dom.appendChild(div)
var div = document.createElement('div')
div = document.createElement('div')
div.className = 'body'
dom.appendChild(div)
category.renderTemplate(data, 'detailsBody', function (div, err, result) {
div.innerHTML = result
}.bind(this, div))
var h = document.createElement('h3')
h = document.createElement('h3')
h.innerHTML = 'Attributes'
dom.appendChild(h)
var div = document.createElement('dl')
div = document.createElement('dl')
div.className = 'tags'
for (var k in data.object.tags) {
var dt = document.createElement('dt')
for (k in data.object.tags) {
dt = document.createElement('dt')
dt.appendChild(document.createTextNode(k))
div.appendChild(dt)
var dd = document.createElement('dd')
dd = document.createElement('dd')
dd.appendChild(document.createTextNode(data.object.tags[k]))
div.appendChild(dd)
}
dom.appendChild(div)
var h = document.createElement('h3')
h = document.createElement('h3')
h.innerHTML = 'OSM Meta'
dom.appendChild(h)
var div = document.createElement('dl')
div = document.createElement('dl')
div.className = 'meta'
var dt = document.createElement('dt')
dt = document.createElement('dt')
dt.appendChild(document.createTextNode('id'))
div.appendChild(dt)
var dd = document.createElement('dd')
dd = document.createElement('dd')
var a = document.createElement('a')
a.appendChild(document.createTextNode(data.object.type + '/' + data.object.osm_id))
a.href = 'https://openstreetmap.org/' + data.object.type + '/' + data.object.osm_id
@ -257,11 +261,12 @@ function showDetails (data, category) {
dd.appendChild(a)
div.appendChild(dd)
for (var k in data.object.meta) {
var dt = document.createElement('dt')
for (k in data.object.meta) {
dt = document.createElement('dt')
dt.appendChild(document.createTextNode(k))
div.appendChild(dt)
var dd = document.createElement('dd')
dd = document.createElement('dd')
dd.appendChild(document.createTextNode(data.object.meta[k]))
div.appendChild(dd)
}

21
src/language.js

@ -1,7 +1,8 @@
/* global languages:false, lang_str:false */
var tagTranslations = require('./tagTranslations')
function getPreferredDataLanguage () {
var m = (navigator.language || navigator.userLanguage).match(/^([^\-]+)(\-.*|)$/)
var m = (navigator.language || navigator.userLanguage).match(/^([^-]+)(-.*|)$/)
if (m) {
return m[1].toLocaleLowerCase()
} else {
@ -14,18 +15,19 @@ function getAcceptLanguages () {
}
function getUiLanguages () {
var i, code
var ret = {}
var acceptLanguages = getAcceptLanguages()
for (var i = 0; i < acceptLanguages.length; i++) {
var code = acceptLanguages[i]
for (i = 0; i < acceptLanguages.length; i++) {
code = acceptLanguages[i]
if (languages.indexOf(code) !== -1) {
ret[code] = langName(code)
}
}
for (var i = 0; i < languages.length; i++) {
var code = languages[i]
for (i = 0; i < languages.length; i++) {
code = languages[i]
if (!(code in ret)) {
ret[code] = langName(code)
}
@ -35,18 +37,19 @@ function getUiLanguages () {
}
function getDataLanguages () {
var code
var ret = {}
var acceptLanguages = getAcceptLanguages()
for (var i = 0; i < acceptLanguages.length; i++) {
var code = acceptLanguages[i]
code = acceptLanguages[i]
ret[code] = langName(code)
}
for (var k in lang_str) {
var m
if (m = k.match(/^lang:(.*)$/)) {
var code = m[1]
var m = k.match(/^lang:(.*)$/)
if (m) {
code = m[1]
if (code === 'current') {
continue
}

4
src/location.js

@ -8,12 +8,10 @@ register_hook('init_callback', function (initState, callback) {
}
ipLocation('', function (err, ipLoc) {
var ret
if (typeof ipLoc === 'object' && 'latitude' in ipLoc) {
initState.map = '14/' + ipLoc.latitude + '/' + ipLoc.longitude
}
callback()
callback(err)
})
})

4
src/mapLayers.js

@ -3,13 +3,13 @@ var currentMapLayer = null
register_hook('init', function () {
if (!config.baseMaps) {
var osm_mapnik = L.tileLayer('//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
var osmMapnik = L.tileLayer('//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{
maxZoom: config.maxZoom || 19,
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}
)
osm_mapnik.addTo(map)
osmMapnik.addTo(map)
return
}

15
src/options.js

@ -1,3 +1,4 @@
/* globals form, ajax, options:true, showRootContent */
var moduleOptions = {}
register_hook('init', function () {
@ -26,18 +27,18 @@ moduleOptions.open = function () {
call_hooks('options_form', def)
var options_form = new form('options', def)
var optionsForm = new form('options', def)
document.getElementById('content').className = 'options'
var dom = document.getElementById('contentOptions')
dom.innerHTML = ''
options_form.set_data(options)
optionsForm.set_data(options)
var f = document.createElement('form')
f.onsubmit = moduleOptions.submit.bind(this, options_form)
f.onsubmit = moduleOptions.submit.bind(this, optionsForm)
dom.appendChild(f)
options_form.show(f)
optionsForm.show(f)
var input = document.createElement('button')
input.innerHTML = lang('save')
@ -46,12 +47,12 @@ moduleOptions.open = function () {
return false
}
moduleOptions.submit = function (options_form) {
var data = options_form.get_data()
moduleOptions.submit = function (optionsForm) {
var data = optionsForm.get_data()
var reload = false
for (var k in data) {
if (options_form.def[k].reloadOnChange && options[k] != data[k]) {
if (optionsForm.def[k].reloadOnChange && options[k] !== data[k]) {
reload = true
}
}

2
src/overpassChooser.js

@ -1,3 +1,5 @@
/* globals overpassUrl:true */
register_hook('init', function () {
if (options.overpassUrl) {
overpassUrl = options.overpassUrl

18
src/state.js

@ -1,3 +1,5 @@
/* globals setPath, history */
var queryString = require('query-string')
function get () {
@ -63,11 +65,12 @@ function stringify (state) {
var locPrecision = 5
if (state.zoom) {
locPrecision =
state.zoom > 16 ? 5 :
state.zoom > 8 ? 4 :
state.zoom > 4 ? 3 :
state.zoom > 2 ? 2 :
state.zoom > 1 ? 1 : 0
state.zoom > 16 ? 5
: state.zoom > 8 ? 4
: state.zoom > 4 ? 3
: state.zoom > 2 ? 2
: state.zoom > 1 ? 1
: 0
}
if (state.zoom && state.lat && state.lon) {
@ -145,13 +148,8 @@ function update (state, push) {
if (push) {
history.pushState(null, null, newHash)
console.log('push', newHash, state)
} else if (location.hash !== newHash && (location.hash !== '' || newHash !== '#')) {
history.replaceState(null, null, newHash)
console.log('replace', newHash, state)
} else {
console.log('ignore', newHash, state)
}
}

14
src/tagTranslations.js

@ -1,5 +1,4 @@
var OverpassLayer = require('overpass-layer')
var translations = null
var tagLang = null
OverpassLayer.twig.extendFunction('keyTrans', function () {
@ -23,12 +22,9 @@ OverpassLayer.twig.extendFunction('trans', function () {
})
function tagTranslationsTrans () {
var ret = null
var fallback = null
tag = arguments[0]
value = undefined
count = undefined
var tag = arguments[0]
var value
var count
if (arguments.length > 1) {
value = typeof arguments[1] === 'undefined' ? null : arguments[1]
}
@ -54,9 +50,9 @@ function tagTranslationsTransList (key, values) {
return tagTranslationsTrans(key, value.trim())
}.bind(this, key))
if (values.length > 1)
if (values.length > 1) {
return values.slice(0, -1).join(', ') + ' and ' + values.slice(-1)[0]
}
return values[0]
}

8
src/twigFunctions.js

@ -12,18 +12,18 @@ OverpassLayer.twig.extendFunction('tagsPrefix', function (tags, prefix) {
}
}
if (count == 0) {
if (count === 0) {
return null
}
return ret
})
OverpassLayer.twig.extendFunction('openingHoursState', function (opening_hours) {
OverpassLayer.twig.extendFunction('openingHoursState', function (openingHours) {
try {
var oh = new OpeningHours(opening_hours)
var oh = new OpeningHours(openingHours)
} catch (err) {
console.log("Error in opening_hours: " + err)
console.log('Error in opening_hours: ' + err)
return 'unknown'
}

Loading…
Cancel
Save