Permalink
Browse files

Regenerate js files

  • Loading branch information...
1 parent e4974f6 commit b3ae3f50f094743c91058f8e6fcff53a6f48ffed @kamal kamal committed Aug 5, 2011
Showing with 75 additions and 9 deletions.
  1. +40 −4 chosen/chosen.jquery.js
  2. +1 −1 chosen/chosen.jquery.min.js
  3. +33 −3 chosen/chosen.proto.js
  4. +1 −1 chosen/chosen.proto.min.js
@@ -11,7 +11,8 @@
/*
Chosen source: generate output using 'cake build'
Copyright (c) 2011 by Harvest
- */ var $, Chosen, get_side_border_padding, root;
+ */
+ var $, Chosen, get_side_border_padding, root;
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
root = this;
$ = jQuery;
@@ -25,7 +26,8 @@
}
});
Chosen = (function() {
- function Chosen(elmn) {
+ function Chosen(elmn, data, options) {
+ this.options = $.extend({}, options);
this.set_default_values();
this.form_field = elmn;
this.form_field_jq = $(this.form_field);
@@ -540,11 +542,45 @@
}
};
Chosen.prototype.no_results = function(terms) {
- var no_results_html;
- no_results_html = $('<li class="no-results">No results match "<span></span>"</li>');
+ var no_results_html, option, regex, selected;
+ no_results_html = $('<li class="no-results">No results match "<span></span>".</li>');
no_results_html.find("span").first().html(terms);
+ regex = new RegExp('^' + terms + '$', 'i');
+ selected = (function() {
+ var _i, _len, _ref, _results;
+ _ref = this.results_data;
+ _results = [];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ option = _ref[_i];
+ if (regex.test(option.value) && option.selected) {
+ _results.push(option);
+ }
+ }
+ return _results;
+ }).call(this);
+ if (selected.length === 0) {
+ no_results_html.append(' <a href="javascript:void(0);" class="option-add">Add this item</a>');
+ no_results_html.find("a.option-add").bind("click", __bind(function(evt) {
+ return this.select_add_option(terms);
+ }, this));
+ }
return this.search_results.append(no_results_html);
};
+ Chosen.prototype.select_add_option = function(terms) {
+ var new_option_html;
+ if ($.isFunction(this.options.addOption)) {
+ this.options.addOption(terms);
+ } else {
+ new_option_html = $('<option />', {
+ value: terms
+ }).text(terms);
+ this.form_field_jq.append(new_option_html);
+ this.form_field_jq.trigger("liszt:updated");
+ }
+ this.search_field.val(terms);
+ this.search_field.trigger("keyup");
+ return this.result_select();
+ };
Chosen.prototype.no_results_clear = function() {
return this.search_results.find(".no-results").remove();
};
Oops, something went wrong.

0 comments on commit b3ae3f5

Please sign in to comment.