Merge pull request #1086 from umap-project/lebab-arrow

Install and apply Lebab for JS arrows’ conversions
This commit is contained in:
David Larlet 2023-05-17 10:59:19 -04:00 committed by GitHub
commit d0f89c3be2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 1084 additions and 188 deletions

View file

@ -58,3 +58,9 @@ filepath = "${jsdir}*.js"
pretty: ## Apply PrettierJS to all JS files (or specified `filepath`) pretty: ## Apply PrettierJS to all JS files (or specified `filepath`)
./node_modules/prettier/bin-prettier.js --write ${filepath} ./node_modules/prettier/bin-prettier.js --write ${filepath}
lebab: ## Convert JS `filepath` to modern syntax with Lebab, then prettify
./node_modules/lebab/bin/index.js --replace ${filepath} --transform arrow,arrow-return
$(MAKE) pretty filepath=${filepath}
lebab-all: $(jsdir)* ## Convert all JS files to modern syntax with Lebab + prettify
for file in $^ ; do $(MAKE) lebab filepath=$${file}; done

976
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -8,6 +8,7 @@
"devDependencies": { "devDependencies": {
"chai": "^3.3.0", "chai": "^3.3.0",
"happen": "~0.1.3", "happen": "~0.1.3",
"lebab": "^3.2.1",
"mocha": "^2.3.3", "mocha": "^2.3.3",
"mocha-phantomjs": "^4.0.1", "mocha-phantomjs": "^4.0.1",
"optimist": "~0.4.0", "optimist": "~0.4.0",

View file

@ -129,10 +129,7 @@ L.U.AutoComplete = L.Class.extend({
}, },
onBlur: function () { onBlur: function () {
var self = this setTimeout(() => this.hide(), 100)
setTimeout(function () {
self.hide()
}, 100)
}, },
clear: function () { clear: function () {
@ -207,7 +204,7 @@ L.U.AutoComplete = L.Class.extend({
resultToIndex: function (result) { resultToIndex: function (result) {
var out = null var out = null
this.forEach(this.RESULTS, function (item, index) { this.forEach(this.RESULTS, (item, index) => {
if (item.item.value == result.item.value) { if (item.item.value == result.item.value) {
out = index out = index
return return
@ -217,12 +214,11 @@ L.U.AutoComplete = L.Class.extend({
}, },
handleResults: function (data) { handleResults: function (data) {
var self = this
this.clear() this.clear()
this.container.style.display = 'block' this.container.style.display = 'block'
this.resizeContainer() this.resizeContainer()
this.forEach(data, function (item) { this.forEach(data, (item) => {
self.RESULTS.push(self.createResult(item)) this.RESULTS.push(this.createResult(item))
}) })
this.CURRENT = 0 this.CURRENT = 0
this.highlight() this.highlight()
@ -230,9 +226,8 @@ L.U.AutoComplete = L.Class.extend({
}, },
highlight: function () { highlight: function () {
var self = this this.forEach(this.RESULTS, (result, index) => {
this.forEach(this.RESULTS, function (result, index) { if (index === this.CURRENT) L.DomUtil.addClass(result.el, 'on')
if (index === self.CURRENT) L.DomUtil.addClass(result.el, 'on')
else L.DomUtil.removeClass(result.el, 'on') else L.DomUtil.removeClass(result.el, 'on')
}) })
}, },

View file

@ -566,7 +566,7 @@ L.U.DataLayersControl = L.Control.extend({
if (e.finalIndex === 0) layer.bringToTop() if (e.finalIndex === 0) layer.bringToTop()
else if (e.finalIndex > e.initialIndex) layer.insertBefore(other) else if (e.finalIndex > e.initialIndex) layer.insertBefore(other)
else layer.insertAfter(other) else layer.insertAfter(other)
this.map.eachDataLayerReverse(function (datalayer) { this.map.eachDataLayerReverse((datalayer) => {
if (datalayer.getRank() >= minIndex) datalayer.isDirty = true if (datalayer.getRank() >= minIndex) datalayer.isDirty = true
}) })
this.map.indexDatalayers() this.map.indexDatalayers()
@ -681,7 +681,7 @@ L.U.Map.include({
filter.placeholder = L._('Filter…') filter.placeholder = L._('Filter…')
filter.value = this.options.filter || '' filter.value = this.options.filter || ''
var addFeature = function (feature) { var addFeature = (feature) => {
var feature_li = L.DomUtil.create('li', feature.getClassName() + ' feature'), var feature_li = L.DomUtil.create('li', feature.getClassName() + ' feature'),
zoom_to = L.DomUtil.create('i', 'feature-zoom_to', feature_li), zoom_to = L.DomUtil.create('i', 'feature-zoom_to', feature_li),
edit = L.DomUtil.create('i', 'show-on-edit feature-edit', feature_li), edit = L.DomUtil.create('i', 'show-on-edit feature-edit', feature_li),
@ -726,7 +726,7 @@ L.U.Map.include({
return feature_li return feature_li
} }
var append = function (datalayer) { var append = (datalayer) => {
var container = L.DomUtil.create( var container = L.DomUtil.create(
'div', 'div',
datalayer.getHidableClass(), datalayer.getHidableClass(),
@ -739,9 +739,9 @@ L.U.Map.include({
var ul = L.DomUtil.create('ul', '', container) var ul = L.DomUtil.create('ul', '', container)
L.DomUtil.classIf(container, 'off', !datalayer.isVisible()) L.DomUtil.classIf(container, 'off', !datalayer.isVisible())
var build = function () { var build = () => {
ul.innerHTML = '' ul.innerHTML = ''
datalayer.eachFeature(function (feature) { datalayer.eachFeature((feature) => {
if ( if (
(filterValue && !feature.matchFilter(filterValue, filterKeys)) || (filterValue && !feature.matchFilter(filterValue, filterKeys)) ||
feature.properties.isVisible === false feature.properties.isVisible === false
@ -752,11 +752,11 @@ L.U.Map.include({
} }
build() build()
datalayer.on('datachanged', build) datalayer.on('datachanged', build)
datalayer.map.ui.once('panel:closed', function () { datalayer.map.ui.once('panel:closed', () => {
datalayer.off('datachanged', build) datalayer.off('datachanged', build)
}) })
datalayer.map.ui.once('panel:ready', function () { datalayer.map.ui.once('panel:ready', () => {
datalayer.map.ui.once('panel:ready', function () { datalayer.map.ui.once('panel:ready', () => {
datalayer.off('datachanged', build) datalayer.off('datachanged', build)
}) })
}) })
@ -765,12 +765,12 @@ L.U.Map.include({
var appendAll = function () { var appendAll = function () {
this.options.filter = filterValue = filter.value this.options.filter = filterValue = filter.value
featuresContainer.innerHTML = '' featuresContainer.innerHTML = ''
this.eachBrowsableDataLayer(function (datalayer) { this.eachBrowsableDataLayer((datalayer) => {
append(datalayer) append(datalayer)
}) })
} }
var resetLayers = function () { var resetLayers = function () {
this.eachBrowsableDataLayer(function (datalayer) { this.eachBrowsableDataLayer((datalayer) => {
datalayer.resetLayer(true) datalayer.resetLayer(true)
}) })
} }
@ -812,8 +812,8 @@ L.U.Map.include({
this.getMap().options.advancedFilters[property] = [] this.getMap().options.advancedFilters[property] = []
} }
}) })
this.eachDataLayer(function (datalayer) { this.eachDataLayer((datalayer) => {
datalayer.eachFeature(function (feature) { datalayer.eachFeature((feature) => {
advancedFilterKeys.forEach((property) => { advancedFilterKeys.forEach((property) => {
if (feature.properties[property]) { if (feature.properties[property]) {
if (!advancedFiltersFull[property].includes(feature.properties[property])) { if (!advancedFiltersFull[property].includes(feature.properties[property])) {
@ -875,7 +875,7 @@ L.U.Map.include({
var filterFeatures = function () { var filterFeatures = function () {
var noResults = true var noResults = true
this.eachDataLayer(function (datalayer) { this.eachDataLayer((datalayer) => {
datalayer.eachFeature(function (feature) { datalayer.eachFeature(function (feature) {
feature.properties.isVisible = true feature.properties.isVisible = true
for (const [property, values] of Object.entries( for (const [property, values] of Object.entries(
@ -1060,11 +1060,11 @@ L.U.Search = L.PhotonSearch.extend({
edit.title = L._('Save this location as new feature') edit.title = L._('Save this location as new feature')
// We need to use "mousedown" because Leaflet.Photon listen to mousedown // We need to use "mousedown" because Leaflet.Photon listen to mousedown
// on el. // on el.
L.DomEvent.on(zoom, 'mousedown', function (e) { L.DomEvent.on(zoom, 'mousedown', (e) => {
L.DomEvent.stop(e) L.DomEvent.stop(e)
self.zoomToFeature(feature) self.zoomToFeature(feature)
}) })
L.DomEvent.on(edit, 'mousedown', function (e) { L.DomEvent.on(edit, 'mousedown', (e) => {
L.DomEvent.stop(e) L.DomEvent.stop(e)
var datalayer = self.map.defaultDataLayer() var datalayer = self.map.defaultDataLayer()
var layer = datalayer.geojsonToFeatures(feature) var layer = datalayer.geojsonToFeatures(feature)
@ -1101,7 +1101,7 @@ L.U.SearchControl = L.Control.extend({
var link = L.DomUtil.create('a', '', container) var link = L.DomUtil.create('a', '', container)
link.href = '#' link.href = '#'
link.title = L._('Search a place name') link.title = L._('Search a place name')
L.DomEvent.on(link, 'click', function (e) { L.DomEvent.on(link, 'click', (e) => {
L.DomEvent.stop(e) L.DomEvent.stop(e)
self.openPanel(map) self.openPanel(map)
}) })
@ -1122,14 +1122,14 @@ L.U.SearchControl = L.Control.extend({
var resultsContainer = L.DomUtil.create('div', 'photon-autocomplete', container) var resultsContainer = L.DomUtil.create('div', 'photon-autocomplete', container)
this.search = new L.U.Search(map, input, options) this.search = new L.U.Search(map, input, options)
var id = Math.random() var id = Math.random()
this.search.on('ajax:send', function () { this.search.on('ajax:send', () => {
map.fire('dataloading', { id: id }) map.fire('dataloading', { id: id })
}) })
this.search.on('ajax:return', function () { this.search.on('ajax:return', () => {
map.fire('dataload', { id: id }) map.fire('dataload', { id: id })
}) })
this.search.resultsContainer = resultsContainer this.search.resultsContainer = resultsContainer
map.ui.once('panel:ready', function () { map.ui.once('panel:ready', () => {
input.focus() input.focus()
}) })
map.ui.openPanel({ data: { html: container } }) map.ui.openPanel({ data: { html: container } })
@ -1236,7 +1236,7 @@ L.U.IframeExporter = L.Evented.extend({
this.queryString.feature = this.map.currentFeature.getSlug() this.queryString.feature = this.map.currentFeature.getSlug()
} }
if (this.options.keepCurrentDatalayers) { if (this.options.keepCurrentDatalayers) {
this.map.eachDataLayer(function (datalayer) { this.map.eachDataLayer((datalayer) => {
if (datalayer.isVisible() && datalayer.umap_id) { if (datalayer.isVisible() && datalayer.umap_id) {
datalayers.push(datalayer.umap_id) datalayers.push(datalayer.umap_id)
} }
@ -1272,7 +1272,7 @@ L.U.Editable = L.Editable.extend({
) )
this.on('editable:drawing:end', this.closeTooltip) this.on('editable:drawing:end', this.closeTooltip)
// Layer for items added by users // Layer for items added by users
this.on('editable:drawing:cancel', function (e) { this.on('editable:drawing:cancel', (e) => {
if (e.layer._latlngs && e.layer._latlngs.length < e.layer.editor.MIN_VERTEX) if (e.layer._latlngs && e.layer._latlngs.length < e.layer.editor.MIN_VERTEX)
e.layer.del() e.layer.del()
if (e.layer instanceof L.U.Marker) e.layer.del() if (e.layer instanceof L.U.Marker) e.layer.del()
@ -1281,7 +1281,7 @@ L.U.Editable = L.Editable.extend({
e.layer.isDirty = true e.layer.isDirty = true
if (this.map.editedFeature !== e.layer) e.layer.edit(e) if (this.map.editedFeature !== e.layer) e.layer.edit(e)
}) })
this.on('editable:editing', function (e) { this.on('editable:editing', (e) => {
var layer = e.layer var layer = e.layer
layer.isDirty = true layer.isDirty = true
if (layer._tooltip && layer.isTooltipOpen()) { if (layer._tooltip && layer.isTooltipOpen()) {
@ -1289,12 +1289,12 @@ L.U.Editable = L.Editable.extend({
layer._tooltip.update() layer._tooltip.update()
} }
}) })
this.on('editable:vertex:ctrlclick', function (e) { this.on('editable:vertex:ctrlclick', (e) => {
var index = e.vertex.getIndex() var index = e.vertex.getIndex()
if (index === 0 || (index === e.vertex.getLastIndex() && e.vertex.continue)) if (index === 0 || (index === e.vertex.getLastIndex() && e.vertex.continue))
e.vertex.continue() e.vertex.continue()
}) })
this.on('editable:vertex:altclick', function (e) { this.on('editable:vertex:altclick', (e) => {
if (e.vertex.editor.vertexCanBeDeleted(e.vertex)) e.vertex.delete() if (e.vertex.editor.vertexCanBeDeleted(e.vertex)) e.vertex.delete()
}) })
this.on('editable:vertex:rawclick', this.onVertexRawClick) this.on('editable:vertex:rawclick', this.onVertexRawClick)

View file

@ -7,10 +7,8 @@ L.U.Map = L.Map.extend({})
/* /*
* Utils * Utils
*/ */
L.Util.queryString = function (name, fallback) { L.Util.queryString = (name, fallback) => {
var decode = function (s) { var decode = (s) => decodeURIComponent(s.replace(/\+/g, ' '))
return decodeURIComponent(s.replace(/\+/g, ' '))
}
var qs = window.location.search.slice(1).split('&'), var qs = window.location.search.slice(1).split('&'),
qa = {} qa = {}
for (var i in qs) { for (var i in qs) {
@ -21,21 +19,21 @@ L.Util.queryString = function (name, fallback) {
return qa[name] || fallback return qa[name] || fallback
} }
L.Util.booleanFromQueryString = function (name) { L.Util.booleanFromQueryString = (name) => {
var value = L.Util.queryString(name) var value = L.Util.queryString(name)
return value === '1' || value === 'true' return value === '1' || value === 'true'
} }
L.Util.setFromQueryString = function (options, name) { L.Util.setFromQueryString = (options, name) => {
var value = L.Util.queryString(name) var value = L.Util.queryString(name)
if (typeof value !== 'undefined') options[name] = value if (typeof value !== 'undefined') options[name] = value
} }
L.Util.setBooleanFromQueryString = function (options, name) { L.Util.setBooleanFromQueryString = (options, name) => {
var value = L.Util.queryString(name) var value = L.Util.queryString(name)
if (typeof value !== 'undefined') options[name] = value == '1' || value == 'true' if (typeof value !== 'undefined') options[name] = value == '1' || value == 'true'
} }
L.Util.setNullableBooleanFromQueryString = function (options, name) { L.Util.setNullableBooleanFromQueryString = (options, name) => {
var value = L.Util.queryString(name) var value = L.Util.queryString(name)
if (typeof value !== 'undefined') { if (typeof value !== 'undefined') {
if (value === 'null') value = null if (value === 'null') value = null
@ -44,11 +42,11 @@ L.Util.setNullableBooleanFromQueryString = function (options, name) {
options[name] = value options[name] = value
} }
} }
L.Util.escapeHTML = function (s) { L.Util.escapeHTML = (s) => {
s = s ? s.toString() : '' s = s ? s.toString() : ''
return s.replace(/</gm, '&lt;') return s.replace(/</gm, '&lt;')
} }
L.Util.toHTML = function (r) { L.Util.toHTML = (r) => {
if (!r) return '' if (!r) return ''
var ii var ii
@ -113,13 +111,9 @@ L.Util.toHTML = function (r) {
return r return r
} }
L.Util.isObject = function (what) { L.Util.isObject = (what) => typeof what === 'object' && what !== null
return typeof what === 'object' && what !== null L.Util.CopyJSON = (geojson) => JSON.parse(JSON.stringify(geojson))
} L.Util.detectFileType = (f) => {
L.Util.CopyJSON = function (geojson) {
return JSON.parse(JSON.stringify(geojson))
}
L.Util.detectFileType = function (f) {
var filename = f.name ? escape(f.name.toLowerCase()) : '' var filename = f.name ? escape(f.name.toLowerCase()) : ''
function ext(_) { function ext(_) {
return filename.indexOf(_) !== -1 return filename.indexOf(_) !== -1
@ -136,11 +130,10 @@ L.Util.detectFileType = function (f) {
if (ext('.umap')) return 'umap' if (ext('.umap')) return 'umap'
} }
L.Util.usableOption = function (options, option) { L.Util.usableOption = (options, option) =>
return options[option] !== undefined && options[option] !== '' options[option] !== undefined && options[option] !== ''
}
L.Util.greedyTemplate = function (str, data, ignore) { L.Util.greedyTemplate = (str, data, ignore) => {
function getValue(data, path) { function getValue(data, path) {
var value = data var value = data
for (var i = 0; i < path.length; i++) { for (var i = 0; i < path.length; i++) {
@ -152,7 +145,7 @@ L.Util.greedyTemplate = function (str, data, ignore) {
return str.replace( return str.replace(
/\{ *([\w_\:\.\|]+)(?:\|("[^"]*"))? *\}/g, /\{ *([\w_\:\.\|]+)(?:\|("[^"]*"))? *\}/g,
function (str, key, staticFallback) { (str, key, staticFallback) => {
var vars = key.split('|'), var vars = key.split('|'),
value, value,
path path
@ -175,10 +168,10 @@ L.Util.greedyTemplate = function (str, data, ignore) {
) )
} }
L.Util.sortFeatures = function (features, sortKey) { L.Util.sortFeatures = (features, sortKey) => {
var sortKeys = (sortKey || 'name').split(',') var sortKeys = (sortKey || 'name').split(',')
var sort = function (a, b, i) { var sort = (a, b, i) => {
var sortKey = sortKeys[i], var sortKey = sortKeys[i],
score, score,
valA = a.properties[sortKey] || '', valA = a.properties[sortKey] || '',
@ -194,7 +187,7 @@ L.Util.sortFeatures = function (features, sortKey) {
return score return score
} }
features.sort(function (a, b) { features.sort((a, b) => {
if (!a.properties || !b.properties) { if (!a.properties || !b.properties) {
return 0 return 0
} }
@ -204,12 +197,12 @@ L.Util.sortFeatures = function (features, sortKey) {
return features return features
} }
L.Util.flattenCoordinates = function (coords) { L.Util.flattenCoordinates = (coords) => {
while (coords[0] && typeof coords[0][0] !== 'number') coords = coords[0] while (coords[0] && typeof coords[0][0] !== 'number') coords = coords[0]
return coords return coords
} }
L.Util.buildQueryString = function (params) { L.Util.buildQueryString = (params) => {
var query_string = [] var query_string = []
for (var key in params) { for (var key in params) {
query_string.push(encodeURIComponent(key) + '=' + encodeURIComponent(params[key])) query_string.push(encodeURIComponent(key) + '=' + encodeURIComponent(params[key]))
@ -217,11 +210,9 @@ L.Util.buildQueryString = function (params) {
return query_string.join('&') return query_string.join('&')
} }
L.Util.getBaseUrl = function () { L.Util.getBaseUrl = () => '//' + window.location.host + window.location.pathname
return '//' + window.location.host + window.location.pathname
}
L.DomUtil.add = function (tagName, className, container, content) { L.DomUtil.add = (tagName, className, container, content) => {
var el = L.DomUtil.create(tagName, className, container) var el = L.DomUtil.create(tagName, className, container)
if (content) { if (content) {
if (content.nodeType && content.nodeType === 1) { if (content.nodeType && content.nodeType === 1) {
@ -233,7 +224,7 @@ L.DomUtil.add = function (tagName, className, container, content) {
return el return el
} }
L.DomUtil.createFieldset = function (container, legend, options) { L.DomUtil.createFieldset = (container, legend, options) => {
options = options || {} options = options || {}
var fieldset = L.DomUtil.create('div', 'fieldset toggle', container) var fieldset = L.DomUtil.create('div', 'fieldset toggle', container)
var legendEl = L.DomUtil.add('h5', 'legend style_options_toggle', fieldset, legend) var legendEl = L.DomUtil.add('h5', 'legend style_options_toggle', fieldset, legend)
@ -249,12 +240,12 @@ L.DomUtil.createFieldset = function (container, legend, options) {
return fieldsEl return fieldsEl
} }
L.DomUtil.classIf = function (el, className, bool) { L.DomUtil.classIf = (el, className, bool) => {
if (bool) L.DomUtil.addClass(el, className) if (bool) L.DomUtil.addClass(el, className)
else L.DomUtil.removeClass(el, className) else L.DomUtil.removeClass(el, className)
} }
L.DomUtil.element = function (what, attrs, parent) { L.DomUtil.element = (what, attrs, parent) => {
var el = document.createElement(what) var el = document.createElement(what)
for (var attr in attrs) { for (var attr in attrs) {
el[attr] = attrs[attr] el[attr] = attrs[attr]
@ -265,19 +256,19 @@ L.DomUtil.element = function (what, attrs, parent) {
return el return el
} }
L.DomUtil.before = function (target, el) { L.DomUtil.before = (target, el) => {
target.parentNode.insertBefore(el, target) target.parentNode.insertBefore(el, target)
return el return el
} }
L.DomUtil.after = function (target, el) { L.DomUtil.after = (target, el) => {
target.parentNode.insertBefore(el, target.nextSibling) target.parentNode.insertBefore(el, target.nextSibling)
return el return el
} }
L.DomUtil.RGBRegex = /rgb *\( *([0-9]{1,3}) *, *([0-9]{1,3}) *, *([0-9]{1,3}) *\)/ L.DomUtil.RGBRegex = /rgb *\( *([0-9]{1,3}) *, *([0-9]{1,3}) *, *([0-9]{1,3}) *\)/
L.DomUtil.TextColorFromBackgroundColor = function (el) { L.DomUtil.TextColorFromBackgroundColor = (el) => {
var out = '#000000' var out = '#000000'
if (!window.getComputedStyle) { if (!window.getComputedStyle) {
return out return out
@ -293,7 +284,7 @@ L.DomUtil.TextColorFromBackgroundColor = function (el) {
} }
return out return out
} }
L.DomEvent.once = function (el, types, fn, context) { L.DomEvent.once = (el, types, fn, context) => {
// cf https://github.com/Leaflet/Leaflet/pull/3528#issuecomment-134551575 // cf https://github.com/Leaflet/Leaflet/pull/3528#issuecomment-134551575
if (typeof types === 'object') { if (typeof types === 'object') {
@ -303,7 +294,7 @@ L.DomEvent.once = function (el, types, fn, context) {
return L.DomEvent return L.DomEvent
} }
var handler = L.bind(function () { var handler = L.bind(() => {
L.DomEvent.off(el, types, fn, context).off(el, types, handler, context) L.DomEvent.off(el, types, fn, context).off(el, types, handler, context)
}, L.DomEvent) }, L.DomEvent)
@ -405,7 +396,7 @@ L.U.Help = L.Class.extend({
self = this, self = this,
title = L.DomUtil.create('h3', '', container), title = L.DomUtil.create('h3', '', container),
actionsContainer = L.DomUtil.create('ul', 'umap-edit-actions', container) actionsContainer = L.DomUtil.create('ul', 'umap-edit-actions', container)
var addAction = function (action) { var addAction = (action) => {
var actionContainer = L.DomUtil.add('li', '', actionsContainer) var actionContainer = L.DomUtil.add('li', '', actionsContainer)
L.DomUtil.add('i', action.options.className, actionContainer), L.DomUtil.add('i', action.options.className, actionContainer),
L.DomUtil.add('span', '', actionContainer, action.options.tooltip) L.DomUtil.add('span', '', actionContainer, action.options.tooltip)

View file

@ -622,7 +622,7 @@ L.U.Marker = L.Marker.extend({
zoomTo: function (e) { zoomTo: function (e) {
if (this.datalayer.isClustered() && !this._icon) { if (this.datalayer.isClustered() && !this._icon) {
// callback is mandatory for zoomToShowLayer // callback is mandatory for zoomToShowLayer
this.datalayer.layer.zoomToShowLayer(this, e.callback || function () {}) this.datalayer.layer.zoomToShowLayer(this, e.callback || (() => {}))
} else { } else {
L.U.FeatureMixin.zoomTo.call(this, e) L.U.FeatureMixin.zoomTo.call(this, e)
} }

View file

@ -296,7 +296,7 @@ L.FormBuilder.ColorPicker = L.FormBuilder.Input.extend({
onBlur: function () { onBlur: function () {
var self = this, var self = this,
closePicker = function () { closePicker = () => {
self.container.style.display = 'none' self.container.style.display = 'none'
} }
// We must leave time for the click to be listened. // We must leave time for the click to be listened.
@ -395,7 +395,7 @@ L.FormBuilder.SlideshowDelay = L.FormBuilder.IntSelect.extend({
L.FormBuilder.DataLayerSwitcher = L.FormBuilder.Select.extend({ L.FormBuilder.DataLayerSwitcher = L.FormBuilder.Select.extend({
getOptions: function () { getOptions: function () {
var options = [] var options = []
this.builder.map.eachDataLayerReverse(function (datalayer) { this.builder.map.eachDataLayerReverse((datalayer) => {
if (datalayer.isLoaded() && !datalayer.isRemoteLayer() && datalayer.canBrowse()) { if (datalayer.isLoaded() && !datalayer.isRemoteLayer() && datalayer.canBrowse()) {
options.push([L.stamp(datalayer), datalayer.getName()]) options.push([L.stamp(datalayer), datalayer.getName()])
} }
@ -864,9 +864,7 @@ L.FormBuilder.ManageEditors = L.FormBuilder.Element.extend({
}, },
onUnselect: function (choice) { onUnselect: function (choice) {
var index = this._values.findIndex(function (item) { var index = this._values.findIndex((item) => item.id === choice.item.value)
return item.id === choice.item.value
})
if (index !== -1) { if (index !== -1) {
this._values.splice(index, 1) this._values.splice(index, 1)
this.set() this.set()

View file

@ -256,7 +256,7 @@ L.U.Map.include({
if (slug && this.features_index[slug]) this.features_index[slug].view() if (slug && this.features_index[slug]) this.features_index[slug].view()
}) })
window.onbeforeunload = function (e) { window.onbeforeunload = (e) => {
var msg = L._('You have unsaved changes.') var msg = L._('You have unsaved changes.')
if (self.isDirty) { if (self.isDirty) {
e.returnValue = msg e.returnValue = msg
@ -376,19 +376,19 @@ L.U.Map.include({
var toload = (dataToload = seen = this.options.datalayers.length), var toload = (dataToload = seen = this.options.datalayers.length),
self = this, self = this,
datalayer datalayer
var loaded = function () { var loaded = () => {
self.datalayersLoaded = true self.datalayersLoaded = true
self.fire('datalayersloaded') self.fire('datalayersloaded')
} }
var decrementToLoad = function () { var decrementToLoad = () => {
toload-- toload--
if (toload === 0) loaded() if (toload === 0) loaded()
} }
var dataLoaded = function () { var dataLoaded = () => {
self.dataLoaded = true self.dataLoaded = true
self.fire('dataloaded') self.fire('dataloaded')
} }
var decrementDataToLoad = function () { var decrementDataToLoad = () => {
dataToload-- dataToload--
if (dataToload === 0) dataLoaded() if (dataToload === 0) dataLoaded()
} }
@ -415,7 +415,7 @@ L.U.Map.include({
}, },
ensurePanesOrder: function () { ensurePanesOrder: function () {
this.eachDataLayer(function (datalayer) { this.eachDataLayer((datalayer) => {
datalayer.bringToTop() datalayer.bringToTop()
}) })
}, },
@ -709,7 +709,7 @@ L.U.Map.include({
updateTileLayers: function () { updateTileLayers: function () {
var self = this, var self = this,
callback = function (tilelayer) { callback = (tilelayer) => {
self.options.tilelayer = tilelayer.toJSON() self.options.tilelayer = tilelayer.toJSON()
self.isDirty = true self.isDirty = true
} }
@ -757,7 +757,7 @@ L.U.Map.include({
UIFields.push('queryString.' + this.HIDDABLE_CONTROLS[i] + 'Control') UIFields.push('queryString.' + this.HIDDABLE_CONTROLS[i] + 'Control')
} }
var iframeExporter = new L.U.IframeExporter(this) var iframeExporter = new L.U.IframeExporter(this)
var buildIframeCode = function () { var buildIframeCode = () => {
iframe.innerHTML = iframeExporter.build() iframe.innerHTML = iframeExporter.build()
} }
buildIframeCode() buildIframeCode()
@ -787,7 +787,7 @@ L.U.Map.include({
L._('Only visible features will be downloaded.') L._('Only visible features will be downloaded.')
) )
exportCaveat.id = 'export_caveat_text' exportCaveat.id = 'export_caveat_text'
var toggleCaveat = function () { var toggleCaveat = () => {
if (typeInput.value === 'umap') exportCaveat.style.display = 'none' if (typeInput.value === 'umap') exportCaveat.style.display = 'none'
else exportCaveat.style.display = 'inherit' else exportCaveat.style.display = 'inherit'
} }
@ -855,7 +855,7 @@ L.U.Map.include({
toGeoJSON: function () { toGeoJSON: function () {
var features = [] var features = []
this.eachDataLayer(function (datalayer) { this.eachDataLayer((datalayer) => {
if (datalayer.isVisible()) { if (datalayer.isVisible()) {
features = features.concat(datalayer.featuresToGeoJSON()) features = features.concat(datalayer.featuresToGeoJSON())
} }
@ -903,7 +903,7 @@ L.U.Map.include({
var clearFlag = L.DomUtil.create('input', '', clearLabel) var clearFlag = L.DomUtil.create('input', '', clearLabel)
clearFlag.type = 'checkbox' clearFlag.type = 'checkbox'
clearFlag.name = 'clear' clearFlag.name = 'clear'
this.eachDataLayerReverse(function (datalayer) { this.eachDataLayerReverse((datalayer) => {
if (datalayer.isLoaded() && !datalayer.isRemoteLayer()) { if (datalayer.isLoaded() && !datalayer.isRemoteLayer()) {
var id = L.stamp(datalayer) var id = L.stamp(datalayer)
option = L.DomUtil.create('option', '', layerInput) option = L.DomUtil.create('option', '', layerInput)
@ -995,7 +995,7 @@ L.U.Map.include({
L.DomEvent.on( L.DomEvent.on(
fileInput, fileInput,
'change', 'change',
function (e) { (e) => {
var type = '', var type = '',
newType newType
for (var i = 0; i < e.target.files.length; i++) { for (var i = 0; i < e.target.files.length; i++) {
@ -1028,7 +1028,7 @@ L.U.Map.include({
if (importedData.geometry) this.options.center = this.latLng(importedData.geometry) if (importedData.geometry) this.options.center = this.latLng(importedData.geometry)
var self = this var self = this
importedData.layers.forEach(function (geojson) { importedData.layers.forEach((geojson) => {
var dataLayer = self.createDataLayer() var dataLayer = self.createDataLayer()
dataLayer.fromUmapGeoJSON(geojson) dataLayer.fromUmapGeoJSON(geojson)
}) })
@ -1036,7 +1036,7 @@ L.U.Map.include({
this.initTileLayers() this.initTileLayers()
this.renderControls() this.renderControls()
this.handleLimitBounds() this.handleLimitBounds()
this.eachDataLayer(function (datalayer) { this.eachDataLayer((datalayer) => {
if (mustReindex) datalayer.reindex() if (mustReindex) datalayer.reindex()
datalayer.redraw() datalayer.redraw()
}) })
@ -1048,7 +1048,7 @@ L.U.Map.include({
var reader = new FileReader() var reader = new FileReader()
reader.readAsText(file) reader.readAsText(file)
var self = this var self = this
reader.onload = function (e) { reader.onload = (e) => {
var rawData = e.target.result var rawData = e.target.result
try { try {
self.importRaw(rawData) self.importRaw(rawData)
@ -1084,7 +1084,7 @@ L.U.Map.include({
description.innerHTML = L.Util.toHTML(this.options.description) description.innerHTML = L.Util.toHTML(this.options.description)
} }
var datalayerContainer = L.DomUtil.create('div', 'datalayer-container', container) var datalayerContainer = L.DomUtil.create('div', 'datalayer-container', container)
this.eachVisibleDataLayer(function (datalayer) { this.eachVisibleDataLayer((datalayer) => {
var p = L.DomUtil.create('p', '', datalayerContainer), var p = L.DomUtil.create('p', '', datalayerContainer),
color = L.DomUtil.create('span', 'datalayer-color', p), color = L.DomUtil.create('span', 'datalayer-color', p),
headline = L.DomUtil.create('strong', '', p), headline = L.DomUtil.create('strong', '', p),
@ -1171,15 +1171,11 @@ L.U.Map.include({
}, },
eachBrowsableDataLayer: function (method, context) { eachBrowsableDataLayer: function (method, context) {
this.eachDataLayerReverse(method, context, function (d) { this.eachDataLayerReverse(method, context, (d) => d.allowBrowse())
return d.allowBrowse()
})
}, },
eachVisibleDataLayer: function (method, context) { eachVisibleDataLayer: function (method, context) {
this.eachDataLayerReverse(method, context, function (d) { this.eachDataLayerReverse(method, context, (d) => d.isVisible())
return d.isVisible()
})
}, },
findDataLayer: function (method, context) { findDataLayer: function (method, context) {
@ -1198,7 +1194,7 @@ L.U.Map.include({
if (this.editTools) this.editTools.stopDrawing() if (this.editTools) this.editTools.stopDrawing()
this.resetOptions() this.resetOptions()
this.datalayers_index = [].concat(this._datalayers_index_bk) this.datalayers_index = [].concat(this._datalayers_index_bk)
this.dirty_datalayers.slice().forEach(function (datalayer) { this.dirty_datalayers.slice().forEach((datalayer) => {
if (datalayer.isDeleted) datalayer.connectToMap() if (datalayer.isDeleted) datalayer.connectToMap()
datalayer.reset() datalayer.reset()
}) })
@ -1308,7 +1304,7 @@ L.U.Map.include({
layers: [], layers: [],
} }
this.eachDataLayer(function (datalayer) { this.eachDataLayer((datalayer) => {
umapfile.layers.push(datalayer.umapGeoJSON()) umapfile.layers.push(datalayer.umapGeoJSON())
}) })
@ -1414,7 +1410,7 @@ L.U.Map.include({
) { ) {
return datalayer return datalayer
} }
datalayer = this.findDataLayer(function (datalayer) { datalayer = this.findDataLayer((datalayer) => {
if (!datalayer.isRemoteLayer() && datalayer.canBrowse()) { if (!datalayer.isRemoteLayer() && datalayer.canBrowse()) {
fallback = datalayer fallback = datalayer
if (datalayer.isVisible()) return true if (datalayer.isVisible()) return true
@ -1430,9 +1426,7 @@ L.U.Map.include({
}, },
getDataLayerByUmapId: function (umap_id) { getDataLayerByUmapId: function (umap_id) {
return this.findDataLayer(function (d) { return this.findDataLayer((d) => d.umap_id == umap_id)
return d.umap_id == umap_id
})
}, },
_editControls: function (container) { _editControls: function (container) {
@ -1478,7 +1472,7 @@ L.U.Map.include({
builder = new L.U.FormBuilder(this, shapeOptions, { builder = new L.U.FormBuilder(this, shapeOptions, {
callback: function (e) { callback: function (e) {
this.eachDataLayer(function (datalayer) { this.eachDataLayer((datalayer) => {
datalayer.redraw() datalayer.redraw()
}) })
}, },
@ -1541,7 +1535,7 @@ L.U.Map.include({
builder = new L.U.FormBuilder(this, optionsFields, { builder = new L.U.FormBuilder(this, optionsFields, {
callback: function (e) { callback: function (e) {
this.initCaptionBar() this.initCaptionBar()
this.eachDataLayer(function (datalayer) { this.eachDataLayer((datalayer) => {
if (e.helper.field === 'options.sortKey') datalayer.reindex() if (e.helper.field === 'options.sortKey') datalayer.reindex()
datalayer.redraw() datalayer.redraw()
}) })
@ -1571,7 +1565,7 @@ L.U.Map.include({
e.helper.field === 'options.popupShape' e.helper.field === 'options.popupShape'
) )
return return
this.eachDataLayer(function (datalayer) { this.eachDataLayer((datalayer) => {
datalayer.redraw() datalayer.redraw()
}) })
}, },
@ -2015,7 +2009,7 @@ L.U.Map.include({
}, },
empty: function () { empty: function () {
this.eachDataLayerReverse(function (datalayer) { this.eachDataLayerReverse((datalayer) => {
datalayer._delete() datalayer._delete()
}) })
}, },

View file

@ -343,9 +343,7 @@ L.U.DataLayer = L.Evented.extend({
reindex: function () { reindex: function () {
var features = [] var features = []
this.eachFeature(function (feature) { this.eachFeature((feature) => features.push(feature))
features.push(feature)
})
L.Util.sortFeatures(features, this.map.getOption('sortKey')) L.Util.sortFeatures(features, this.map.getOption('sortKey'))
this._index = [] this._index = []
for (var i = 0; i < features.length; i++) { for (var i = 0; i < features.length; i++) {
@ -366,18 +364,17 @@ L.U.DataLayer = L.Evented.extend({
} }
if (!this.options.remoteData.dynamic && this.hasDataLoaded()) return if (!this.options.remoteData.dynamic && this.hasDataLoaded()) return
if (!this.isVisible()) return if (!this.isVisible()) return
var self = this, var url = this.map.localizeUrl(this.options.remoteData.url)
url = this.map.localizeUrl(this.options.remoteData.url)
if (this.options.remoteData.proxy) if (this.options.remoteData.proxy)
url = this.map.proxyUrl(url, this.options.remoteData.ttl) url = this.map.proxyUrl(url, this.options.remoteData.ttl)
this.map.ajax({ this.map.ajax({
uri: url, uri: url,
verb: 'GET', verb: 'GET',
callback: function (raw) { callback: (raw) => {
self.clear() this.clear()
self.rawToGeoJSON(raw, self.options.remoteData.format, function (geojson) { this.rawToGeoJSON(raw, this.options.remoteData.format, (geojson) =>
self.fromGeoJSON(geojson) this.fromGeoJSON(geojson)
}) )
}, },
}) })
}, },
@ -508,17 +505,11 @@ L.U.DataLayer = L.Evented.extend({
}, },
addRawData: function (c, type) { addRawData: function (c, type) {
var self = this this.rawToGeoJSON(c, type, (geojson) => this.addData(geojson))
this.rawToGeoJSON(c, type, function (geojson) {
self.addData(geojson)
})
}, },
rawToGeoJSON: function (c, type, callback) { rawToGeoJSON: function (c, type, callback) {
var self = this var toDom = (x) => new DOMParser().parseFromString(x, 'text/xml')
var toDom = function (x) {
return new DOMParser().parseFromString(x, 'text/xml')
}
// TODO add a duck typing guessType // TODO add a duck typing guessType
if (type === 'csv') { if (type === 'csv') {
@ -528,7 +519,7 @@ L.U.DataLayer = L.Evented.extend({
delimiter: 'auto', delimiter: 'auto',
includeLatLon: false, includeLatLon: false,
}, },
function (err, result) { (err, result) => {
if (err) { if (err) {
var message var message
if (err.type === 'Error') { if (err.type === 'Error') {
@ -539,7 +530,7 @@ L.U.DataLayer = L.Evented.extend({
message: err[0].message, message: err[0].message,
}) })
} }
self.map.ui.alert({ content: message, level: 'error', duration: 10000 }) this.map.ui.alert({ content: message, level: 'error', duration: 10000 })
console.log(err) console.log(err)
} }
if (result && result.features.length) { if (result && result.features.length) {
@ -566,7 +557,7 @@ L.U.DataLayer = L.Evented.extend({
var gj = JSON.parse(c) var gj = JSON.parse(c)
callback(gj) callback(gj)
} catch (err) { } catch (err) {
self.map.ui.alert({ content: 'Invalid JSON file: ' + err }) this.map.ui.alert({ content: 'Invalid JSON file: ' + err })
return return
} }
} }
@ -670,24 +661,18 @@ L.U.DataLayer = L.Evented.extend({
}, },
importFromFile: function (f, type) { importFromFile: function (f, type) {
var reader = new FileReader(), var reader = new FileReader()
self = this
type = type || L.Util.detectFileType(f) type = type || L.Util.detectFileType(f)
reader.readAsText(f) reader.readAsText(f)
reader.onload = function (e) { reader.onload = (e) => this.importRaw(e.target.result, type)
self.importRaw(e.target.result, type)
}
}, },
importFromUrl: function (url, type) { importFromUrl: function (url, type) {
url = this.map.localizeUrl(url) url = this.map.localizeUrl(url)
var self = this
this.map.xhr._ajax({ this.map.xhr._ajax({
verb: 'GET', verb: 'GET',
uri: url, uri: url,
callback: function (data) { callback: (data) => this.importRaw(data, type),
self.importRaw(data, type)
},
}) })
}, },
@ -1034,9 +1019,7 @@ L.U.DataLayer = L.Evented.extend({
featuresToGeoJSON: function () { featuresToGeoJSON: function () {
var features = [] var features = []
this.eachLayer(function (layer) { this.eachLayer((layer) => features.push(layer.toGeoJSON()))
features.push(layer.toGeoJSON())
})
return features return features
}, },

View file

@ -140,9 +140,7 @@ L.U.MapPermissions = L.Class.extend({
if (!this.isDirty) return this.map.continueSaving() if (!this.isDirty) return this.map.continueSaving()
var formData = new FormData() var formData = new FormData()
if (!this.isAnonymousMap() && this.options.editors) { if (!this.isAnonymousMap() && this.options.editors) {
var editors = this.options.editors.map(function (u) { var editors = this.options.editors.map((u) => u.id)
return u.id
})
for (var i = 0; i < this.options.editors.length; i++) for (var i = 0; i < this.options.editors.length; i++)
formData.append('editors', this.options.editors[i].id) formData.append('editors', this.options.editors[i].id)
} }

View file

@ -136,10 +136,10 @@ L.U.PopupTemplate.Default = L.Class.extend({
feature: prev.properties.name || L._('previous'), feature: prev.properties.name || L._('previous'),
}) })
zoomLi.title = L._('Zoom to this feature') zoomLi.title = L._('Zoom to this feature')
L.DomEvent.on(nextLi, 'click', function () { L.DomEvent.on(nextLi, 'click', () => {
if (next) next.zoomTo({ callback: next.view }) if (next) next.zoomTo({ callback: next.view })
}) })
L.DomEvent.on(previousLi, 'click', function () { L.DomEvent.on(previousLi, 'click', () => {
if (prev) prev.zoomTo({ callback: prev.view }) if (prev) prev.zoomTo({ callback: prev.view })
}) })
L.DomEvent.on( L.DomEvent.on(

View file

@ -62,9 +62,7 @@ L.U.Slideshow = L.Class.extend({
}, },
defaultDatalayer: function () { defaultDatalayer: function () {
return this.map.findDataLayer(function (d) { return this.map.findDataLayer((d) => d.allowBrowse() && d.hasData())
return d.allowBrowse() && d.hasData()
})
}, },
timeSpinner: function () { timeSpinner: function () {

View file

@ -27,7 +27,7 @@ L.U.TableEditor = L.Class.extend({
L._('Are you sure you want to delete this property on all the features?') L._('Are you sure you want to delete this property on all the features?')
) )
) { ) {
this.datalayer.eachLayer(function (feature) { this.datalayer.eachLayer((feature) => {
feature.deleteProperty(property) feature.deleteProperty(property)
}) })
this.datalayer.deindexProperty(property) this.datalayer.deindexProperty(property)
@ -38,7 +38,7 @@ L.U.TableEditor = L.Class.extend({
var doRename = function () { var doRename = function () {
var newName = prompt(L._('Please enter the new name of this property'), property) var newName = prompt(L._('Please enter the new name of this property'), property)
if (!newName || !this.validateName(newName)) return if (!newName || !this.validateName(newName)) return
this.datalayer.eachLayer(function (feature) { this.datalayer.eachLayer((feature) => {
feature.renameProperty(property, newName) feature.renameProperty(property, newName)
}) })
this.datalayer.deindexProperty(property) this.datalayer.deindexProperty(property)

View file

@ -6,7 +6,7 @@ L.U.Xhr = L.Evented.extend({
_wrapper: function () { _wrapper: function () {
var wrapper var wrapper
if (window.XMLHttpRequest === undefined) { if (window.XMLHttpRequest === undefined) {
wrapper = function () { wrapper = () => {
try { try {
return new window.ActiveXObject('Microsoft.XMLHTTP.6.0') return new window.ActiveXObject('Microsoft.XMLHTTP.6.0')
} catch (e1) { } catch (e1) {
@ -28,7 +28,7 @@ L.U.Xhr = L.Evented.extend({
id = Math.random(), id = Math.random(),
self = this self = this
this.fire('dataloading', { id: id }) this.fire('dataloading', { id: id })
var loaded = function () { var loaded = () => {
self.fire('dataload', { id: id }) self.fire('dataload', { id: id })
} }
@ -58,7 +58,7 @@ L.U.Xhr = L.Evented.extend({
} }
} }
xhr.onreadystatechange = function () { xhr.onreadystatechange = () => {
if (xhr.readyState === 4) { if (xhr.readyState === 4) {
if (xhr.status == 200) { if (xhr.status == 200) {
settings.callback.call(settings.context || xhr, xhr.responseText, xhr) settings.callback.call(settings.context || xhr, xhr.responseText, xhr)
@ -194,7 +194,7 @@ L.U.Xhr = L.Evented.extend({
if (!form) return if (!form) return
L.DomEvent.on(form, 'submit', L.DomEvent.stopPropagation) L.DomEvent.on(form, 'submit', L.DomEvent.stopPropagation)
.on(form, 'submit', L.DomEvent.preventDefault) .on(form, 'submit', L.DomEvent.preventDefault)
.on(form, 'submit', function () { .on(form, 'submit', () => {
self.submit_form(form_id, options) self.submit_form(form_id, options)
}) })
}, },
@ -203,7 +203,7 @@ L.U.Xhr = L.Evented.extend({
var link = L.DomUtil.get(link_id), var link = L.DomUtil.get(link_id),
self = this self = this
if (link) { if (link) {
L.DomEvent.on(link, 'click', L.DomEvent.stop).on(link, 'click', function () { L.DomEvent.on(link, 'click', L.DomEvent.stop).on(link, 'click', () => {
if (options.confirm && !confirm(options.confirm)) { if (options.confirm && !confirm(options.confirm)) {
return return
} }
@ -252,12 +252,12 @@ L.U.Xhr = L.Evented.extend({
// data.html: login form // data.html: login form
// args: args of the first _json call, to call again at process end // args: args of the first _json call, to call again at process end
var self = this var self = this
var proceed = function () { var proceed = () => {
self.ui.closePanel() self.ui.closePanel()
if (typeof args !== 'undefined') self._json.apply(self, args) if (typeof args !== 'undefined') self._json.apply(self, args)
else self.default_callback(data, {}) else self.default_callback(data, {})
} }
var ask_for_login = function (data) { var ask_for_login = (data) => {
self.ui.openPanel({ data: data, className: 'login-panel' }) self.ui.openPanel({ data: data, className: 'login-panel' })
self.listen_form('login_form', { self.listen_form('login_form', {
callback: function (data) { callback: function (data) {
@ -267,12 +267,12 @@ L.U.Xhr = L.Evented.extend({
}) })
// Auth links // Auth links
var links = document.getElementsByClassName('umap-login-popup') var links = document.getElementsByClassName('umap-login-popup')
Object.keys(links).forEach(function (el) { Object.keys(links).forEach((el) => {
var link = links[el] var link = links[el]
L.DomEvent.on(link, 'click', L.DomEvent.stop).on(link, 'click', function () { L.DomEvent.on(link, 'click', L.DomEvent.stop).on(link, 'click', () => {
self.ui.closePanel() self.ui.closePanel()
var win = window.open(link.href) var win = window.open(link.href)
window.umap_proceed = function () { window.umap_proceed = () => {
proceed() proceed()
win.close() win.close()
} }