private void resultsBuild() { selectItems = new SelectParser().parse(selectElement); if (isMultiple && choices > 0) { searchChoices.find("li." + css.searchChoice()).remove(); choices = 0; } else if (!isMultiple) { selectedItem.addClass(css.chznDefault()).find("span").text(defaultText); if (selectElement.getOptions().getLength() <= options.getDisableSearchThreshold()) { container.addClass(css.chznContainerSingleNoSearch()); } else { container.removeClass(css.chznContainerSingleNoSearch()); } } SafeHtmlBuilder content = new SafeHtmlBuilder(); for (int i = 0; i < selectItems.length(); i++) { SelectItem item = selectItems.get(i); if (item.isGroup()) { SafeHtml result = resultAddGroup((GroupItem) item); if (result != null) { content.append(result); } } else { OptionItem optionItem = (OptionItem) item; if (optionItem.isEmpty()) { continue; } SafeHtml optionHtml = resultAddOption(optionItem); if (optionHtml != null) { content.append(optionHtml); } if (optionItem.isSelected() && isMultiple) { choiceBuild(optionItem); } else if (optionItem.isSelected() && !isMultiple) { selectedItem.removeClass(css.chznDefault()).find("span").text(optionItem.getText()); if (allowSingleDeselect) { singleDeselectControlBuild(); } } } } searchFieldDisabled(); showSearchFieldDefault(); searchFieldScale(); searchResults.html(content.toSafeHtml().asString()); }
private void winnowResults() { noResultClear(); int results = 0; String searchText = defaultText.equals(searchField.val()) ? "" : searchField.val().trim(); searchText = SafeHtmlUtils.htmlEscape(searchText); String regexAnchor = options.isSearchContains() ? "" : "^"; // escape reg exp special chars String escapedSearchText = regExpChars.replace(searchText, "\\$&"); String test2 = "test"; test2.substring(1); RegExp regex = RegExp.compile(regexAnchor + escapedSearchText, "i"); RegExp zregex = RegExp.compile("(" + escapedSearchText + ")", "i"); for (int i = 0; i < selectItems.length(); i++) { SelectItem item = selectItems.get(i); if (item.isDisabled() || item.isEmpty()) { continue; } if (item.isGroup()) { $('#' + item.getDomId()).css("display", "none"); } else { OptionItem option = (OptionItem) item; if (!(isMultiple && option.isSelected())) { boolean found = false; String resultId = option.getDomId(); GQuery result = $("#" + resultId); String optionContent = option.getHtml(); if (regex.test(optionContent)) { found = true; results++; } else if (optionContent.indexOf(" ") >= 0 || optionContent.indexOf("[") == 0) { String[] parts = optionContent.replaceAll("\\[|\\]", "").split(" "); for (String part : parts) { if (regex.test(part)) { found = true; results++; } } } if (found) { String text; if (searchText.length() > 0) { text = zregex.replace(optionContent, "<em>$1</em>"); } else { text = optionContent; } result.html(text); resultActivate(result); if (option.getGroupArrayIndex() != -1) { $("#" + selectItems.get(option.getGroupArrayIndex()).getDomId()) .css("display", "list-item"); } } else { if (resultHighlight != null && resultId.equals(resultHighlight.attr("id"))) { resultClearHighlight(); } resultDeactivate(result); } } } } if (results < 1 && searchText.length() > 0) { noResults(searchText); } else { winnowResultsSetHighlight(); } }