stefanocudini / leaflet-search

Search stuff in a Leaflet map
https://opengeo.tech/maps/leaflet-search/
MIT License
772 stars 334 forks source link

Refactoring - Reformatting #308

Closed trasherdk closed 1 year ago

trasherdk commented 1 year ago

While going down the list of errors found by standard.js a few stand out:

Is detection of AMD still a thing? I can't remember running in to something using it. 'define' is not defined. (no-undef)

(function (factory) {
  if (typeof define === 'function' && define.amd) { <== 'define' is not defined. (no-undef)
    // AMD
    define(['leaflet'], factory)
  } else if (typeof module !== 'undefined') {
    // Node/CommonJS
    module.exports = factory(require('leaflet'))
  } else {
    // Browser globals
    if (typeof window.L === 'undefined') { throw new Error('Leaflet must be loaded first') }
    factory(window.L)
  }
})

I have no idea what to do with that AMD thingy. Any sugestions?

Support for IE 8/9. I know that's not a thing. I think, in the case XMLHttpRequest() not available, just throw that error.

let request

try {
  request = new window.XMLHttpRequest()
} catch (e) {
  throw new Error('XMLHttpRequest is not supported')
}

The non-existing labs-common.js Google tracking script is just an annoyance. I'm not in favor of visitor tracking, but it's your web-site.

So far, I have only touched files in /src and fixed all but the AMD thing, except from adding your favicon.png to index.html and examples/geocoding-nominatim.html.

I have pushed my changes to format/refactor branch.

Next I will jump into examples directory, if you want.

trasherdk commented 1 year ago

BTW: The changes are running on Leaflet.Control.Search