Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include a "force=true" attribute to data so "forced" options allways appear on results #369

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -361,4 +369,3 @@ var EasyAutocomplete = (function(scope){
return scope;

})(EasyAutocomplete || {});

13 changes: 11 additions & 2 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,17 @@ var EasyAutocomplete = (function(scope) {
$listContainer.append("<div class='eac-category' >" + listBuilders[builderIndex].header + "</div>");
}

for(var i = 0, listDataLength = listData.length; i < listDataLength && counter < listBuilders[builderIndex].maxListSize; i += 1) {
$item = $("<li><div class='eac-item'></div></li>");
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 = $("<li class='eac-item-forced'><div class='eac-item'></div></li>");
}
else {
$item = $("<li><div class='eac-item'></div></li>");
}

(function() {
var j = i,
Expand Down Expand Up @@ -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]));
})();

Expand Down
24 changes: 13 additions & 11 deletions src/proccessData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -92,4 +95,3 @@ var EasyAutocomplete = (function(scope) {


})(EasyAutocomplete || {});