Add options object for both prototype and jquery version.

js_style_fix
Patrick Filler 2011-09-12 17:31:10 -04:00
parent 718f500c9a
commit 800e3d5502
6 changed files with 23 additions and 25 deletions

View File

@ -11,20 +11,15 @@
/*
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;
$.fn.extend({
<<<<<<< HEAD
chosen: function(data, options) {
chosen: function(options) {
if ($.browser === "msie" && ($.browser.version === "6.0" || $.browser.version === "7.0")) {
return this;
}
=======
chosen: function(options) {
>>>>>>> f9674e7db221f119f1f5fb8e33a277c3b37ee013
return $(this).each(function(input_field) {
if (!($(this)).hasClass("chzn-done")) {
return new Chosen(this, options);
@ -34,7 +29,8 @@
});
Chosen = (function() {
function Chosen(elmn, options) {
this.set_default_values(options || {});
this.options = options || {};
this.set_default_values();
this.form_field = elmn;
this.form_field_jq = $(this.form_field);
this.is_multiple = this.form_field.multiple;
@ -44,7 +40,7 @@
this.register_observers();
this.form_field_jq.addClass("chzn-done");
}
Chosen.prototype.set_default_values = function(options) {
Chosen.prototype.set_default_values = function() {
this.click_test_action = __bind(function(evt) {
return this.test_active_click(evt);
}, this);
@ -54,7 +50,7 @@
this.result_highlighted = null;
this.result_single_selected = null;
this.choices = 0;
return this.results_none_found = options.no_results_text || "No results match";
return this.results_none_found = this.options.no_results_text || "No results match";
};
Chosen.prototype.set_up_html = function() {
var container_div, dd_top, dd_width, sf_width;

File diff suppressed because one or more lines are too long

View File

@ -11,12 +11,12 @@
/*
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;
Chosen = (function() {
function Chosen(elmn) {
function Chosen(elmn, options) {
this.options = options || {};
this.set_default_values();
this.form_field = elmn;
this.is_multiple = this.form_field.multiple;
@ -36,10 +36,11 @@
this.result_highlighted = null;
this.result_single_selected = null;
this.choices = 0;
this.results_none_found = this.options.no_results_text || "No results match";
this.single_temp = new Template('<a href="javascript:void(0)" class="chzn-single"><span>#{default}</span><div><b></b></div></a><div class="chzn-drop" style="left:-9000px;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>');
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" style="left:-9000px;"><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>');
return this.no_results_temp = new Template('<li class="no-results">No results match "<span>#{terms}</span>"</li>');
return this.no_results_temp = new Template('<li class="no-results">' + this.results_none_found + ' "<span>#{terms}</span>"</li>');
};
Chosen.prototype.set_up_html = function() {
var base_template, container_props, dd_top, dd_width, sf_width;

File diff suppressed because one or more lines are too long

View File

@ -16,7 +16,8 @@ $.fn.extend({
class Chosen
constructor: (elmn, options) ->
this.set_default_values(options or {})
@options = options or {}
this.set_default_values()
@form_field = elmn
@form_field_jq = $ @form_field
@ -29,7 +30,7 @@ class Chosen
this.register_observers()
@form_field_jq.addClass "chzn-done"
set_default_values: (options) ->
set_default_values: ->
@click_test_action = (evt) => this.test_active_click(evt)
@active_field = false
@ -38,7 +39,7 @@ class Chosen
@result_highlighted = null
@result_single_selected = null
@choices = 0
@results_none_found = options.no_results_text or "No results match"
@results_none_found = @options.no_results_text or "No results match"
set_up_html: ->
@container_id = if @form_field.id.length then @form_field.id.replace(/(:|\.)/g, '_') else this.generate_field_id()

View File

@ -6,7 +6,9 @@ root = this
class Chosen
constructor: (elmn) ->
constructor: (elmn, options) ->
@options = options or {}
this.set_default_values()
@form_field = elmn
@ -30,11 +32,13 @@ class Chosen
@result_single_selected = null
@choices = 0
@results_none_found = @options.no_results_text or "No results match"
# HTML Templates
@single_temp = new Template('<a href="javascript:void(0)" class="chzn-single"><span>#{default}</span><div><b></b></div></a><div class="chzn-drop" style="left:-9000px;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>')
@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" style="left:-9000px;"><ul class="chzn-results"></ul></div>')
@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>')
@no_results_temp = new Template('<li class="no-results">No results match "<span>#{terms}</span>"</li>')
@no_results_temp = new Template('<li class="no-results">' + @results_none_found + ' "<span>#{terms}</span>"</li>')
set_up_html: ->