Make icons search accent insensitive
This commit is contained in:
parent
8a2109948f
commit
c581172197
3 changed files with 34 additions and 18 deletions
|
@ -287,6 +287,13 @@ L.Util.copyToClipboard = function (textToCopy) {
|
|||
}
|
||||
}
|
||||
|
||||
L.Util.normalize = function (s) {
|
||||
return (s || '')
|
||||
.toLowerCase()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
}
|
||||
|
||||
L.DomUtil.add = (tagName, className, container, content) => {
|
||||
const el = L.DomUtil.create(tagName, className, container)
|
||||
if (content) {
|
||||
|
|
|
@ -557,12 +557,19 @@ L.FormBuilder.IconUrl = L.FormBuilder.BlurInput.extend({
|
|||
L._('Emoji & Character')
|
||||
)
|
||||
url = L.DomUtil.add('button', 'flat tab-url', this.tabsContainer, L._('URL'))
|
||||
L.DomEvent.on(symbol, 'click', L.DomEvent.stop)
|
||||
.on(symbol, 'click', this.showSymbolsTab, this)
|
||||
L.DomEvent.on(char, 'click', L.DomEvent.stop)
|
||||
.on(char, 'click', this.showCharsTab, this)
|
||||
L.DomEvent.on(url, 'click', L.DomEvent.stop)
|
||||
.on(url, 'click', this.showURLTab, this)
|
||||
L.DomEvent.on(symbol, 'click', L.DomEvent.stop).on(
|
||||
symbol,
|
||||
'click',
|
||||
this.showSymbolsTab,
|
||||
this
|
||||
)
|
||||
L.DomEvent.on(char, 'click', L.DomEvent.stop).on(
|
||||
char,
|
||||
'click',
|
||||
this.showCharsTab,
|
||||
this
|
||||
)
|
||||
L.DomEvent.on(url, 'click', L.DomEvent.stop).on(url, 'click', this.showURLTab, this)
|
||||
},
|
||||
|
||||
highlightTab: function (name) {
|
||||
|
@ -589,11 +596,7 @@ L.FormBuilder.IconUrl = L.FormBuilder.BlurInput.extend({
|
|||
const img = L.DomUtil.create(
|
||||
'img',
|
||||
'',
|
||||
L.DomUtil.create(
|
||||
'div',
|
||||
'umap-pictogram-choice',
|
||||
this.buttonsContainer
|
||||
)
|
||||
L.DomUtil.create('div', 'umap-pictogram-choice', this.buttonsContainer)
|
||||
)
|
||||
img.src = this.value()
|
||||
L.DomEvent.on(img, 'click', this.showSymbolsTab, this)
|
||||
|
@ -601,11 +604,7 @@ L.FormBuilder.IconUrl = L.FormBuilder.BlurInput.extend({
|
|||
const el = L.DomUtil.create(
|
||||
'span',
|
||||
'',
|
||||
L.DomUtil.create(
|
||||
'div',
|
||||
'umap-pictogram-choice',
|
||||
this.buttonsContainer
|
||||
)
|
||||
L.DomUtil.create('div', 'umap-pictogram-choice', this.buttonsContainer)
|
||||
)
|
||||
el.textContent = this.value()
|
||||
L.DomEvent.on(el, 'click', this.showSymbolsTab, this)
|
||||
|
@ -623,11 +622,11 @@ L.FormBuilder.IconUrl = L.FormBuilder.BlurInput.extend({
|
|||
addIconPreview: function (pictogram, parent) {
|
||||
const baseClass = 'umap-pictogram-choice',
|
||||
value = pictogram.src,
|
||||
search = this.searchInput.value.toLowerCase(),
|
||||
search = L.Util.normalize(this.searchInput.value),
|
||||
title = pictogram.attribution
|
||||
? `${pictogram.name} — © ${pictogram.attribution}`
|
||||
: pictogram.name
|
||||
if (search && title.toLowerCase().indexOf(search) === -1) return
|
||||
if (search && L.Util.normalize(title).indexOf(search) === -1) return
|
||||
const className = value === this.value() ? `${baseClass} selected` : baseClass,
|
||||
container = L.DomUtil.create('div', className, parent),
|
||||
img = L.DomUtil.create('img', '', container)
|
||||
|
|
|
@ -475,6 +475,16 @@ describe('L.Util', function () {
|
|||
})
|
||||
})
|
||||
|
||||
describe("#normalize()", function () {
|
||||
|
||||
if('should remove accents', function () {
|
||||
// French é
|
||||
assert.equal(L.Util.normalize('aéroport'), 'aeroport')
|
||||
// American é
|
||||
assert.equal(L.Util.normalize('aéroport'), 'aeroport')
|
||||
})
|
||||
})
|
||||
|
||||
describe("#sortFeatures()", function () {
|
||||
let feat1, feat2, feat3
|
||||
before(function () {
|
||||
|
|
Loading…
Reference in a new issue