Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inherit select classes #917

Merged
merged 5 commits into from
Dec 12, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions chosen/chosen.jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ Copyright (c) 2011 by Harvest
this.search_contains = this.options.search_contains || false;
this.choices = 0;
this.single_backstroke_delete = this.options.single_backstroke_delete || false;
return this.max_selected_options = this.options.max_selected_options || Infinity;
this.max_selected_options = this.options.max_selected_options || Infinity;
return this.inherit_select_classes = this.options.inherit_select_classes || false;
};

AbstractChosen.prototype.set_default_text = function() {
Expand Down Expand Up @@ -337,13 +338,21 @@ Copyright (c) 2011 by Harvest
};

Chosen.prototype.set_up_html = function() {
var container_div, container_props, dd_top, dd_width, sf_width;
var container_classes, container_div, container_props, dd_top, dd_width, sf_width;
this.container_id = this.form_field.id.length ? this.form_field.id.replace(/[^\w]/g, '_') : this.generate_field_id();
this.container_id += "_chzn";
container_classes = ["chzn-container"];
container_classes.push("chzn-container-" + (this.is_multiple ? "multi" : "single"));
if (this.inherit_select_classes && this.form_field.className) {
container_classes.push(this.form_field.className);
}
if (this.is_rtl) {
container_classes.push("chzn-rtl");
}
this.f_width = this.form_field_jq.outerWidth();
container_props = {
id: this.container_id,
"class": "chzn-container" + (this.is_rtl ? ' chzn-rtl' : ''),
"class": container_classes.join(' '),
style: 'width: ' + this.f_width + 'px;',
title: this.form_field.title
};
Expand All @@ -355,7 +364,6 @@ Copyright (c) 2011 by Harvest
}
this.form_field_jq.hide().after(container_div);
this.container = $('#' + this.container_id);
this.container.addClass("chzn-container-" + (this.is_multiple ? "multi" : "single"));
this.dropdown = this.container.find('div.chzn-drop').first();
dd_top = this.container.height();
dd_width = this.f_width - get_side_border_padding(this.dropdown);
Expand Down
2 changes: 1 addition & 1 deletion chosen/chosen.jquery.min.js

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions chosen/chosen.proto.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ Copyright (c) 2011 by Harvest
this.search_contains = this.options.search_contains || false;
this.choices = 0;
this.single_backstroke_delete = this.options.single_backstroke_delete || false;
return this.max_selected_options = this.options.max_selected_options || Infinity;
this.max_selected_options = this.options.max_selected_options || Infinity;
return this.inherit_select_classes = this.options.inherit_select_classes || false;
};

AbstractChosen.prototype.set_default_text = function() {
Expand Down Expand Up @@ -328,12 +329,20 @@ Copyright (c) 2011 by Harvest
};

Chosen.prototype.set_up_html = function() {
var base_template, container_props, dd_top, dd_width, sf_width;
var base_template, container_classes, container_props, dd_top, dd_width, sf_width;
this.container_id = this.form_field.identify().replace(/[^\w]/g, '_') + "_chzn";
container_classes = ["chzn-container"];
container_classes.push("chzn-container-" + (this.is_multiple ? "multi" : "single"));
if (this.inherit_select_classes && this.form_field.className) {
container_classes.push(this.form_field.className);
}
if (this.is_rtl) {
container_classes.push("chzn-rtl");
}
this.f_width = this.form_field.getStyle("width") ? parseInt(this.form_field.getStyle("width"), 10) : this.form_field.getWidth();
container_props = {
'id': this.container_id,
'class': "chzn-container" + (this.is_rtl ? ' chzn-rtl' : ''),
'class': container_classes.join(' '),
'style': 'width: ' + this.f_width + 'px',
'title': this.form_field.title
};
Expand All @@ -346,7 +355,6 @@ Copyright (c) 2011 by Harvest
after: base_template
});
this.container = $(this.container_id);
this.container.addClassName("chzn-container-" + (this.is_multiple ? "multi" : "single"));
this.dropdown = this.container.down('div.chzn-drop');
dd_top = this.container.getHeight();
dd_width = this.f_width - get_side_border_padding(this.dropdown);
Expand Down
2 changes: 1 addition & 1 deletion chosen/chosen.proto.min.js

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions coffee/chosen.jquery.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ class Chosen extends AbstractChosen
@container_id = if @form_field.id.length then @form_field.id.replace(/[^\w]/g, '_') else this.generate_field_id()
@container_id += "_chzn"

container_classes = ["chzn-container"]
container_classes.push "chzn-container-" + (if @is_multiple then "multi" else "single")
container_classes.push @form_field.className if @inherit_select_classes && @form_field.className
container_classes.push "chzn-rtl" if @is_rtl

@f_width = @form_field_jq.outerWidth()

container_props =
id: @container_id
class: "chzn-container#{ if @is_rtl then ' chzn-rtl' else '' }"
class: container_classes.join ' '
style: 'width: ' + (@f_width) + 'px;' #use parens around @f_width so coffeescript doesn't think + ' px' is a function parameter
title: @form_field.title

Expand All @@ -47,7 +52,6 @@ class Chosen extends AbstractChosen

@form_field_jq.hide().after container_div
@container = ($ '#' + @container_id)
@container.addClass( "chzn-container-" + (if @is_multiple then "multi" else "single") )
@dropdown = @container.find('div.chzn-drop').first()

dd_top = @container.height()
Expand Down
8 changes: 6 additions & 2 deletions coffee/chosen.proto.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,23 @@ class Chosen extends AbstractChosen
set_up_html: ->
@container_id = @form_field.identify().replace(/[^\w]/g, '_') + "_chzn"

container_classes = ["chzn-container"]
container_classes.push "chzn-container-" + (if @is_multiple then "multi" else "single")
container_classes.push @form_field.className if @inherit_select_classes && @form_field.className
container_classes.push "chzn-rtl" if @is_rtl

@f_width = if @form_field.getStyle("width") then parseInt @form_field.getStyle("width"), 10 else @form_field.getWidth()

container_props =
'id': @container_id
'class': "chzn-container#{ if @is_rtl then ' chzn-rtl' else '' }"
'class': container_classes.join ' '
'style': 'width: ' + (@f_width) + 'px' #use parens around @f_width so coffeescript doesn't think + ' px' is a function parameter
'title': @form_field.title

base_template = if @is_multiple then new Element('div', container_props).update( @multi_temp.evaluate({ "default": @default_text}) ) else new Element('div', container_props).update( @single_temp.evaluate({ "default":@default_text }) )

@form_field.hide().insert({ after: base_template })
@container = $(@container_id)
@container.addClassName( "chzn-container-" + (if @is_multiple then "multi" else "single") )
@dropdown = @container.down('div.chzn-drop')

dd_top = @container.getHeight()
Expand Down
1 change: 1 addition & 0 deletions coffee/lib/abstract-chosen.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class AbstractChosen
@choices = 0
@single_backstroke_delete = @options.single_backstroke_delete || false
@max_selected_options = @options.max_selected_options || Infinity
@inherit_select_classes = @options.inherit_select_classes || false

set_default_text: ->
if @form_field.getAttribute("data-placeholder")
Expand Down