Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit b3f2076
Author: Koen Punt <koen@koenpunt.nl>
Date:   Mon Apr 1 22:36:26 2013 +0200

    Updated setting selected attribute for new options
    Some code tidying

commit 8a459a2
Author: Koen Punt <koen@koenpunt.nl>
Date:   Sun Mar 10 16:37:41 2013 +0100

    added separate examples for option adding

commit 99e746c
Author: Csaba Csoma <csabacsoma@gmail.com>
Date:   Thu Feb 28 22:54:25 2013 -0800

    Fix light blue text on dark blue background when create_option is on

commit 3cc7287
Author: Koen Punt <koen@koenpunt.nl>
Date:   Thu Nov 1 11:33:02 2012 +0100

    Squashed commit of the following:

    commit 7de0007b855c464f9a26425afb85e3fe4daf0df5
    Merge: 10fb211 80f3985
    Author: Koen Punt <koen@koenpunt.nl>
    Date:   Thu Nov 1 11:32:06 2012 +0100

        Merge branch 'gh7_empty_select_should_show_input' into rebase

    commit 10fb2119954a7129e3214985d679f3e957f1bd0a
    Author: Koen Punt <koen@koenpunt.nl>
    Date:   Thu Nov 1 11:30:04 2012 +0100

        Merged koenpunt/master onto harvesthq/master

    commit 80f3985
    Author: Koen Punt <koen@koenpunt.nl>
    Date:   Thu Nov 1 11:02:57 2012 +0100

        fixes #7, select without options will now show input on click

    commit c481fed
    Author: Patrick Filler <pf@patrickfiller.com>
    Date:   Tue Oct 9 14:20:10 2012 -0700

        Make sure single text link gets negative tab index. Fixes issue with tabbing backwards.

    commit 9085750
    Author: Patrick Filler <pf@patrickfiller.com>
    Date:   Tue Oct 9 10:21:04 2012 -0700

        Fixes tab order issues with single Chosen.

commit 5f6ef66
Author: Samnan ur Rehman <samnan.akhoond@gmail.com>
Date:   Sun Oct 14 10:23:29 2012 +0500

    updated coffeescript and package files with new changes

commit 5592c1f
Author: Samnan ur Rehman Akhoond <samnan.akhoond@gmail.com>
Date:   Fri Oct 12 18:20:31 2012 +0600

    Option to disable duplicate option creation, with case insensitive option

    This commit enables a new option create_allow_duplicates, which enables or disables duplicate option creation in the control (to be used with create_option). Also, you can set create_allow_case_insensitive to true or false for additional behavior.

commit 3bc8749
Author: Samnan ur Rehman Akhoond <samnan.akhoond@gmail.com>
Date:   Fri Oct 12 16:21:53 2012 +0600

    Fix issue #11 => https://github.com/koenpunt/chosen/issues

    On mouse click selection of new option creation, callback being called twice

commit 1eab3d0
Author: Koen Punt <koen@koenpunt.nl>
Date:   Mon Aug 27 15:24:49 2012 +0200

    Removed result_add_option from chosen.jquery.coffee
      thanks to: @fson (harvesthq#166 (comment))

commit d93b9ce
Author: Koen Punt <koenpunt@gmail.com>
Date:   Tue Jul 17 10:55:55 2012 +0200

    persistent_create_option was not implemented in prototype version
    removed console.log

commit ca63d79
Author: Koen Punt <koenpunt@gmail.com>
Date:   Fri Jul 13 03:48:47 2012 +0200

    Added option for adding values by keyboard

commit 627b8d5
Author: Koen Punt <koen@koenpunt.nl>
Date:   Mon Dec 19 20:52:04 2011 +0100

    Updated the way for adding items using a custom callback
    removed debug console.log

commit b9f0444
Author: Koen Punt <koen@koenpunt.nl>
Date:   Mon Dec 19 20:31:47 2011 +0100

    Fixed issue with prototype version where option adding did not work.

commit 20fcd17
Author: Ben West <bewest@gmail.com>
Date:   Sat Dec 17 14:36:21 2011 -0800

    add create_option feature to example demo

commit c45529a
Author: Koen Punt <koen@koenpunt.nl>
Date:   Tue Nov 22 15:41:07 2011 +0100

    Add <option /> with selected attribute

    Add <option /> with selected attribute instead of selecting it
    afterwards with JS

commit 245acc8
Author: Koen Punt <koen@koenpunt.nl>
Date:   Mon Aug 8 15:11:15 2011 +0200

    c57d1d6
    hiding select.chzn-select was a bad idea, in general! reverting
    923c3b2
    Do no harm and return as soon as possible for unsupported browsers, name...

commit 08f9fab
Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
Date:   Sat Aug 6 13:02:58 2011 +0800

    Remove duplicate entries for United States and United Kingdom

commit 3edc093
Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
Date:   Mon Aug 8 09:49:01 2011 +0800

    Show add item link even for prefix matches

commit d8eea80
Author: Koen Punt <koen@koenpunt.nl>
Date:   Sun Aug 7 19:52:10 2011 +0200

    Updated callback parameter to object with `value` and `text` property

commit 3e7ce4b
Author: Koen Punt <koen@koenpunt.nl>
Date:   Sun Aug 7 16:50:06 2011 +0200

    Merged with branch kamal/master

commit f7a578d
Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
Date:   Sat Aug 6 12:51:31 2011 +0800

    Regenerate js files for performance fix

commit d7c36be
Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
Date:   Sat Aug 6 12:51:20 2011 +0800

    Ported performance fix to prototype

commit 04ee8be
Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
Date:   Sat Aug 6 12:47:28 2011 +0800

    Performance fix for deciding when to show the "Add this item" link

commit e44837b
Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
Date:   Fri Aug 5 23:05:14 2011 +0800

    Regenerate js files

commit adf4fb7
Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
Date:   Fri Aug 5 22:58:45 2011 +0800

    Ported 'Add Item' link to chosen.proto

commit f84f455
Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
Date:   Fri Aug 5 21:48:39 2011 +0800

    Guard against adding already selected options

commit 41c90e4
Author: Koen Punt <koen@koenpunt.nl>
Date:   Thu Aug 4 16:18:03 2011 +0200

    Updated use of Add options

commit 903e003
Author: Koen Punt <koen@koenpunt.nl>
Date:   Tue Aug 2 16:48:29 2011 +0200

    Added 'Add item link'
  • Loading branch information
koenpunt committed May 10, 2013
1 parent 1205c62 commit cb5cb22
Show file tree
Hide file tree
Showing 10 changed files with 2,986 additions and 35 deletions.
11 changes: 11 additions & 0 deletions chosen/chosen.css
@@ -1,4 +1,5 @@
/* @group Base */

.chzn-container {
font-size: 13px;
position: relative;
Expand Down Expand Up @@ -288,6 +289,13 @@
background-image: linear-gradient(#3875d7 20%, #2a62bc 90%);
color: #fff;
}
.chzn-container .chzn-results a {
color: #444444;
}
.chzn-container .chzn-results .highlighted a {
color: #fff;
text-decoration: none;
}
.chzn-container .chzn-results li em {
background: #feffde;
font-style: normal;
Expand All @@ -299,6 +307,9 @@
background: #f4f4f4;
display: list-item;
}
.chzn-container .chzn-results .create-option {
display: list-item;
}
.chzn-container .chzn-results .group-result {
cursor: default;
color: #999;
Expand Down
68 changes: 61 additions & 7 deletions chosen/chosen.jquery.js
Expand Up @@ -141,7 +141,9 @@ Copyright (c) 2011 by Harvest
this.choices = 0;
this.single_backstroke_delete = this.options.single_backstroke_delete || false;
this.max_selected_options = this.options.max_selected_options || Infinity;
return this.inherit_select_classes = this.options.inherit_select_classes || false;
this.inherit_select_classes = this.options.inherit_select_classes || false;
this.create_option = this.options.create_option || false;
return this.persistent_create_option = this.options.persistent_create_option || false;
};

AbstractChosen.prototype.set_default_text = function() {
Expand All @@ -152,7 +154,8 @@ Copyright (c) 2011 by Harvest
} else {
this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || AbstractChosen.default_single_text;
}
return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || AbstractChosen.default_no_result_text;
this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || AbstractChosen.default_no_result_text;
return this.create_option_text = this.form_field.getAttribute("data-create_option_text") || this.options.create_option_text || "Add option";
};

AbstractChosen.prototype.mouse_enter = function() {
Expand Down Expand Up @@ -209,6 +212,10 @@ Copyright (c) 2011 by Harvest
}
};

AbstractChosen.prototype.append_option = function(option) {
return this.select_append_option(option);
};

AbstractChosen.prototype.results_update_field = function() {
this.set_default_text();
if (!this.is_multiple) {
Expand Down Expand Up @@ -572,10 +579,10 @@ Copyright (c) 2011 by Harvest
this.choices = 0;
} else if (!this.is_multiple) {
this.selected_item.addClass("chzn-default").find("span").text(this.default_text);
if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) {
this.container.addClass("chzn-container-single-nosearch");
} else {
if (this.create_option && !this.disable_search) {
this.container.removeClass("chzn-container-single-nosearch");
} else if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) {
this.container.addClass("chzn-container-single-nosearch");
}
}
content = '';
Expand Down Expand Up @@ -792,6 +799,10 @@ Copyright (c) 2011 by Harvest
var high, high_id, item, position;
if (this.result_highlight) {
high = this.result_highlight;
if (high.hasClass('create-option')) {
this.select_create_option(this.search_field.val());
return this.results_hide();
}
high_id = high.attr("id");
this.result_clear_highlight();
if (this.is_multiple) {
Expand Down Expand Up @@ -863,13 +874,16 @@ Copyright (c) 2011 by Harvest
};

Chosen.prototype.winnow_results = function() {
var found, option, part, parts, regex, regexAnchor, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len1, _ref;
var eregex, exact_result, found, option, part, parts, regex, regexAnchor, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len1, _ref;
this.no_results_clear();
this.create_option_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');
eregex = new RegExp('^' + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") + '$', 'i');
exact_result = false;
_ref = this.results_data;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
option = _ref[_i];
Expand All @@ -883,6 +897,9 @@ Copyright (c) 2011 by Harvest
if (regex.test(option.html)) {
found = true;
results += 1;
if (eregex.test(option.html)) {
exact_result = true;
}
} else if (this.enable_split_word_search && (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0)) {
parts = option.html.replace(/\[|\]/g, "").split(" ");
if (parts.length) {
Expand Down Expand Up @@ -920,6 +937,9 @@ Copyright (c) 2011 by Harvest
if (results < 1 && searchText.length) {
return this.no_results(searchText);
} else {
if (this.create_option && !exact_result && this.persistent_create_option && searchText.length) {
this.show_create_option(searchText);
}
return this.winnow_results_set_highlight();
}
};
Expand Down Expand Up @@ -958,7 +978,41 @@ Copyright (c) 2011 by Harvest
var no_results_html;
no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>');
no_results_html.find("span").first().html(terms);
return this.search_results.append(no_results_html);
this.search_results.append(no_results_html);
if (this.create_option) {
return this.show_create_option(terms);
}
};

Chosen.prototype.show_create_option = function(terms) {
var create_option_html;
create_option_html = $('<li class="create-option active-result"><a href="javascript:void(0);">' + this.create_option_text + '</a>: "' + terms + '"</li>');
return this.search_results.append(create_option_html);
};

Chosen.prototype.create_option_clear = function() {
return this.search_results.find(".create-option").remove();
};

Chosen.prototype.select_create_option = function(terms) {
if ($.isFunction(this.create_option)) {
return this.create_option.call(this, terms);
} else {
return this.select_append_option({
value: terms,
text: terms
});
}
};

Chosen.prototype.select_append_option = function(options) {
var attributes, option;
attributes = $.extend({}, options, {
selected: 1
});
option = $('<option />', attributes);
this.form_field_jq.append(option);
return this.form_field_jq.trigger("liszt:updated");
};

Chosen.prototype.no_results_clear = function() {
Expand Down
2 changes: 1 addition & 1 deletion chosen/chosen.jquery.min.js

Large diffs are not rendered by default.

81 changes: 70 additions & 11 deletions chosen/chosen.proto.js
Expand Up @@ -141,7 +141,9 @@ Copyright (c) 2011 by Harvest
this.choices = 0;
this.single_backstroke_delete = this.options.single_backstroke_delete || false;
this.max_selected_options = this.options.max_selected_options || Infinity;
return this.inherit_select_classes = this.options.inherit_select_classes || false;
this.inherit_select_classes = this.options.inherit_select_classes || false;
this.create_option = this.options.create_option || false;
return this.persistent_create_option = this.options.persistent_create_option || false;
};

AbstractChosen.prototype.set_default_text = function() {
Expand All @@ -152,7 +154,8 @@ Copyright (c) 2011 by Harvest
} else {
this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || AbstractChosen.default_single_text;
}
return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || AbstractChosen.default_no_result_text;
this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || AbstractChosen.default_no_result_text;
return this.create_option_text = this.form_field.getAttribute("data-create_option_text") || this.options.create_option_text || "Add option";
};

AbstractChosen.prototype.mouse_enter = function() {
Expand Down Expand Up @@ -209,6 +212,10 @@ Copyright (c) 2011 by Harvest
}
};

AbstractChosen.prototype.append_option = function(option) {
return this.select_append_option(option);
};

AbstractChosen.prototype.results_update_field = function() {
this.set_default_text();
if (!this.is_multiple) {
Expand Down Expand Up @@ -359,7 +366,9 @@ Copyright (c) 2011 by Harvest
this.multi_temp = new Template('<ul class="chzn-choices"><li class="search-field"><input type="text" value="#{default}" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop"><ul class="chzn-results"></ul></div>');
this.choice_temp = new Template('<li class="search-choice" id="#{id}"><span>#{choice}</span><a href="javascript:void(0)" class="search-choice-close" rel="#{position}"></a></li>');
this.choice_noclose_temp = new Template('<li class="search-choice search-choice-disabled" id="#{id}"><span>#{choice}</span></li>');
return this.no_results_temp = new Template('<li class="no-results">' + this.results_none_found + ' "<span>#{terms}</span>"</li>');
this.no_results_temp = new Template('<li class="no-results">' + this.results_none_found + ' "<span>#{terms}</span>"</li>');
this.new_option_temp = new Template('<option value="#{value}" selected="selected">#{text}</option>');
return this.create_option_temp = new Template('<li class="create-option active-result"><a href="javascript:void(0);">#{text}</a>: "#{terms}"</li>');
};

Chosen.prototype.set_up_html = function() {
Expand Down Expand Up @@ -565,10 +574,10 @@ Copyright (c) 2011 by Harvest
this.choices = 0;
} else if (!this.is_multiple) {
this.selected_item.addClassName("chzn-default").down("span").update(this.default_text);
if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) {
this.container.addClassName("chzn-container-single-nosearch");
} else {
if (this.create_option && !this.disable_search) {
this.container.removeClassName("chzn-container-single-nosearch");
} else if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) {
this.container.addClassName("chzn-container-single-nosearch");
}
}
content = '';
Expand Down Expand Up @@ -792,6 +801,10 @@ Copyright (c) 2011 by Harvest
var high, item, position;
if (this.result_highlight) {
high = this.result_highlight;
if (high.hasClassName('create-option')) {
this.select_create_option(this.search_field.value);
return this.results_hide();
}
this.result_clear_highlight();
if (this.is_multiple) {
this.result_deactivate(high);
Expand Down Expand Up @@ -862,13 +875,16 @@ Copyright (c) 2011 by Harvest
};

Chosen.prototype.winnow_results = function() {
var found, option, part, parts, regex, regexAnchor, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len1, _ref;
var eregex, exact_result, found, option, part, parts, regex, regexAnchor, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len1, _ref;
this.no_results_clear();
this.create_option_clear();
results = 0;
searchText = this.search_field.value === this.default_text ? "" : this.search_field.value.strip().escapeHTML();
regexAnchor = this.search_contains ? "" : "^";
regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
eregex = new RegExp('^' + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") + '$', 'i');
exact_result = false;
_ref = this.results_data;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
option = _ref[_i];
Expand All @@ -878,9 +894,13 @@ Copyright (c) 2011 by Harvest
} else if (!(this.is_multiple && option.selected)) {
found = false;
result_id = option.dom_id;
result = $(option.dom_id);
if (regex.test(option.html)) {
found = true;
results += 1;
if (eregex.test(option.html)) {
exact_result = true;
}
} else if (this.enable_split_word_search && (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0)) {
parts = option.html.replace(/\[|\]/g, "").split(" ");
if (parts.length) {
Expand All @@ -901,10 +921,10 @@ Copyright (c) 2011 by Harvest
} else {
text = option.html;
}
if ($(result_id).innerHTML !== text) {
$(result_id).update(text);
if (result.innerHTML !== text) {
result.update(text);
}
this.result_activate($(result_id));
this.result_activate(result);
if (option.group_array_index != null) {
$(this.results_data[option.group_array_index].dom_id).setStyle({
display: 'list-item'
Expand All @@ -922,6 +942,9 @@ Copyright (c) 2011 by Harvest
if (results < 1 && searchText.length) {
return this.no_results(searchText);
} else {
if (this.create_option && !exact_result && this.persistent_create_option && searchText.length) {
this.show_create_option(searchText);
}
return this.winnow_results_set_highlight();
}
};
Expand Down Expand Up @@ -960,9 +983,45 @@ Copyright (c) 2011 by Harvest
};

Chosen.prototype.no_results = function(terms) {
return this.search_results.insert(this.no_results_temp.evaluate({
this.search_results.insert(this.no_results_temp.evaluate({
terms: terms
}));
if (this.create_option) {
return this.show_create_option(terms);
}
};

Chosen.prototype.show_create_option = function(terms) {
return this.search_results.insert(this.create_option_temp.evaluate({
text: this.create_option_text,
terms: terms
}));
};

Chosen.prototype.create_option_clear = function() {
var create_option;
create_option = this.search_results.select(".create-option");
return create_option.each(function(el) {
return el.remove();
});
};

Chosen.prototype.select_create_option = function(terms) {
if (Object.isFunction(this.create_option)) {
return this.create_option.call(this, terms);
} else {
return this.select_append_option({
value: terms,
text: terms
});
}
};

Chosen.prototype.select_append_option = function(options) {
var option;
option = this.new_option_temp.evaluate(options);
this.form_field.insert(option);
return Event.fire(this.form_field, "liszt:updated");
};

Chosen.prototype.no_results_clear = function() {
Expand Down
2 changes: 1 addition & 1 deletion chosen/chosen.proto.min.js

Large diffs are not rendered by default.

0 comments on commit cb5cb22

Please sign in to comment.