A fairly down-to-earth, quick solution can be applied as follows.
Please note
This solution requires/assumes:
- Chosen Version 1.1.0
- A
data-keywords
attribute for eachoption
tag - Keywords separated by a comma within the
data-keywords
attribute
Ok, so let's get to it.
Open your jquery.chosen.js file.
(You will not be able to use the minified version).
1. Assure storage of data attribute in local options
Location => add_option()
Full Definition
SelectParser.prototype.add_option = function(option, group_position, group_disabled) {}
Edit
Look for this.parsed.push()
and at the bottom of the definition, just below style
, add this code:
keywords: ($(option).data().keywords!==undefined
? $(option).data().keywords.split(',')
: false)
2. Make sure the keywords are parsed by the search function
Location => winnow_results()
Full Definition
AbstractChosen.prototype.winnow_results = function() {}
Edit
2.1 Add a new variable keywordMatch
to top declaration:
var escapedSearchText, option, regex, regexAnchor, results, results_group, searchText, startpos, text, zregex, _i, _len, _ref;
Becomes:
var escapedSearchText, option, regex, regexAnchor, results, results_group, searchText, startpos, text, zregex, _i, _len, _ref, keywordMatch;
2.2 Find this condition: if (!(option.group && !this.group_search)){}
and after the second line (where option.search_match
is set), add this code:
keywordMatch=(option.keywords && option.keywords.indexOf(searchText) > -1);
if(keywordMatch)
option.search_match=true;
2.3 Find this assignment:
option.search_text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
And replace it with this code:
option.search_text = keywordMatch ? text : (text.substr(0, startpos) + '<em>' + text.substr(startpos));
These modifications come in the form of a quick implementation. If you need more options (for instance that the keywords are not case-sensitive), you need to implement these parts yourself.
Let me know if there are problems or if i forgot anything.