From 45d4759ab0aa104e63743395bfdedcdd909b0e22 Mon Sep 17 00:00:00 2001 From: REJack Date: Sat, 27 Jun 2020 18:58:12 +0200 Subject: [PATCH] add abilty to highlight name and path --- build/js/SidebarSearch.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/build/js/SidebarSearch.js b/build/js/SidebarSearch.js index 0eacbba95..092c631d8 100644 --- a/build/js/SidebarSearch.js +++ b/build/js/SidebarSearch.js @@ -38,6 +38,9 @@ const Default = { arrowSign: '->', minLength: 3, maxResults: 7, + highlightName: true, + highlightPath: false, + highlightClass: 'text-light', notFoundText: 'No element found!' } @@ -152,12 +155,37 @@ class SidebarSearch { } _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 `${str}` + } + ) + } + + if (this.options.highlightPath) { + path = path.replace( + regExp, + str => { + return `${str}` + } + ) + } + } + return `
${name}
- ${path.join(` ${this.options.arrowSign} `)} + ${path}
` }