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

Arbitraries Seach and Highlight functions #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rdllopes
Copy link

@rdllopes rdllopes commented May 8, 2012

I'd like to allow arbitraries search and highlight functions. In my specific case, I'm interested in search function that mimic TextMate "Go to File…" action.

Here, an example:

    
<script>
function mateSearch(target, query){
  regexp = query.replace(/(.)/g, "$1.*");
  return target.search(regexp);
}
function highlight(target, query, caseOpt){
  comp = target;
  if (!caseOpt) comp = comp.toLowerCase();
  result = ""
  j = 0
  for (var i=0; i < target.length; i++){
    if (comp[i]==query[j]){
      result += ""+ target[i] + "";
      j++;
    } else {
      result += target[i]
    }
  }
  result = result.replace(/<\/em>/g, "");
  return result;  
}
$("#input_names").autoSuggest(data.items, {selectedItemProp: "name", searchObjProps: "name", searchFunction: mateSearch, highlightFunction: highlight});

@wuyuntao
Copy link
Owner

wuyuntao commented May 9, 2012

Thank you very much for the code contribution. I will run through your code as soon as I get time.

@rdllopes
Copy link
Author

rdllopes commented May 9, 2012

Thank you in advance for your attention.

jerefrer referenced this pull request in jerefrer/jquery-autosuggest Aug 5, 2013
Adds missing informations about the canGenerateNewSelections option
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants