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) => {
|
L.DomUtil.add = (tagName, className, container, content) => {
|
||||||
const el = L.DomUtil.create(tagName, className, container)
|
const el = L.DomUtil.create(tagName, className, container)
|
||||||
if (content) {
|
if (content) {
|
||||||
|
|
|
@ -557,12 +557,19 @@ L.FormBuilder.IconUrl = L.FormBuilder.BlurInput.extend({
|
||||||
L._('Emoji & Character')
|
L._('Emoji & Character')
|
||||||
)
|
)
|
||||||
url = L.DomUtil.add('button', 'flat tab-url', this.tabsContainer, L._('URL'))
|
url = L.DomUtil.add('button', 'flat tab-url', this.tabsContainer, L._('URL'))
|
||||||
L.DomEvent.on(symbol, 'click', L.DomEvent.stop)
|
L.DomEvent.on(symbol, 'click', L.DomEvent.stop).on(
|
||||||
.on(symbol, 'click', this.showSymbolsTab, this)
|
symbol,
|
||||||
L.DomEvent.on(char, 'click', L.DomEvent.stop)
|
'click',
|
||||||
.on(char, 'click', this.showCharsTab, this)
|
this.showSymbolsTab,
|
||||||
L.DomEvent.on(url, 'click', L.DomEvent.stop)
|
this
|
||||||
.on(url, 'click', this.showURLTab, 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) {
|
highlightTab: function (name) {
|
||||||
|
@ -589,11 +596,7 @@ L.FormBuilder.IconUrl = L.FormBuilder.BlurInput.extend({
|
||||||
const img = L.DomUtil.create(
|
const img = L.DomUtil.create(
|
||||||
'img',
|
'img',
|
||||||
'',
|
'',
|
||||||
L.DomUtil.create(
|
L.DomUtil.create('div', 'umap-pictogram-choice', this.buttonsContainer)
|
||||||
'div',
|
|
||||||
'umap-pictogram-choice',
|
|
||||||
this.buttonsContainer
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
img.src = this.value()
|
img.src = this.value()
|
||||||
L.DomEvent.on(img, 'click', this.showSymbolsTab, this)
|
L.DomEvent.on(img, 'click', this.showSymbolsTab, this)
|
||||||
|
@ -601,11 +604,7 @@ L.FormBuilder.IconUrl = L.FormBuilder.BlurInput.extend({
|
||||||
const el = L.DomUtil.create(
|
const el = L.DomUtil.create(
|
||||||
'span',
|
'span',
|
||||||
'',
|
'',
|
||||||
L.DomUtil.create(
|
L.DomUtil.create('div', 'umap-pictogram-choice', this.buttonsContainer)
|
||||||
'div',
|
|
||||||
'umap-pictogram-choice',
|
|
||||||
this.buttonsContainer
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
el.textContent = this.value()
|
el.textContent = this.value()
|
||||||
L.DomEvent.on(el, 'click', this.showSymbolsTab, this)
|
L.DomEvent.on(el, 'click', this.showSymbolsTab, this)
|
||||||
|
@ -623,11 +622,11 @@ L.FormBuilder.IconUrl = L.FormBuilder.BlurInput.extend({
|
||||||
addIconPreview: function (pictogram, parent) {
|
addIconPreview: function (pictogram, parent) {
|
||||||
const baseClass = 'umap-pictogram-choice',
|
const baseClass = 'umap-pictogram-choice',
|
||||||
value = pictogram.src,
|
value = pictogram.src,
|
||||||
search = this.searchInput.value.toLowerCase(),
|
search = L.Util.normalize(this.searchInput.value),
|
||||||
title = pictogram.attribution
|
title = pictogram.attribution
|
||||||
? `${pictogram.name} — © ${pictogram.attribution}`
|
? `${pictogram.name} — © ${pictogram.attribution}`
|
||||||
: pictogram.name
|
: 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,
|
const className = value === this.value() ? `${baseClass} selected` : baseClass,
|
||||||
container = L.DomUtil.create('div', className, parent),
|
container = L.DomUtil.create('div', className, parent),
|
||||||
img = L.DomUtil.create('img', '', container)
|
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 () {
|
describe("#sortFeatures()", function () {
|
||||||
let feat1, feat2, feat3
|
let feat1, feat2, feat3
|
||||||
before(function () {
|
before(function () {
|
||||||
|
|
Loading…
Reference in a new issue