remove unused data constructor variable, make use of options

js_style_fix
Tim Chen 2011-08-02 15:16:14 -05:00
parent 0812bc3d64
commit 90ca300921
5 changed files with 21 additions and 17 deletions

View File

@ -11,22 +11,23 @@
/* /*
Chosen source: generate output using 'cake build' Chosen source: generate output using 'cake build'
Copyright (c) 2011 by Harvest 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); }; }; var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
root = this; root = this;
$ = jQuery; $ = jQuery;
$.fn.extend({ $.fn.extend({
chosen: function(data, options) { chosen: function(options) {
return $(this).each(function(input_field) { return $(this).each(function(input_field) {
if (!($(this)).hasClass("chzn-done")) { if (!($(this)).hasClass("chzn-done")) {
return new Chosen(this, data, options); return new Chosen(this, options);
} }
}); });
} }
}); });
Chosen = (function() { Chosen = (function() {
function Chosen(elmn) { function Chosen(elmn, options) {
this.set_default_values(); this.set_default_values(options);
this.form_field = elmn; this.form_field = elmn;
this.form_field_jq = $(this.form_field); this.form_field_jq = $(this.form_field);
this.is_multiple = this.form_field.multiple; this.is_multiple = this.form_field.multiple;
@ -36,7 +37,7 @@
this.register_observers(); this.register_observers();
this.form_field_jq.addClass("chzn-done"); this.form_field_jq.addClass("chzn-done");
} }
Chosen.prototype.set_default_values = function() { Chosen.prototype.set_default_values = function(options) {
this.click_test_action = __bind(function(evt) { this.click_test_action = __bind(function(evt) {
return this.test_active_click(evt); return this.test_active_click(evt);
}, this); }, this);
@ -45,7 +46,8 @@
this.results_showing = false; this.results_showing = false;
this.result_highlighted = null; this.result_highlighted = null;
this.result_single_selected = null; this.result_single_selected = null;
return this.choices = 0; this.choices = 0;
return this.results_none_found = options.no_results_text || "No results match";
}; };
Chosen.prototype.set_up_html = function() { Chosen.prototype.set_up_html = function() {
var container_div, dd_top, dd_width, sf_width; var container_div, dd_top, dd_width, sf_width;
@ -541,7 +543,7 @@
}; };
Chosen.prototype.no_results = function(terms) { Chosen.prototype.no_results = function(terms) {
var no_results_html; var no_results_html;
no_results_html = $('<li class="no-results">No results match "<span></span>"</li>'); no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>');
no_results_html.find("span").first().html(terms); no_results_html.find("span").first().html(terms);
return this.search_results.append(no_results_html); return this.search_results.append(no_results_html);
}; };

File diff suppressed because one or more lines are too long

View File

@ -11,7 +11,8 @@
/* /*
Chosen source: generate output using 'cake build' Chosen source: generate output using 'cake build'
Copyright (c) 2011 by Harvest 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); }; }; var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
root = this; root = this;
Chosen = (function() { Chosen = (function() {

View File

@ -6,16 +6,16 @@ root = this
$ = jQuery $ = jQuery
$.fn.extend({ $.fn.extend({
chosen: (data, options) -> chosen: (options) ->
$(this).each((input_field) -> $(this).each((input_field) ->
new Chosen(this, data, options) unless ($ this).hasClass "chzn-done" new Chosen(this, options) unless ($ this).hasClass "chzn-done"
) )
}) })
class Chosen class Chosen
constructor: (elmn) -> constructor: (elmn, options) ->
this.set_default_values() this.set_default_values(options)
@form_field = elmn @form_field = elmn
@form_field_jq = $ @form_field @form_field_jq = $ @form_field
@ -28,7 +28,7 @@ class Chosen
this.register_observers() this.register_observers()
@form_field_jq.addClass "chzn-done" @form_field_jq.addClass "chzn-done"
set_default_values: -> set_default_values: (options) ->
@click_test_action = (evt) => this.test_active_click(evt) @click_test_action = (evt) => this.test_active_click(evt)
@active_field = false @active_field = false
@ -37,6 +37,7 @@ class Chosen
@result_highlighted = null @result_highlighted = null
@result_single_selected = null @result_single_selected = null
@choices = 0 @choices = 0
@results_none_found = options.no_results_text or "No results match"
set_up_html: -> set_up_html: ->
@container_id = if @form_field.id.length then @form_field.id.replace(/(:|\.)/g, '_') else this.generate_field_id() @container_id = if @form_field.id.length then @form_field.id.replace(/(:|\.)/g, '_') else this.generate_field_id()
@ -464,7 +465,7 @@ class Chosen
this.result_do_highlight do_high if do_high? this.result_do_highlight do_high if do_high?
no_results: (terms) -> no_results: (terms) ->
no_results_html = $('<li class="no-results">No results match "<span></span>"</li>') no_results_html = $('<li class="no-results">' + @results_none_found + ' "<span></span>"</li>')
no_results_html.find("span").first().html(terms) no_results_html.find("span").first().html(terms)
@search_results.append no_results_html @search_results.append no_results_html

View File

@ -1270,5 +1270,5 @@
</div> </div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
<script src="chosen/chosen.jquery.js" type="text/javascript"></script> <script src="chosen/chosen.jquery.js" type="text/javascript"></script>
<script type="text/javascript"> $(".chzn-select").chosen(); </script> <script type="text/javascript"> $(".chzn-select").chosen({no_results_text: 'Create strategy: '}); </script>
</body> </body>