diff --git a/src/configuration.js b/src/configuration.js index aa734d2..ef45b64 100644 --- a/src/configuration.js +++ b/src/configuration.js @@ -30,7 +30,15 @@ var EasyAutocomplete = (function(scope){ list: { sort: { enabled: false, - method: function(a, b) { + method: function (a, b) { + + fa = a.force; + fb = b.force; + + // if one of them is forced, promote the other (real matches go first) + if (fa && !fb) return 1; + if (fb && !fa) return -1; + a = defaults.getValue(a); b = defaults.getValue(b); @@ -361,4 +369,3 @@ var EasyAutocomplete = (function(scope){ return scope; })(EasyAutocomplete || {}); - diff --git a/src/core.js b/src/core.js index 4203dfa..a6d344b 100644 --- a/src/core.js +++ b/src/core.js @@ -268,9 +268,17 @@ var EasyAutocomplete = (function(scope) { $listContainer.append("
" + listBuilders[builderIndex].header + "
"); } - for(var i = 0, listDataLength = listData.length; i < listDataLength && counter < listBuilders[builderIndex].maxListSize; i += 1) { - $item = $("
  • "); + for (var i = 0, listDataLength = listData.length; i < listDataLength && counter < listBuilders[builderIndex].maxListSize; i += 1) { + + // adding a css class to li to let the front-end show it differently + // example: .eac-item-forced .eac-item { color: #888; } + if ((listData[i].force != undefined) && (listData[i].force == true)) { + $item = $("
  • "); + } + else { + $item = $("
  • "); + } (function() { var j = i, @@ -298,6 +306,7 @@ var EasyAutocomplete = (function(scope) { .mouseout(function() { config.get("list").onMouseOutEvent(); }) + .attr("title", elementsValue) .html(template.build(highlight(elementsValue, phrase), listData[j])); })(); diff --git a/src/proccessData.js b/src/proccessData.js index b227fc5..12d9add 100644 --- a/src/proccessData.js +++ b/src/proccessData.js @@ -24,20 +24,23 @@ var EasyAutocomplete = (function(scope) { function findMatch(list, phrase) { - var preparedList = [], - value = ""; + var preparedList = [], + value = "", + force = false; if (config.get("list").match.enabled) { - for(var i = 0, length = list.length; i < length; i += 1) { + for (var i = 0, length = list.length; i < length; i += 1) { - value = config.get("getValue")(list[i]); - - if (match(value, phrase)) { - preparedList.push(list[i]); - } - - } + value = config.get("getValue")(list[i]); + force = list[i].force; + + if (match(value, phrase)) { + preparedList.push(list[i]); + } else if ((force != undefined) && (force == true)) { + preparedList.push(list[i]); + } + } } else { preparedList = list; @@ -92,4 +95,3 @@ var EasyAutocomplete = (function(scope) { })(EasyAutocomplete || {}); -