mirror of https://github.com/ColorlibHQ/AdminLTE
add abilty to highlight name and path
parent
798cf73e45
commit
45d4759ab0
|
@ -38,6 +38,9 @@ const Default = {
|
||||||
arrowSign: '->',
|
arrowSign: '->',
|
||||||
minLength: 3,
|
minLength: 3,
|
||||||
maxResults: 7,
|
maxResults: 7,
|
||||||
|
highlightName: true,
|
||||||
|
highlightPath: false,
|
||||||
|
highlightClass: 'text-light',
|
||||||
notFoundText: 'No element found!'
|
notFoundText: 'No element found!'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,12 +155,37 @@ class SidebarSearch {
|
||||||
}
|
}
|
||||||
|
|
||||||
_renderItem(name, link, path) {
|
_renderItem(name, link, path) {
|
||||||
|
path = path.join(` ${this.options.arrowSign} `)
|
||||||
|
|
||||||
|
if (this.options.highlightName || this.options.highlightPath) {
|
||||||
|
const searchValue = $(SELECTOR_SEARCH_INPUT).val().toLowerCase()
|
||||||
|
const regExp = new RegExp(searchValue, 'gi')
|
||||||
|
|
||||||
|
if (this.options.highlightName) {
|
||||||
|
name = name.replace(
|
||||||
|
regExp,
|
||||||
|
str => {
|
||||||
|
return `<b class="${this.options.highlightClass}">${str}</b>`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.options.highlightPath) {
|
||||||
|
path = path.replace(
|
||||||
|
regExp,
|
||||||
|
str => {
|
||||||
|
return `<b class="${this.options.highlightClass}">${str}</b>`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return `<a href="${link}" class="list-group-item">
|
return `<a href="${link}" class="list-group-item">
|
||||||
<div class="search-title">
|
<div class="search-title">
|
||||||
${name}
|
${name}
|
||||||
</div>
|
</div>
|
||||||
<div class="search-path">
|
<div class="search-path">
|
||||||
${path.join(` ${this.options.arrowSign} `)}
|
${path}
|
||||||
</div>
|
</div>
|
||||||
</a>`
|
</a>`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue