chosen-rails 1.5.2 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +14 -10
- data/Rakefile +1 -1
- data/chosen-rails.gemspec +1 -1
- data/lib/chosen-rails/rspec.rb +7 -6
- data/lib/chosen-rails/source_file.rb +6 -8
- data/lib/chosen-rails/version.rb +2 -2
- data/lib/chosen-rails.rb +1 -1
- data/vendor/assets/javascripts/chosen.jquery.coffee +118 -118
- data/vendor/assets/javascripts/chosen.proto.coffee +113 -97
- data/vendor/assets/javascripts/lib/abstract-chosen.coffee +116 -35
- data/vendor/assets/javascripts/lib/select-parser.coffee +1 -16
- data/vendor/assets/stylesheets/chosen-base.scss +18 -10
- data/vendor/assets/stylesheets/chosen.scss +375 -9
- metadata +9 -11
- data/vendor/assets/stylesheets/chosen-compass.scss +0 -63
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cb9a01d9e95e9334d789999deed11a5f4eeff7f7bf4aded85153ccb90e2cdb60
|
4
|
+
data.tar.gz: e0598c9ee4777bffaee6f134fe1f8d0b01d9bfc2d5e93291f24246d94a7ecabe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: deff791359ce236e7bcb49d58979c8e57e4732e4feb8b6707359ff93ce4e918a143a7e8010e9a0a346c723bad9364596babb8081e5d97680b1afee2fc0a130ba
|
7
|
+
data.tar.gz: '0832921699aa80ee2771bc75074e651261587f620aa6a70118208e5035cbe8f567d4bae95e4006587a52e3a0964e0eb7ce758414453634332b1c35cfc83eeb4e'
|
data/README.md
CHANGED
@@ -2,22 +2,24 @@
|
|
2
2
|
|
3
3
|
[Chosen](https://github.com/harvesthq/chosen) is a library for making long, unwieldy select boxes more user friendly.
|
4
4
|
|
5
|
-
The `chosen-rails` gem integrates the `Chosen`
|
5
|
+
The `chosen-rails` gem integrates the `Chosen` into Rails asset pipeline with the [sprockets-rails](https://github.com/rails/sprockets-rails).
|
6
6
|
|
7
7
|
## Usage
|
8
8
|
|
9
9
|
### Install chosen-rails gem
|
10
10
|
|
11
|
-
Include `chosen-rails` in
|
11
|
+
Include `chosen-rails` in Gemfile
|
12
12
|
|
13
13
|
```rb
|
14
|
-
gem '
|
14
|
+
gem 'jquery-rails'
|
15
15
|
gem 'chosen-rails'
|
16
16
|
```
|
17
17
|
|
18
18
|
Then run `bundle install`
|
19
19
|
|
20
|
-
|
20
|
+
### About JQuery
|
21
|
+
|
22
|
+
You can get jquery via [jquery-rails](https://github.com/rails/jquery-rails).
|
21
23
|
|
22
24
|
Please consider [jquery-turbolinks](https://github.com/kossnocorp/jquery.turbolinks) if you have turbolinks issues for Rails 4 +.
|
23
25
|
|
@@ -26,12 +28,14 @@ Please consider [jquery-turbolinks](https://github.com/kossnocorp/jquery.turboli
|
|
26
28
|
Add to your `app/assets/javascripts/application.js` if use with jQuery
|
27
29
|
|
28
30
|
```coffee
|
31
|
+
//= require jquery
|
29
32
|
//= require chosen-jquery
|
30
33
|
```
|
31
34
|
|
32
35
|
Or with Prototype
|
33
36
|
|
34
37
|
```coffee
|
38
|
+
//= require jquery
|
35
39
|
//= require chosen-prototype
|
36
40
|
```
|
37
41
|
|
@@ -39,18 +43,18 @@ Or with Prototype
|
|
39
43
|
|
40
44
|
Add to your `app/assets/stylesheets/application.css`
|
41
45
|
|
42
|
-
```scss
|
43
|
-
*= require chosen-compass
|
44
|
-
```
|
45
|
-
|
46
|
-
or without `compass-rails`
|
47
|
-
|
48
46
|
```scss
|
49
47
|
*= require chosen
|
50
48
|
```
|
51
49
|
|
52
50
|
### Enable chosen javascript by specific css class
|
53
51
|
|
52
|
+
For rails 6, remember to add `javascript_include_tag` in `app/views/layouts/application.html.erb`, like
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
<%= javascript_include_tag 'application' %>
|
56
|
+
```
|
57
|
+
|
54
58
|
Add to one coffee script file, like `scaffold.js.coffee`
|
55
59
|
|
56
60
|
```coffee
|
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ task 'update-chosen', 'repository_url', 'branch' do |task, args|
|
|
9
9
|
files = SourceFile.new
|
10
10
|
files.fetch remote, branch
|
11
11
|
files.eject_javascript_class_from_closure
|
12
|
-
files.remove_compass_lines
|
13
12
|
files.add_depend_on_asset
|
13
|
+
files.change_url_to_image_url
|
14
14
|
files.cleanup
|
15
15
|
end
|
data/chosen-rails.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
|
|
18
18
|
|
19
19
|
gem.add_dependency 'railties', '>= 3.0'
|
20
20
|
gem.add_dependency 'coffee-rails', '>= 3.2'
|
21
|
-
gem.add_dependency '
|
21
|
+
gem.add_dependency 'sassc-rails', '>= 2.1.2'
|
22
22
|
|
23
23
|
gem.add_development_dependency 'bundler', '>= 1.0'
|
24
24
|
gem.add_development_dependency 'rails', '>= 3.0'
|
data/lib/chosen-rails/rspec.rb
CHANGED
@@ -34,22 +34,22 @@ module Chosen
|
|
34
34
|
def chosen_find_container(from, options)
|
35
35
|
from = from.to_s
|
36
36
|
|
37
|
-
id = from
|
37
|
+
id = from.underscore
|
38
38
|
id = "##{id}" unless from.start_with?('#')
|
39
39
|
id = "#{id}_chosen" unless from.end_with?('_chosen')
|
40
40
|
|
41
|
-
find(:css, id, options)
|
41
|
+
find(:css, id, **options)
|
42
42
|
rescue Capybara::ElementNotFound
|
43
|
-
label = find('label', { text: from }.merge(options))
|
43
|
+
label = find('label', **{ text: from }.merge(options))
|
44
44
|
|
45
|
-
find(:css, "##{label[:for]}_chosen", options)
|
45
|
+
find(:css, "##{label[:for].underscore}_chosen", **options)
|
46
46
|
end
|
47
47
|
|
48
48
|
def chosen_find_input(from, options)
|
49
49
|
from = from.to_s
|
50
50
|
from = "##{from}" unless from.start_with?('#')
|
51
51
|
|
52
|
-
find(:css, from, options)
|
52
|
+
find(:css, from.underscore, **options)
|
53
53
|
end
|
54
54
|
|
55
55
|
def chosen_multiselect?(input)
|
@@ -63,7 +63,7 @@ module Chosen
|
|
63
63
|
input.click
|
64
64
|
|
65
65
|
within "##{input[:id]} .chosen-drop .chosen-results" do
|
66
|
-
result = find('.active-result', text: item)
|
66
|
+
result = find('.active-result', text: item, match: :prefer_exact)
|
67
67
|
|
68
68
|
result.click if result.visible?
|
69
69
|
end
|
@@ -88,5 +88,6 @@ module Chosen
|
|
88
88
|
end
|
89
89
|
|
90
90
|
RSpec.configure do |config|
|
91
|
+
config.include Chosen::Rspec::FeatureHelpers, type: :system
|
91
92
|
config.include Chosen::Rspec::FeatureHelpers, type: :feature
|
92
93
|
end
|
@@ -31,14 +31,6 @@ class SourceFile < Thor
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
desc 'remove compass lines', 'remove compass lines'
|
35
|
-
def remove_compass_lines
|
36
|
-
self.destination_root = 'vendor/assets'
|
37
|
-
gsub_file 'stylesheets/chosen-base.scss', /^\s*\@include.*\n/, ''
|
38
|
-
gsub_file 'stylesheets/chosen-base.scss', /^\@import.*\n/, ''
|
39
|
-
# gsub_file 'stylesheets/chosen-base.scss', /\n(\$chosen-sprite:)/, '\1'
|
40
|
-
end
|
41
|
-
|
42
34
|
desc 'add depend_on_asset', 'add depend_on_asset'
|
43
35
|
def add_depend_on_asset
|
44
36
|
self.destination_root = 'vendor/assets'
|
@@ -49,6 +41,12 @@ class SourceFile < Thor
|
|
49
41
|
prepend_to_file 'stylesheets/chosen-base.scss', scss
|
50
42
|
end
|
51
43
|
|
44
|
+
desc 'change url to image url', 'change url to image url'
|
45
|
+
def change_url_to_image_url
|
46
|
+
self.destination_root = 'vendor/assets'
|
47
|
+
gsub_file 'stylesheets/chosen-base.scss', /url/, 'image-url'
|
48
|
+
end
|
49
|
+
|
52
50
|
desc 'clean up useless files', 'clean up useless files'
|
53
51
|
def cleanup
|
54
52
|
self.destination_root = 'vendor/assets'
|
data/lib/chosen-rails/version.rb
CHANGED
data/lib/chosen-rails.rb
CHANGED
@@ -24,7 +24,6 @@ class Chosen extends AbstractChosen
|
|
24
24
|
setup: ->
|
25
25
|
@form_field_jq = $ @form_field
|
26
26
|
@current_selectedIndex = @form_field.selectedIndex
|
27
|
-
@is_rtl = @form_field_jq.hasClass "chosen-rtl"
|
28
27
|
|
29
28
|
set_up_html: ->
|
30
29
|
container_classes = ["chosen-container"]
|
@@ -34,17 +33,19 @@ class Chosen extends AbstractChosen
|
|
34
33
|
|
35
34
|
container_props =
|
36
35
|
'class': container_classes.join ' '
|
37
|
-
'style': "width: #{this.container_width()};"
|
38
36
|
'title': @form_field.title
|
39
37
|
|
40
38
|
container_props.id = @form_field.id.replace(/[^\w]/g, '_') + "_chosen" if @form_field.id.length
|
41
39
|
|
42
40
|
@container = ($ "<div />", container_props)
|
43
41
|
|
42
|
+
# CSP without 'unsafe-inline' doesn't allow setting the style attribute directly
|
43
|
+
@container.width this.container_width()
|
44
|
+
|
44
45
|
if @is_multiple
|
45
|
-
@container.html
|
46
|
+
@container.html this.get_multi_html()
|
46
47
|
else
|
47
|
-
@container.html
|
48
|
+
@container.html this.get_single_html()
|
48
49
|
|
49
50
|
@form_field_jq.hide().after @container
|
50
51
|
@dropdown = @container.find('div.chosen-drop').first()
|
@@ -70,42 +71,44 @@ class Chosen extends AbstractChosen
|
|
70
71
|
@form_field_jq.trigger("chosen:ready", {chosen: this})
|
71
72
|
|
72
73
|
register_observers: ->
|
73
|
-
@container.
|
74
|
-
@container.
|
75
|
-
|
76
|
-
@container.
|
77
|
-
@container.
|
78
|
-
@container.
|
79
|
-
@container.
|
80
|
-
|
81
|
-
@search_results.
|
82
|
-
@search_results.
|
83
|
-
@search_results.
|
84
|
-
@search_results.
|
85
|
-
|
86
|
-
@search_results.
|
87
|
-
@search_results.
|
88
|
-
@search_results.
|
89
|
-
|
90
|
-
@form_field_jq.
|
91
|
-
@form_field_jq.
|
92
|
-
@form_field_jq.
|
93
|
-
@form_field_jq.
|
94
|
-
|
95
|
-
@search_field.
|
96
|
-
@search_field.
|
97
|
-
@search_field.
|
98
|
-
@search_field.
|
99
|
-
@search_field.
|
100
|
-
@search_field.
|
74
|
+
@container.on 'touchstart.chosen', (evt) => this.container_mousedown(evt); return
|
75
|
+
@container.on 'touchend.chosen', (evt) => this.container_mouseup(evt); return
|
76
|
+
|
77
|
+
@container.on 'mousedown.chosen', (evt) => this.container_mousedown(evt); return
|
78
|
+
@container.on 'mouseup.chosen', (evt) => this.container_mouseup(evt); return
|
79
|
+
@container.on 'mouseenter.chosen', (evt) => this.mouse_enter(evt); return
|
80
|
+
@container.on 'mouseleave.chosen', (evt) => this.mouse_leave(evt); return
|
81
|
+
|
82
|
+
@search_results.on 'mouseup.chosen', (evt) => this.search_results_mouseup(evt); return
|
83
|
+
@search_results.on 'mouseover.chosen', (evt) => this.search_results_mouseover(evt); return
|
84
|
+
@search_results.on 'mouseout.chosen', (evt) => this.search_results_mouseout(evt); return
|
85
|
+
@search_results.on 'mousewheel.chosen DOMMouseScroll.chosen', (evt) => this.search_results_mousewheel(evt); return
|
86
|
+
|
87
|
+
@search_results.on 'touchstart.chosen', (evt) => this.search_results_touchstart(evt); return
|
88
|
+
@search_results.on 'touchmove.chosen', (evt) => this.search_results_touchmove(evt); return
|
89
|
+
@search_results.on 'touchend.chosen', (evt) => this.search_results_touchend(evt); return
|
90
|
+
|
91
|
+
@form_field_jq.on "chosen:updated.chosen", (evt) => this.results_update_field(evt); return
|
92
|
+
@form_field_jq.on "chosen:activate.chosen", (evt) => this.activate_field(evt); return
|
93
|
+
@form_field_jq.on "chosen:open.chosen", (evt) => this.container_mousedown(evt); return
|
94
|
+
@form_field_jq.on "chosen:close.chosen", (evt) => this.close_field(evt); return
|
95
|
+
|
96
|
+
@search_field.on 'blur.chosen', (evt) => this.input_blur(evt); return
|
97
|
+
@search_field.on 'keyup.chosen', (evt) => this.keyup_checker(evt); return
|
98
|
+
@search_field.on 'keydown.chosen', (evt) => this.keydown_checker(evt); return
|
99
|
+
@search_field.on 'focus.chosen', (evt) => this.input_focus(evt); return
|
100
|
+
@search_field.on 'cut.chosen', (evt) => this.clipboard_event_checker(evt); return
|
101
|
+
@search_field.on 'paste.chosen', (evt) => this.clipboard_event_checker(evt); return
|
101
102
|
|
102
103
|
if @is_multiple
|
103
|
-
@search_choices.
|
104
|
+
@search_choices.on 'click.chosen', (evt) => this.choices_click(evt); return
|
104
105
|
else
|
105
|
-
@container.
|
106
|
+
@container.on 'click.chosen', (evt) -> evt.preventDefault(); return # gobble click of anchor
|
106
107
|
|
107
108
|
destroy: ->
|
108
|
-
$(@container[0].ownerDocument).
|
109
|
+
$(@container[0].ownerDocument).off 'click.chosen', @click_test_action
|
110
|
+
@form_field_label.off 'click.chosen' if @form_field_label.length > 0
|
111
|
+
|
109
112
|
if @search_field[0].tabIndex
|
110
113
|
@form_field_jq[0].tabIndex = @search_field[0].tabIndex
|
111
114
|
|
@@ -114,32 +117,35 @@ class Chosen extends AbstractChosen
|
|
114
117
|
@form_field_jq.show()
|
115
118
|
|
116
119
|
search_field_disabled: ->
|
117
|
-
@is_disabled = @form_field_jq
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
120
|
+
@is_disabled = @form_field.disabled || @form_field_jq.parents('fieldset').is(':disabled')
|
121
|
+
|
122
|
+
@container.toggleClass 'chosen-disabled', @is_disabled
|
123
|
+
@search_field[0].disabled = @is_disabled
|
124
|
+
|
125
|
+
unless @is_multiple
|
126
|
+
@selected_item.off 'focus.chosen', this.activate_field
|
127
|
+
|
128
|
+
if @is_disabled
|
122
129
|
this.close_field()
|
123
|
-
else
|
124
|
-
@
|
125
|
-
@search_field[0].disabled = false
|
126
|
-
@selected_item.bind "focus.chosen", @activate_action if !@is_multiple
|
130
|
+
else unless @is_multiple
|
131
|
+
@selected_item.on 'focus.chosen', this.activate_field
|
127
132
|
|
128
133
|
container_mousedown: (evt) ->
|
129
|
-
if
|
130
|
-
if evt and evt.type is "mousedown" and not @results_showing
|
131
|
-
evt.preventDefault()
|
134
|
+
return if @is_disabled
|
132
135
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
136
|
+
if evt and evt.type in ['mousedown', 'touchstart'] and not @results_showing
|
137
|
+
evt.preventDefault()
|
138
|
+
|
139
|
+
if not (evt? and ($ evt.target).hasClass "search-choice-close")
|
140
|
+
if not @active_field
|
141
|
+
@search_field.val "" if @is_multiple
|
142
|
+
$(@container[0].ownerDocument).on 'click.chosen', @click_test_action
|
143
|
+
this.results_show()
|
144
|
+
else if not @is_multiple and evt and (($(evt.target)[0] == @selected_item[0]) || $(evt.target).parents("a.chosen-single").length)
|
145
|
+
evt.preventDefault()
|
146
|
+
this.results_toggle()
|
141
147
|
|
142
|
-
|
148
|
+
this.activate_field()
|
143
149
|
|
144
150
|
container_mouseup: (evt) ->
|
145
151
|
this.results_reset(evt) if evt.target.nodeName is "ABBR" and not @is_disabled
|
@@ -155,7 +161,7 @@ class Chosen extends AbstractChosen
|
|
155
161
|
this.close_field() if not @active_field and @container.hasClass "chosen-container-active"
|
156
162
|
|
157
163
|
close_field: ->
|
158
|
-
$(@container[0].ownerDocument).
|
164
|
+
$(@container[0].ownerDocument).off "click.chosen", @click_test_action
|
159
165
|
|
160
166
|
@active_field = false
|
161
167
|
this.results_hide()
|
@@ -165,8 +171,11 @@ class Chosen extends AbstractChosen
|
|
165
171
|
|
166
172
|
this.show_search_field_default()
|
167
173
|
this.search_field_scale()
|
174
|
+
@search_field.blur()
|
168
175
|
|
169
176
|
activate_field: ->
|
177
|
+
return if @is_disabled
|
178
|
+
|
170
179
|
@container.addClass "chosen-container-active"
|
171
180
|
@active_field = true
|
172
181
|
|
@@ -189,7 +198,7 @@ class Chosen extends AbstractChosen
|
|
189
198
|
|
190
199
|
if @is_multiple
|
191
200
|
@search_choices.find("li.search-choice").remove()
|
192
|
-
else
|
201
|
+
else
|
193
202
|
this.single_set_selected_text()
|
194
203
|
if @disable_search or @form_field.options.length <= @disable_search_threshold
|
195
204
|
@search_field[0].readOnly = true
|
@@ -238,7 +247,7 @@ class Chosen extends AbstractChosen
|
|
238
247
|
@results_showing = true
|
239
248
|
|
240
249
|
@search_field.focus()
|
241
|
-
@search_field.val
|
250
|
+
@search_field.val this.get_search_field_value()
|
242
251
|
|
243
252
|
this.winnow_results()
|
244
253
|
@form_field_jq.trigger("chosen:showing_dropdown", {chosen: this})
|
@@ -268,7 +277,7 @@ class Chosen extends AbstractChosen
|
|
268
277
|
@form_field_label = $("label[for='#{@form_field.id}']") #next check for a for=#{id}
|
269
278
|
|
270
279
|
if @form_field_label.length > 0
|
271
|
-
@form_field_label.
|
280
|
+
@form_field_label.on 'click.chosen', this.label_click_handler
|
272
281
|
|
273
282
|
show_search_field_default: ->
|
274
283
|
if @is_multiple and this.choices_count() < 1 and not @active_field
|
@@ -290,7 +299,7 @@ class Chosen extends AbstractChosen
|
|
290
299
|
this.result_do_highlight( target ) if target
|
291
300
|
|
292
301
|
search_results_mouseout: (evt) ->
|
293
|
-
this.result_clear_highlight() if $(evt.target).hasClass
|
302
|
+
this.result_clear_highlight() if $(evt.target).hasClass("active-result") or $(evt.target).parents('.active-result').first()
|
294
303
|
|
295
304
|
choice_build: (item) ->
|
296
305
|
choice = $('<li />', { class: "search-choice" }).html("<span>#{this.choice_label(item)}</span>")
|
@@ -299,7 +308,7 @@ class Chosen extends AbstractChosen
|
|
299
308
|
choice.addClass 'search-choice-disabled'
|
300
309
|
else
|
301
310
|
close_link = $('<a />', { class: 'search-choice-close', 'data-option-array-index': item.array_index })
|
302
|
-
close_link.
|
311
|
+
close_link.on 'click.chosen', (evt) => this.choice_destroy_link_click(evt)
|
303
312
|
choice.append close_link
|
304
313
|
|
305
314
|
@search_container.before choice
|
@@ -311,9 +320,12 @@ class Chosen extends AbstractChosen
|
|
311
320
|
|
312
321
|
choice_destroy: (link) ->
|
313
322
|
if this.result_deselect( link[0].getAttribute("data-option-array-index") )
|
314
|
-
|
323
|
+
if @active_field
|
324
|
+
@search_field.focus()
|
325
|
+
else
|
326
|
+
this.show_search_field_default()
|
315
327
|
|
316
|
-
this.results_hide() if @is_multiple and this.choices_count() > 0 and
|
328
|
+
this.results_hide() if @is_multiple and this.choices_count() > 0 and this.get_search_field_value().length < 1
|
317
329
|
|
318
330
|
link.parents('li').first().remove()
|
319
331
|
|
@@ -325,7 +337,7 @@ class Chosen extends AbstractChosen
|
|
325
337
|
this.single_set_selected_text()
|
326
338
|
this.show_search_field_default()
|
327
339
|
this.results_reset_cleanup()
|
328
|
-
|
340
|
+
this.trigger_form_field_change()
|
329
341
|
this.results_hide() if @active_field
|
330
342
|
|
331
343
|
results_reset_cleanup: ->
|
@@ -360,10 +372,17 @@ class Chosen extends AbstractChosen
|
|
360
372
|
else
|
361
373
|
this.single_set_selected_text(this.choice_label(item))
|
362
374
|
|
363
|
-
|
364
|
-
|
375
|
+
if @is_multiple && (!@hide_results_on_select || (evt.metaKey or evt.ctrlKey))
|
376
|
+
if evt.metaKey or evt.ctrlKey
|
377
|
+
this.winnow_results(skip_highlight: true)
|
378
|
+
else
|
379
|
+
@search_field.val("")
|
380
|
+
this.winnow_results()
|
381
|
+
else
|
382
|
+
this.results_hide()
|
383
|
+
this.show_search_field_default()
|
365
384
|
|
366
|
-
|
385
|
+
this.trigger_form_field_change selected: @form_field.options[item.options_index].value if @is_multiple || @form_field.selectedIndex != @current_selectedIndex
|
367
386
|
@current_selectedIndex = @form_field.selectedIndex
|
368
387
|
|
369
388
|
evt.preventDefault()
|
@@ -391,7 +410,7 @@ class Chosen extends AbstractChosen
|
|
391
410
|
this.result_clear_highlight()
|
392
411
|
this.winnow_results() if @results_showing
|
393
412
|
|
394
|
-
|
413
|
+
this.trigger_form_field_change deselected: @form_field.options[result_data.options_index].value
|
395
414
|
this.search_field_scale()
|
396
415
|
|
397
416
|
return true
|
@@ -403,8 +422,14 @@ class Chosen extends AbstractChosen
|
|
403
422
|
@selected_item.find("span").first().after "<abbr class=\"search-choice-close\"></abbr>" unless @selected_item.find("abbr").length
|
404
423
|
@selected_item.addClass("chosen-single-with-deselect")
|
405
424
|
|
425
|
+
get_search_field_value: ->
|
426
|
+
@search_field.val()
|
427
|
+
|
406
428
|
get_search_text: ->
|
407
|
-
|
429
|
+
$.trim this.get_search_field_value()
|
430
|
+
|
431
|
+
escape_html: (text) ->
|
432
|
+
$('<div/>').text(text).html()
|
408
433
|
|
409
434
|
winnow_results_set_highlight: ->
|
410
435
|
selected_results = if not @is_multiple then @search_results.find(".result-selected.active-result") else []
|
@@ -413,9 +438,7 @@ class Chosen extends AbstractChosen
|
|
413
438
|
this.result_do_highlight do_high if do_high?
|
414
439
|
|
415
440
|
no_results: (terms) ->
|
416
|
-
no_results_html =
|
417
|
-
no_results_html.find("span").first().html(terms)
|
418
|
-
|
441
|
+
no_results_html = this.get_no_results_html(terms)
|
419
442
|
@search_results.append no_results_html
|
420
443
|
@form_field_jq.trigger("chosen:no_results", {chosen:this})
|
421
444
|
|
@@ -458,56 +481,33 @@ class Chosen extends AbstractChosen
|
|
458
481
|
@pending_backstroke.removeClass "search-choice-focus" if @pending_backstroke
|
459
482
|
@pending_backstroke = null
|
460
483
|
|
461
|
-
keydown_checker: (evt) ->
|
462
|
-
stroke = evt.which ? evt.keyCode
|
463
|
-
this.search_field_scale()
|
464
|
-
|
465
|
-
this.clear_backstroke() if stroke != 8 and this.pending_backstroke
|
466
|
-
|
467
|
-
switch stroke
|
468
|
-
when 8
|
469
|
-
@backstroke_length = this.search_field.val().length
|
470
|
-
break
|
471
|
-
when 9
|
472
|
-
this.result_select(evt) if this.results_showing and not @is_multiple
|
473
|
-
@mouse_on_container = false
|
474
|
-
break
|
475
|
-
when 13
|
476
|
-
evt.preventDefault() if this.results_showing
|
477
|
-
break
|
478
|
-
when 32
|
479
|
-
evt.preventDefault() if @disable_search
|
480
|
-
break
|
481
|
-
when 38
|
482
|
-
evt.preventDefault()
|
483
|
-
this.keyup_arrow()
|
484
|
-
break
|
485
|
-
when 40
|
486
|
-
evt.preventDefault()
|
487
|
-
this.keydown_arrow()
|
488
|
-
break
|
489
|
-
|
490
484
|
search_field_scale: ->
|
491
|
-
|
492
|
-
|
493
|
-
|
485
|
+
return unless @is_multiple
|
486
|
+
|
487
|
+
style_block =
|
488
|
+
position: 'absolute'
|
489
|
+
left: '-1000px'
|
490
|
+
top: '-1000px'
|
491
|
+
display: 'none'
|
492
|
+
whiteSpace: 'pre'
|
494
493
|
|
495
|
-
|
496
|
-
styles = ['font-size','font-style', 'font-weight', 'font-family','line-height', 'text-transform', 'letter-spacing']
|
494
|
+
styles = ['fontSize', 'fontStyle', 'fontWeight', 'fontFamily', 'lineHeight', 'textTransform', 'letterSpacing']
|
497
495
|
|
498
|
-
|
499
|
-
|
496
|
+
for style in styles
|
497
|
+
style_block[style] = @search_field.css(style)
|
500
498
|
|
501
|
-
|
502
|
-
|
503
|
-
|
499
|
+
div = $('<div />').css(style_block)
|
500
|
+
div.text this.get_search_field_value()
|
501
|
+
$('body').append div
|
504
502
|
|
505
|
-
|
506
|
-
|
503
|
+
width = div.width() + 25
|
504
|
+
div.remove()
|
507
505
|
|
508
|
-
|
506
|
+
if @container.is(':visible')
|
507
|
+
width = Math.min(@container.outerWidth() - 10, width)
|
509
508
|
|
510
|
-
|
511
|
-
w = f_width - 10
|
509
|
+
@search_field.width(width)
|
512
510
|
|
513
|
-
|
511
|
+
trigger_form_field_change: (extra) ->
|
512
|
+
@form_field_jq.trigger "input", extra
|
513
|
+
@form_field_jq.trigger "change", extra
|