Skip to content

Commit

Permalink
Merge branch 'master' into issue/2903
Browse files Browse the repository at this point in the history
  • Loading branch information
JJJ committed Jul 22, 2020
2 parents 779a76d + a524f7a commit 7ca7624
Show file tree
Hide file tree
Showing 27 changed files with 11,613 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Tell us how to reproduce this issue.

3. Further steps, etc.

Additionally, please link to a working demo that shows the issue so we can attempt to reproduce. You can use [this template](https://jsfiddle.net/5v3v353z/) as a base. Alternatively, confirm that the [Chosen demo page](http://harvesthq.github.io/chosen/) shows the issue.
Additionally, please link to a working demo that shows the issue so we can attempt to reproduce. You can use [this template](https://jsfiddle.net/j7k727cp/) as a base. Alternatively, confirm that the [Chosen demo page](http://harvesthq.github.io/chosen/) shows the issue.


### Expected behavior
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_modules
public/*.js
public/*.css
public/*.json
public/LICENSE.md
chosen*.zip
.sass-cache
.ruby-version
Expand Down
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ language: node_js

node_js:
- 6
- node

addons:
apt:
Expand All @@ -13,11 +12,6 @@ addons:
packages:
- git

matrix:
fast_finish: true
allow_failures:
- node_js: node

before_install: npm install -g grunt-cli
before_script: grunt build package-npm package-bower

Expand Down
16 changes: 12 additions & 4 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ This file is generated by `grunt build`, do not edit it by hand.
src: ['public/chosen.css']
dest: 'public/chosen.css'

copy:
main:
src: 'LICENSE.md'
dest: 'public/'
php:
src: 'composer.json'
dest: 'public/'

coffee:
options:
join: true
Expand Down Expand Up @@ -97,21 +105,21 @@ This file is generated by `grunt build`, do not edit it by hand.
jquery:
options:
vendor: [
'https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'
'public/docsupport/jquery-3.2.1.min.js'
]
specs: 'spec/public/jquery_specs.js'
src: [ 'public/chosen.jquery.js' ]
jquery_old:
options:
vendor: [
'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js'
'public/docsupport/jquery-1.12.4.min.js'
]
specs: 'spec/public/jquery_specs.js'
src: [ 'public/chosen.jquery.js' ]
proto:
options:
vendor: [
'https://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js'
'public/docsupport/prototype-1.7.0.0.js'
'node_modules/simulant/dist/simulant.umd.js'
]
specs: 'spec/public/proto_specs.js'
Expand All @@ -120,7 +128,7 @@ This file is generated by `grunt build`, do not edit it by hand.
grunt.loadTasks 'tasks'

grunt.registerTask 'default', ['build']
grunt.registerTask 'build', ['coffee:jquery', 'coffee:proto', 'sass', 'concat', 'uglify', 'postcss', 'cssmin']
grunt.registerTask 'build', ['coffee:jquery', 'coffee:proto', 'sass', 'concat', 'uglify', 'postcss', 'cssmin', 'copy']
grunt.registerTask 'test', ['coffee', 'jasmine']
grunt.registerTask 'test:jquery', ['coffee:test', 'coffee:jquery', 'jasmine:jquery', 'jasmine:jquery_old']
grunt.registerTask 'test:proto', ['coffee:test', 'coffee:proto', 'jasmine:proto']
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ https://github.com/harvesthq/chosen/releases/

### Package managers

Chosen is available through [Bower](https://bower.io/) and [npm](https://www.npmjs.com),
_however, the package names are not the same_.
Chosen is available through [Bower](https://bower.io/), [npm](https://www.npmjs.com), and [Composer](https://getcomposer.org/), _however, the package names are not the same_.

To install with Bower:

Expand All @@ -28,6 +27,12 @@ To install with npm:
npm install chosen-js
```

To install with Composer:

```
composer require harvesthq/chosen
```

The compiled files for these packages are automatically generated and stored in a [2nd Chosen repository](https://github.com/harvesthq/chosen-package). No pull requests will be accepted to that repository.

### Contributing to this project
Expand Down
68 changes: 52 additions & 16 deletions coffee/chosen.jquery.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Chosen extends AbstractChosen

@search_field = @container.find('input').first()
@search_results = @container.find('ul.chosen-results').first()
@search_results.attr('id', "#{@form_field.id}-chosen-search-results")
this.search_field_scale()

@search_no_results = @container.find('li.no-results').first()
Expand All @@ -63,6 +64,7 @@ class Chosen extends AbstractChosen
@search_container = @container.find('div.chosen-search').first()
@selected_item = @container.find('.chosen-single').first()

this.set_aria_labels()
this.results_build()
this.set_tab_index()
this.set_label_behavior()
Expand Down Expand Up @@ -106,7 +108,7 @@ class Chosen extends AbstractChosen
@container.on 'click.chosen', (evt) -> evt.preventDefault(); return # gobble click of anchor

destroy: ->
$(@container[0].ownerDocument).off 'click.chosen', @click_test_action
$(if @container[0].getRootNode? then @container[0].getRootNode() else @container[0].ownerDocument).off 'click.chosen', @click_test_action
@form_field_label.off 'click.chosen' if @form_field_label.length > 0

if @search_field[0].tabIndex
Expand All @@ -116,6 +118,20 @@ class Chosen extends AbstractChosen
@form_field_jq.removeData('chosen')
@form_field_jq.show()

set_aria_labels: ->
@search_field.attr "aria-owns", @search_results.attr "id"
if @form_field.attributes["aria-label"]
@search_field.attr "aria-label", @form_field.attributes["aria-label"]
if @form_field.attributes["aria-labelledby"]
@search_field.attr "aria-labelledby", @form_field.attributes["aria-labelledby"]
else if Object.prototype.hasOwnProperty.call(@form_field,'labels') && @form_field.labels.length
labelledbyList = ""
for label, i in @form_field.labels
if label.id is ""
label.id = "#{@form_field.id}-chosen-label-#{i}"
labelledbyList += @form_field.labels[i].id + " "
@search_field.attr "aria-labelledby", labelledbyList

search_field_disabled: ->
@is_disabled = @form_field.disabled || @form_field_jq.parents('fieldset').is(':disabled')

Expand All @@ -139,7 +155,7 @@ class Chosen extends AbstractChosen
if not (evt? and ($ evt.target).hasClass "search-choice-close")
if not @active_field
@search_field.val "" if @is_multiple
$(@container[0].ownerDocument).on 'click.chosen', @click_test_action
$(if @container[0].getRootNode? then @container[0].getRootNode() else @container[0].ownerDocument).on 'click.chosen', @click_test_action
this.results_show()
else if not @is_multiple and evt and (($(evt.target)[0] == @selected_item[0]) || $(evt.target).parents("a.chosen-single").length)
evt.preventDefault()
Expand All @@ -161,17 +177,18 @@ class Chosen extends AbstractChosen
this.close_field() if not @active_field and @container.hasClass "chosen-container-active"

close_field: ->
$(@container[0].ownerDocument).off "click.chosen", @click_test_action
$(if @container[0].getRootNode? then @container[0].getRootNode() else @container[0].ownerDocument).off "click.chosen", @click_test_action

@active_field = false
this.results_hide()
@search_field.attr("aria-expanded",false);

@container.removeClass "chosen-container-active"
this.clear_backstroke()

this.show_search_field_default()
this.search_field_scale()
@search_field.blur()
@search_field.trigger "blur"

activate_field: ->
return if @is_disabled
Expand All @@ -180,7 +197,9 @@ class Chosen extends AbstractChosen
@active_field = true

@search_field.val(@search_field.val())
@search_field.focus()
@search_field.attr("aria-expanded",true);
this.search_results.attr("aria-busy", false);
@search_field.trigger "focus"


test_active_click: (evt) ->
Expand All @@ -198,7 +217,7 @@ class Chosen extends AbstractChosen

if @is_multiple
@search_choices.find("li.search-choice").remove()
else if not @is_multiple
else
this.single_set_selected_text()
if @disable_search or @form_field.options.length <= @disable_search_threshold
@search_field[0].readOnly = true
Expand All @@ -222,6 +241,8 @@ class Chosen extends AbstractChosen
@result_highlight = el
@result_highlight.addClass "highlighted"

@search_field.attr("aria-activedescendant", @result_highlight.attr("id"))

maxHeight = parseInt @search_results.css("maxHeight"), 10
visible_top = @search_results.scrollTop()
visible_bottom = maxHeight + visible_top
Expand All @@ -246,7 +267,7 @@ class Chosen extends AbstractChosen
@container.addClass "chosen-with-drop"
@results_showing = true

@search_field.focus()
@search_field.trigger "focus"
@search_field.val this.get_search_field_value()

this.winnow_results()
Expand All @@ -255,6 +276,9 @@ class Chosen extends AbstractChosen
update_results_content: (content) ->
@search_results.html content

fire_search_updated: (search_term) ->
@form_field_jq.trigger("chosen:search_updated", {chosen: this, search_term: search_term})

results_hide: ->
if @results_showing
this.result_clear_highlight()
Expand All @@ -279,20 +303,26 @@ class Chosen extends AbstractChosen
if @form_field_label.length > 0
@form_field_label.on 'click.chosen', this.label_click_handler

set_search_field_placeholder: ->
if @is_multiple and this.choices_count() < 1
@search_field.attr('placeholder', @default_text)
else
@search_field.attr('placeholder', '')

show_search_field_default: ->
@search_field.val('')
do @set_search_field_placeholder
if @is_multiple and this.choices_count() < 1 and not @active_field
@search_field.val(@default_text)
@search_field.addClass "default"
else
@search_field.val("")
@search_field.removeClass "default"

search_results_mouseup: (evt) ->
target = if $(evt.target).hasClass "active-result" then $(evt.target) else $(evt.target).parents(".active-result").first()
if target.length
@result_highlight = target
this.result_select(evt)
@search_field.focus()
@search_field.trigger "focus"

search_results_mouseover: (evt) ->
target = if $(evt.target).hasClass "active-result" then $(evt.target) else $(evt.target).parents(".active-result").first()
Expand All @@ -302,14 +332,16 @@ class Chosen extends AbstractChosen
this.result_clear_highlight() if $(evt.target).hasClass("active-result") or $(evt.target).parents('.active-result').first()

choice_build: (item) ->
choice = $('<li />', { class: "search-choice" }).html("<span>#{this.choice_label(item)}</span>")
choice = $('<li />', { class: "search-choice", "data-value": item.value }).html("<span>#{this.choice_label(item)}</span>")

if item.disabled
choice.addClass 'search-choice-disabled'
else
close_link = $('<a />', { 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

Expand All @@ -321,14 +353,15 @@ class Chosen extends AbstractChosen
choice_destroy: (link) ->
if this.result_deselect( link[0].getAttribute("data-option-array-index") )
if @active_field
@search_field.focus()
@search_field.trigger "focus"
else
this.show_search_field_default()

this.results_hide() if @is_multiple and this.choices_count() > 0 and this.get_search_field_value().length < 1
this.results_hide() if @is_multiple and this.hide_results_on_select and this.choices_count() > 0 and this.get_search_field_value().length < 1

link.parents('li').first().remove()

do @set_search_field_placeholder
this.search_field_scale()

results_reset: ->
Expand Down Expand Up @@ -366,15 +399,18 @@ class Chosen extends AbstractChosen

@form_field.options[item.options_index].selected = true
@selected_option_count = null
@search_field.val("")

if @is_multiple
this.choice_build item
else
this.single_set_selected_text(this.choice_label(item))

if @is_multiple && (!@hide_results_on_select || (evt.metaKey or evt.ctrlKey))
this.winnow_results()
if evt.metaKey or evt.ctrlKey
this.winnow_results(skip_highlight: true)
else
@search_field.val("")
this.winnow_results()
else
this.results_hide()
this.show_search_field_default()
Expand Down Expand Up @@ -494,7 +530,7 @@ class Chosen extends AbstractChosen
style_block[style] = @search_field.css(style)

div = $('<div />').css(style_block)
div.text this.get_search_field_value()
div.text @get_search_field_value() || @search_field.attr('placeholder')
$('body').append div

width = div.width() + 25
Expand Down
Loading

0 comments on commit 7ca7624

Please sign in to comment.