Skip to content

Commit e0bad36

Browse files
committed
highlight now works for German Umlauts too
option to show html if no suggests are available
1 parent 2cbcede commit e0bad36

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "unibox",
3-
"version": "1.14.2",
3+
"version": "1.14.3",
44
"main": [
55
"js/unibox.min.js",
66
"css/unibox.min.css"

html/sampleSite.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,12 @@
9292
highlight: true, // whether matched words should be highlighted, default: true
9393
queryVisualizationHeadline: '', // A headline for the image visualization, default: empty
9494
animationSpeed: 200, // speed of the animations, default: 300ms
95-
enterCallback: undefined, // callback on what should happen when enter is pressed, default: undefined, meaning the link will be followed
95+
enterCallback: function(text,link){console.log(text);}, // callback on what should happen when enter is pressed, default: undefined, meaning the link will be followed
9696
placeholder: 'Search for something',
97-
minChars: 3 // minimum number of characters before the suggests shows, default: 3
97+
minChars: 3, // minimum number of characters before the suggests shows, default: 3
98+
suggestOrder: [], // the order of the suggests
99+
suggestSelectionOrder: [], // the order of how they should be selected
100+
noSuggests: '<b>We haven\'t found anything for you, <u>sooorrryyy</u></b>',
98101
//maxWidth: 400 // the maximum width of the suggest box, default: as wide as the input box
99102
};
100103

js/unibox.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ var UniBox = function () {
9090
// the maximum width of the suggest box, default: as wide as the input box
9191
var maxWidth = undefined;
9292

93+
// the content to show when no suggests are available, if undefined, no suggests will be shown
94+
var noSuggests = undefined;
95+
9396
var entityMap = {
9497
"&": "&amp;",
9598
"<": "&lt;",
@@ -147,7 +150,7 @@ var UniBox = function () {
147150
if (!highlight) {
148151
return string;
149152
}
150-
var words = searchString.replace(/[^a-zA-Z0-9äöüÄÖÜß]|\s+|\r?\n|\r/gmi, " ").replace(/\W+/g, " ").split(' ');
153+
var words = searchString.replace(/[^a-zA-Z0-9äöüÄÖÜß]|\s+|\r?\n|\r/gmi, " ").replace(/[^a-zA-Z0-9äöüÄÖÜß]/g, " ").split(' ');
151154

152155
// sort words by length, longest first
153156
words.sort(function(a, b){
@@ -160,6 +163,7 @@ var UniBox = function () {
160163
return;
161164
}
162165
var matches = string.match(new RegExp("((" + word + ")(?!#<##|-\\d+#<##))(?!.*\\1)", 'gi'));
166+
163167
if (matches != null) {
164168
for (var i = 0; i < matches.length; i++) {
165169
var match = matches[i];
@@ -387,6 +391,11 @@ var UniBox = function () {
387391
//suggestBox.css('left', getSearchBoxOffset().left);
388392
//suggestBox.css('top', getSearchBoxOffset().top);
389393

394+
if (noSuggests != undefined) {
395+
showSuggestBox = true;
396+
suggestBox.append(noSuggests);
397+
}
398+
390399
//// show it
391400
if (showSuggestBox) {
392401
// if already visible, just update position and set class
@@ -626,6 +635,7 @@ var UniBox = function () {
626635
suggestOrder = options.suggestOrder;
627636
suggestSelectionOrder = options.suggestSelectionOrder;
628637
maxWidth = options.maxWidth;
638+
noSuggests = options.noSuggests;
629639

630640
// insert necessary values for inputfield
631641
searchBox.attr("autocomplete", "off");
@@ -790,6 +800,7 @@ var UniBox = function () {
790800
blurCallback: undefined,
791801
placeholder: undefined,
792802
extraHtml: undefined,
803+
noSuggests: undefined,
793804
minChars: 3,
794805
maxWidth: searchBox.outerWidth(),
795806
showDeleteAllButton: false,

0 commit comments

Comments
 (0)