Skip to content

Commit

Permalink
Set search_contains option in Abstrac-chosen.
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Filler committed Mar 12, 2012
1 parent 0483c93 commit ad88217
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 8 deletions.
6 changes: 4 additions & 2 deletions chosen/chosen.jquery.js
Expand Up @@ -129,6 +129,7 @@ Copyright (c) 2011 by Harvest
this.result_single_selected = null;
this.allow_single_deselect = (this.options.allow_single_deselect != null) && (this.form_field.options[0] != null) && this.form_field.options[0].text === "" ? this.options.allow_single_deselect : false;
this.disable_search_threshold = this.options.disable_search_threshold || 0;
this.search_contains = this.options.search_contains || false;
this.choices = 0;
return this.results_none_found = this.options.no_results_text || "No results match";
};
Expand Down Expand Up @@ -727,11 +728,12 @@ Copyright (c) 2011 by Harvest
};

Chosen.prototype.winnow_results = function() {
var found, option, part, parts, regex, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len2, _ref;
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();
regex = new RegExp('^' + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
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++) {
Expand Down
2 changes: 1 addition & 1 deletion chosen/chosen.jquery.min.js

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions chosen/chosen.proto.js
Expand Up @@ -129,6 +129,7 @@ Copyright (c) 2011 by Harvest
this.result_single_selected = null;
this.allow_single_deselect = (this.options.allow_single_deselect != null) && (this.form_field.options[0] != null) && this.form_field.options[0].text === "" ? this.options.allow_single_deselect : false;
this.disable_search_threshold = this.options.disable_search_threshold || 0;
this.search_contains = this.options.search_contains || false;
this.choices = 0;
return this.results_none_found = this.options.no_results_text || "No results match";
};
Expand Down Expand Up @@ -728,11 +729,12 @@ Copyright (c) 2011 by Harvest
};

Chosen.prototype.winnow_results = function() {
var found, option, part, parts, regex, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len2, _ref;
var found, option, part, parts, regex, regexAnchor, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len2, _ref;
this.no_results_clear();
results = 0;
searchText = this.search_field.value === this.default_text ? "" : this.search_field.value.strip().escapeHTML();
regex = new RegExp('^' + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
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++) {
Expand Down
2 changes: 1 addition & 1 deletion chosen/chosen.proto.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion coffee/chosen.jquery.coffee
Expand Up @@ -385,7 +385,7 @@ class Chosen extends AbstractChosen
results = 0

searchText = if @search_field.val() is @default_text then "" else $('<div/>').text($.trim(@search_field.val())).html()
regexAnchor = if @options.search_contains then "" else "^"
regexAnchor = if @search_contains then "" else "^"
regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')
zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')

Expand Down
2 changes: 1 addition & 1 deletion coffee/chosen.proto.coffee
Expand Up @@ -376,7 +376,7 @@ class Chosen extends AbstractChosen
results = 0

searchText = if @search_field.value is @default_text then "" else @search_field.value.strip().escapeHTML()
regexAnchor = if @options.search_contains then "" else "^"
regexAnchor = if @search_contains then "" else "^"
regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')
zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')

Expand Down
1 change: 1 addition & 0 deletions coffee/lib/abstract-chosen.coffee
Expand Up @@ -29,6 +29,7 @@ class AbstractChosen
@result_single_selected = null
@allow_single_deselect = if @options.allow_single_deselect? and @form_field.options[0]? and @form_field.options[0].text is "" then @options.allow_single_deselect else false
@disable_search_threshold = @options.disable_search_threshold || 0
@search_contains = @options.search_contains || false
@choices = 0
@results_none_found = @options.no_results_text or "No results match"

Expand Down

0 comments on commit ad88217

Please sign in to comment.