From 6837b1fa5e9410ca1a0a193ad2bf701bc34e1207 Mon Sep 17 00:00:00 2001 From: John Meuser Date: Tue, 21 Nov 2017 13:59:22 -0500 Subject: [PATCH] Add `option` class passthrough for multi-select --- coffee/chosen.jquery.coffee | 2 ++ coffee/chosen.proto.coffee | 2 ++ coffee/lib/abstract-chosen.coffee | 1 + public/options.html | 5 +++++ 4 files changed, 10 insertions(+) diff --git a/coffee/chosen.jquery.coffee b/coffee/chosen.jquery.coffee index 203af36aeda..ae411e2ef9b 100644 --- a/coffee/chosen.jquery.coffee +++ b/coffee/chosen.jquery.coffee @@ -310,6 +310,8 @@ class Chosen extends AbstractChosen close_link = $('', { class: 'search-choice-close', 'data-option-array-index': item.array_index }) close_link.on 'click.chosen', (evt) => this.choice_destroy_link_click(evt) choice.append close_link + if @inherit_option_classes && item.classes + choice[0].classList.add item.classes @search_container.before choice diff --git a/coffee/chosen.proto.coffee b/coffee/chosen.proto.coffee index 654a905507f..9f5fdd8af72 100644 --- a/coffee/chosen.proto.coffee +++ b/coffee/chosen.proto.coffee @@ -302,6 +302,8 @@ class @Chosen extends AbstractChosen close_link = new Element('a', { href: '#', class: 'search-choice-close', rel: item.array_index }) close_link.observe "click", (evt) => this.choice_destroy_link_click(evt) choice.insert close_link + if @inherit_option_classes && item.classes + choice[0].classList.add item.classes @search_container.insert { before: choice } diff --git a/coffee/lib/abstract-chosen.coffee b/coffee/lib/abstract-chosen.coffee index a83c194f826..fe80629f33a 100644 --- a/coffee/lib/abstract-chosen.coffee +++ b/coffee/lib/abstract-chosen.coffee @@ -30,6 +30,7 @@ class AbstractChosen @single_backstroke_delete = if @options.single_backstroke_delete? then @options.single_backstroke_delete else true @max_selected_options = @options.max_selected_options || Infinity @inherit_select_classes = @options.inherit_select_classes || false + @inherit_option_classes = @options.inherit_option_classes || false @display_selected_options = if @options.display_selected_options? then @options.display_selected_options else true @display_disabled_options = if @options.display_disabled_options? then @options.display_disabled_options else true @include_group_label_in_selected = @options.include_group_label_in_selected || false diff --git a/public/options.html b/public/options.html index 6a92bead277..283d9004fed 100644 --- a/public/options.html +++ b/public/options.html @@ -60,6 +60,11 @@

Example:

false When set to true, Chosen will grab any classes on the original select field and add them to Chosen’s container div. + + inherit_option_classes + false + When set to true, Chosen will grab any classes on the original option tags and add them to Chosen’s container li. + max_selected_options Infinity