Advertisement
Guest User

Chosen winnow 2

a guest
Nov 12th, 2012
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         Chosen.prototype.winnow_results = function() {
  2.             var found, option, part, parts, regex, regexAnchor, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len2, _ref;
  3.             this.no_results_clear();
  4.             results = 0;
  5.             searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html();
  6.             regexAnchor = this.search_contains ? "" : "^";
  7.             regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
  8.             zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
  9.             _ref = this.results_data;
  10.             for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  11.                 option = _ref[_i];
  12.                 if (!option.empty) {
  13.                     if (option.group) {
  14.                         $('#' + option.dom_id).css('display', 'none');
  15.                     } else if (!(this.is_multiple && option.selected)) {
  16.                         found = false;
  17.                         result_id = option.dom_id;
  18.                         result = $("#" + result_id);
  19.                         if (regex.test(option.html)) {
  20.                             found = true;
  21.                             results += 1;
  22.                         } else if (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0) {
  23.                             parts = option.html.replace(/\[|\]/g, "").split(" ");
  24.                             if (parts.length) {
  25.                                 for (_j = 0, _len2 = parts.length; _j < _len2; _j++) {
  26.                                     part = parts[_j];
  27.                                     if (regex.test(part)) {
  28.                                         found = true;
  29.                                         results += 1;
  30.                                     }
  31.                                 }
  32.                             }
  33.                         }
  34.                         if (found) {
  35.                             if (searchText.length) {
  36.                                 startpos = option.html.search(zregex);
  37.                                 text = option.html.substr(0, startpos + searchText.length) + '</em>' + option.html.substr(startpos + searchText.length);
  38.                                 text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
  39.                             } else {
  40.                                 text = option.html;
  41.                             }
  42.                             result.html(text);
  43.                             this.result_activate(result);
  44.                             if (option.group_array_index != null) {
  45.                                 $("#" + this.results_data[option.group_array_index].dom_id).css('display', 'list-item');
  46.                             }
  47.                         } else {
  48.                             if (this.result_highlight && result_id === this.result_highlight.attr('id')) {
  49.                                 this.result_clear_highlight();
  50.                             }
  51.                             this.result_deactivate(result);
  52.                         }
  53.                     }
  54.                 }
  55.             }
  56.             if (results < 1 && searchText.length) {
  57.                 return this.no_results(searchText);
  58.             } else {
  59.                 return this.winnow_results_set_highlight();
  60.             }
  61.         };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement