From 7d7c798dea96955d30462c213cf296f7f8070775 Mon Sep 17 00:00:00 2001 From: Chris Hallberg <crhallberg@gmail.com> Date: Tue, 1 Dec 2015 12:37:40 -0500 Subject: [PATCH] autocomplete 0.3 - term highlighting working. --- themes/bootstrap3/js/autocomplete.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/themes/bootstrap3/js/autocomplete.js b/themes/bootstrap3/js/autocomplete.js index 8a5597f8457..ed4737d06d0 100644 --- a/themes/bootstrap3/js/autocomplete.js +++ b/themes/bootstrap3/js/autocomplete.js @@ -1,5 +1,5 @@ /** - * vufind.typeahead.js 0.2 + * vufind.typeahead.js 0.3 * ~ @crhallberg */ (function ( $ ) { @@ -29,14 +29,18 @@ if (typeof data[i] === 'string') { data[i] = {val: data[i]}; } + var content = data[i].val; + if (options.highlight) { + var regex = new RegExp('('+input.val()+')', 'ig'); + content = content.replace(regex, '<b>$1</b>'); + } var item = typeof data[i].href === 'undefined' - ? $('<div/>').attr('data-value', data[i].val) - .html(data[i].val) - .addClass('item') + ? $('<div/>').addClass('item') + .attr('data-value', data[i].val) + .html(content) : $('<a/>').attr('href', data[i].href) - .attr('data-value', data[i].val) - .html(data[i].val) - .addClass('item') + .attr('data-value', data[i].val) + .html(content) if (typeof data[i].description !== 'undefined') { item.append($('<small/>').text(data[i].description)); } -- GitLab