Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Chosen.prototype.winnow_results = function() {
- var found, option, part, parts, regex, regexAnchor, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len2, _ref;
- this.no_results_clear();
- results = 0;
- searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html();
- regexAnchor = this.search_contains ? "" : "^";
- regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
- zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
- _ref = this.results_data;
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- option = _ref[_i];
- if (!option.empty) {
- if (option.group) {
- $('#' + option.dom_id).css('display', 'none');
- } else if (!(this.is_multiple && option.selected)) {
- found = false;
- result_id = option.dom_id;
- result = $("#" + result_id);
- if (regex.test(option.html)) {
- found = true;
- results += 1;
- } else if (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0) {
- parts = option.html.replace(/\[|\]/g, "").split(" ");
- if (parts.length) {
- for (_j = 0, _len2 = parts.length; _j < _len2; _j++) {
- part = parts[_j];
- if (regex.test(part)) {
- found = true;
- results += 1;
- }
- }
- }
- }
- if (found) {
- if (searchText.length) {
- startpos = option.html.search(zregex);
- text = option.html.substr(0, startpos + searchText.length) + '</em>' + option.html.substr(startpos + searchText.length);
- text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
- } else {
- text = option.html;
- }
- result.html(text);
- this.result_activate(result);
- if (option.group_array_index != null) {
- $("#" + this.results_data[option.group_array_index].dom_id).css('display', 'list-item');
- }
- } else {
- if (this.result_highlight && result_id === this.result_highlight.attr('id')) {
- this.result_clear_highlight();
- }
- this.result_deactivate(result);
- }
- }
- }
- }
- if (results < 1 && searchText.length) {
- return this.no_results(searchText);
- } else {
- return this.winnow_results_set_highlight();
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement