Skip to content

Commit 7ca7624

Browse files
committed
Merge branch 'master' into issue/2903
2 parents 779a76d + a524f7a commit 7ca7624

27 files changed

+11613
-91
lines changed

.github/ISSUE_TEMPLATE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Tell us how to reproduce this issue.
1818

1919
3. Further steps, etc.
2020

21-
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.
21+
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.
2222

2323

2424
### Expected behavior

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ node_modules
44
public/*.js
55
public/*.css
66
public/*.json
7+
public/LICENSE.md
78
chosen*.zip
89
.sass-cache
910
.ruby-version

.travis.yml

-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ language: node_js
44

55
node_js:
66
- 6
7-
- node
87

98
addons:
109
apt:
@@ -13,11 +12,6 @@ addons:
1312
packages:
1413
- git
1514

16-
matrix:
17-
fast_finish: true
18-
allow_failures:
19-
- node_js: node
20-
2115
before_install: npm install -g grunt-cli
2216
before_script: grunt build package-npm package-bower
2317

Gruntfile.coffee

+12-4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ This file is generated by `grunt build`, do not edit it by hand.
3434
src: ['public/chosen.css']
3535
dest: 'public/chosen.css'
3636

37+
copy:
38+
main:
39+
src: 'LICENSE.md'
40+
dest: 'public/'
41+
php:
42+
src: 'composer.json'
43+
dest: 'public/'
44+
3745
coffee:
3846
options:
3947
join: true
@@ -97,21 +105,21 @@ This file is generated by `grunt build`, do not edit it by hand.
97105
jquery:
98106
options:
99107
vendor: [
100-
'https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'
108+
'public/docsupport/jquery-3.2.1.min.js'
101109
]
102110
specs: 'spec/public/jquery_specs.js'
103111
src: [ 'public/chosen.jquery.js' ]
104112
jquery_old:
105113
options:
106114
vendor: [
107-
'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js'
115+
'public/docsupport/jquery-1.12.4.min.js'
108116
]
109117
specs: 'spec/public/jquery_specs.js'
110118
src: [ 'public/chosen.jquery.js' ]
111119
proto:
112120
options:
113121
vendor: [
114-
'https://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js'
122+
'public/docsupport/prototype-1.7.0.0.js'
115123
'node_modules/simulant/dist/simulant.umd.js'
116124
]
117125
specs: 'spec/public/proto_specs.js'
@@ -120,7 +128,7 @@ This file is generated by `grunt build`, do not edit it by hand.
120128
grunt.loadTasks 'tasks'
121129

122130
grunt.registerTask 'default', ['build']
123-
grunt.registerTask 'build', ['coffee:jquery', 'coffee:proto', 'sass', 'concat', 'uglify', 'postcss', 'cssmin']
131+
grunt.registerTask 'build', ['coffee:jquery', 'coffee:proto', 'sass', 'concat', 'uglify', 'postcss', 'cssmin', 'copy']
124132
grunt.registerTask 'test', ['coffee', 'jasmine']
125133
grunt.registerTask 'test:jquery', ['coffee:test', 'coffee:jquery', 'jasmine:jquery', 'jasmine:jquery_old']
126134
grunt.registerTask 'test:proto', ['coffee:test', 'coffee:proto', 'jasmine:proto']

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ https://github.com/harvesthq/chosen/releases/
1313

1414
### Package managers
1515

16-
Chosen is available through [Bower](https://bower.io/) and [npm](https://www.npmjs.com),
17-
_however, the package names are not the same_.
16+
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_.
1817

1918
To install with Bower:
2019

@@ -28,6 +27,12 @@ To install with npm:
2827
npm install chosen-js
2928
```
3029

30+
To install with Composer:
31+
32+
```
33+
composer require harvesthq/chosen
34+
```
35+
3136
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.
3237

3338
### Contributing to this project

coffee/chosen.jquery.coffee

+52-16
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class Chosen extends AbstractChosen
5252

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

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

67+
this.set_aria_labels()
6668
this.results_build()
6769
this.set_tab_index()
6870
this.set_label_behavior()
@@ -106,7 +108,7 @@ class Chosen extends AbstractChosen
106108
@container.on 'click.chosen', (evt) -> evt.preventDefault(); return # gobble click of anchor
107109

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

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

121+
set_aria_labels: ->
122+
@search_field.attr "aria-owns", @search_results.attr "id"
123+
if @form_field.attributes["aria-label"]
124+
@search_field.attr "aria-label", @form_field.attributes["aria-label"]
125+
if @form_field.attributes["aria-labelledby"]
126+
@search_field.attr "aria-labelledby", @form_field.attributes["aria-labelledby"]
127+
else if Object.prototype.hasOwnProperty.call(@form_field,'labels') && @form_field.labels.length
128+
labelledbyList = ""
129+
for label, i in @form_field.labels
130+
if label.id is ""
131+
label.id = "#{@form_field.id}-chosen-label-#{i}"
132+
labelledbyList += @form_field.labels[i].id + " "
133+
@search_field.attr "aria-labelledby", labelledbyList
134+
119135
search_field_disabled: ->
120136
@is_disabled = @form_field.disabled || @form_field_jq.parents('fieldset').is(':disabled')
121137

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

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

166182
@active_field = false
167183
this.results_hide()
184+
@search_field.attr("aria-expanded",false);
168185

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

172189
this.show_search_field_default()
173190
this.search_field_scale()
174-
@search_field.blur()
191+
@search_field.trigger "blur"
175192

176193
activate_field: ->
177194
return if @is_disabled
@@ -180,7 +197,9 @@ class Chosen extends AbstractChosen
180197
@active_field = true
181198

182199
@search_field.val(@search_field.val())
183-
@search_field.focus()
200+
@search_field.attr("aria-expanded",true);
201+
this.search_results.attr("aria-busy", false);
202+
@search_field.trigger "focus"
184203

185204

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

199218
if @is_multiple
200219
@search_choices.find("li.search-choice").remove()
201-
else if not @is_multiple
220+
else
202221
this.single_set_selected_text()
203222
if @disable_search or @form_field.options.length <= @disable_search_threshold
204223
@search_field[0].readOnly = true
@@ -222,6 +241,8 @@ class Chosen extends AbstractChosen
222241
@result_highlight = el
223242
@result_highlight.addClass "highlighted"
224243

244+
@search_field.attr("aria-activedescendant", @result_highlight.attr("id"))
245+
225246
maxHeight = parseInt @search_results.css("maxHeight"), 10
226247
visible_top = @search_results.scrollTop()
227248
visible_bottom = maxHeight + visible_top
@@ -246,7 +267,7 @@ class Chosen extends AbstractChosen
246267
@container.addClass "chosen-with-drop"
247268
@results_showing = true
248269

249-
@search_field.focus()
270+
@search_field.trigger "focus"
250271
@search_field.val this.get_search_field_value()
251272

252273
this.winnow_results()
@@ -255,6 +276,9 @@ class Chosen extends AbstractChosen
255276
update_results_content: (content) ->
256277
@search_results.html content
257278

279+
fire_search_updated: (search_term) ->
280+
@form_field_jq.trigger("chosen:search_updated", {chosen: this, search_term: search_term})
281+
258282
results_hide: ->
259283
if @results_showing
260284
this.result_clear_highlight()
@@ -279,20 +303,26 @@ class Chosen extends AbstractChosen
279303
if @form_field_label.length > 0
280304
@form_field_label.on 'click.chosen', this.label_click_handler
281305

306+
set_search_field_placeholder: ->
307+
if @is_multiple and this.choices_count() < 1
308+
@search_field.attr('placeholder', @default_text)
309+
else
310+
@search_field.attr('placeholder', '')
311+
282312
show_search_field_default: ->
313+
@search_field.val('')
314+
do @set_search_field_placeholder
283315
if @is_multiple and this.choices_count() < 1 and not @active_field
284-
@search_field.val(@default_text)
285316
@search_field.addClass "default"
286317
else
287-
@search_field.val("")
288318
@search_field.removeClass "default"
289319

290320
search_results_mouseup: (evt) ->
291321
target = if $(evt.target).hasClass "active-result" then $(evt.target) else $(evt.target).parents(".active-result").first()
292322
if target.length
293323
@result_highlight = target
294324
this.result_select(evt)
295-
@search_field.focus()
325+
@search_field.trigger "focus"
296326

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

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

307337
if item.disabled
308338
choice.addClass 'search-choice-disabled'
309339
else
310340
close_link = $('<a />', { class: 'search-choice-close', 'data-option-array-index': item.array_index })
311341
close_link.on 'click.chosen', (evt) => this.choice_destroy_link_click(evt)
312342
choice.append close_link
343+
if @inherit_option_classes && item.classes
344+
choice[0].classList.add item.classes
313345

314346
@search_container.before choice
315347

@@ -321,14 +353,15 @@ class Chosen extends AbstractChosen
321353
choice_destroy: (link) ->
322354
if this.result_deselect( link[0].getAttribute("data-option-array-index") )
323355
if @active_field
324-
@search_field.focus()
356+
@search_field.trigger "focus"
325357
else
326358
this.show_search_field_default()
327359

328-
this.results_hide() if @is_multiple and this.choices_count() > 0 and this.get_search_field_value().length < 1
360+
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
329361

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

364+
do @set_search_field_placeholder
332365
this.search_field_scale()
333366

334367
results_reset: ->
@@ -366,15 +399,18 @@ class Chosen extends AbstractChosen
366399

367400
@form_field.options[item.options_index].selected = true
368401
@selected_option_count = null
369-
@search_field.val("")
370402

371403
if @is_multiple
372404
this.choice_build item
373405
else
374406
this.single_set_selected_text(this.choice_label(item))
375407

376408
if @is_multiple && (!@hide_results_on_select || (evt.metaKey or evt.ctrlKey))
377-
this.winnow_results()
409+
if evt.metaKey or evt.ctrlKey
410+
this.winnow_results(skip_highlight: true)
411+
else
412+
@search_field.val("")
413+
this.winnow_results()
378414
else
379415
this.results_hide()
380416
this.show_search_field_default()
@@ -494,7 +530,7 @@ class Chosen extends AbstractChosen
494530
style_block[style] = @search_field.css(style)
495531

496532
div = $('<div />').css(style_block)
497-
div.text this.get_search_field_value()
533+
div.text @get_search_field_value() || @search_field.attr('placeholder')
498534
$('body').append div
499535

500536
width = div.width() + 25

0 commit comments

Comments
 (0)