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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 53ab8c7f957d30317d0e6081b2c1e2e7fd67846a
4
- data.tar.gz: dc31f364d75238af5225017fb87bf85d91273930
2
+ SHA256:
3
+ metadata.gz: cb9a01d9e95e9334d789999deed11a5f4eeff7f7bf4aded85153ccb90e2cdb60
4
+ data.tar.gz: e0598c9ee4777bffaee6f134fe1f8d0b01d9bfc2d5e93291f24246d94a7ecabe
5
5
  SHA512:
6
- metadata.gz: 6dee8a53fa50bba34f37ff6888aa8680854d826e1c63623fdf7d2d2d7becab356460d35912194ac5f4db9377b9d65dc1eb56a01a715b36223b93cbb85e6be418
7
- data.tar.gz: f950fbcf9c474463b712defbd0c28319bc24634631f5cd4612b414d53e6b4371a14347366d21d5dc8f523869154cfaf9457f4be6e5aa2181b0f334ce038ea5a6
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` with the Rails asset pipeline.
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 Gemefile
11
+ Include `chosen-rails` in Gemfile
12
12
 
13
13
  ```rb
14
- gem 'compass-rails'
14
+ gem 'jquery-rails'
15
15
  gem 'chosen-rails'
16
16
  ```
17
17
 
18
18
  Then run `bundle install`
19
19
 
20
- You need to add `compass-rails` manually since it is not a dependency from version 1.5.1.
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 'sass-rails', '>= 3.2'
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'
@@ -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'
@@ -1,6 +1,6 @@
1
1
  module Chosen
2
2
  module Rails
3
- VERSION = '1.5.2'
4
- CHOSEN_VERSION = '1.5.1'
3
+ VERSION = '1.10.0'
4
+ CHOSEN_VERSION = '1.8.7'
5
5
  end
6
6
  end
data/lib/chosen-rails.rb CHANGED
@@ -6,7 +6,7 @@ module Chosen
6
6
  end
7
7
 
8
8
  case ::Rails.version.to_s
9
- when /^(4|5)/
9
+ when /^(4|5|6|7)/
10
10
  require 'chosen-rails/engine'
11
11
  when /^3\.[12]/
12
12
  require 'chosen-rails/engine3'
@@ -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 '<ul class="chosen-choices"><li class="search-field"><input type="text" value="' + @default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chosen-drop"><ul class="chosen-results"></ul></div>'
46
+ @container.html this.get_multi_html()
46
47
  else
47
- @container.html '<a class="chosen-single chosen-default"><span>' + @default_text + '</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off" /></div><ul class="chosen-results"></ul></div>'
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.bind 'touchstart.chosen', (evt) => this.container_mousedown(evt); evt.preventDefault()
74
- @container.bind 'touchend.chosen', (evt) => this.container_mouseup(evt); evt.preventDefault()
75
-
76
- @container.bind 'mousedown.chosen', (evt) => this.container_mousedown(evt); return
77
- @container.bind 'mouseup.chosen', (evt) => this.container_mouseup(evt); return
78
- @container.bind 'mouseenter.chosen', (evt) => this.mouse_enter(evt); return
79
- @container.bind 'mouseleave.chosen', (evt) => this.mouse_leave(evt); return
80
-
81
- @search_results.bind 'mouseup.chosen', (evt) => this.search_results_mouseup(evt); return
82
- @search_results.bind 'mouseover.chosen', (evt) => this.search_results_mouseover(evt); return
83
- @search_results.bind 'mouseout.chosen', (evt) => this.search_results_mouseout(evt); return
84
- @search_results.bind 'mousewheel.chosen DOMMouseScroll.chosen', (evt) => this.search_results_mousewheel(evt); return
85
-
86
- @search_results.bind 'touchstart.chosen', (evt) => this.search_results_touchstart(evt); return
87
- @search_results.bind 'touchmove.chosen', (evt) => this.search_results_touchmove(evt); return
88
- @search_results.bind 'touchend.chosen', (evt) => this.search_results_touchend(evt); return
89
-
90
- @form_field_jq.bind "chosen:updated.chosen", (evt) => this.results_update_field(evt); return
91
- @form_field_jq.bind "chosen:activate.chosen", (evt) => this.activate_field(evt); return
92
- @form_field_jq.bind "chosen:open.chosen", (evt) => this.container_mousedown(evt); return
93
- @form_field_jq.bind "chosen:close.chosen", (evt) => this.input_blur(evt); return
94
-
95
- @search_field.bind 'blur.chosen', (evt) => this.input_blur(evt); return
96
- @search_field.bind 'keyup.chosen', (evt) => this.keyup_checker(evt); return
97
- @search_field.bind 'keydown.chosen', (evt) => this.keydown_checker(evt); return
98
- @search_field.bind 'focus.chosen', (evt) => this.input_focus(evt); return
99
- @search_field.bind 'cut.chosen', (evt) => this.clipboard_event_checker(evt); return
100
- @search_field.bind 'paste.chosen', (evt) => this.clipboard_event_checker(evt); return
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.bind 'click.chosen', (evt) => this.choices_click(evt); return
104
+ @search_choices.on 'click.chosen', (evt) => this.choices_click(evt); return
104
105
  else
105
- @container.bind 'click.chosen', (evt) -> evt.preventDefault(); return # gobble click of anchor
106
+ @container.on 'click.chosen', (evt) -> evt.preventDefault(); return # gobble click of anchor
106
107
 
107
108
  destroy: ->
108
- $(@container[0].ownerDocument).unbind "click.chosen", @click_test_action
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[0].disabled
118
- if(@is_disabled)
119
- @container.addClass 'chosen-disabled'
120
- @search_field[0].disabled = true
121
- @selected_item.unbind "focus.chosen", @activate_action if !@is_multiple
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
- @container.removeClass 'chosen-disabled'
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 !@is_disabled
130
- if evt and evt.type is "mousedown" and not @results_showing
131
- evt.preventDefault()
134
+ return if @is_disabled
132
135
 
133
- if not (evt? and ($ evt.target).hasClass "search-choice-close")
134
- if not @active_field
135
- @search_field.val "" if @is_multiple
136
- $(@container[0].ownerDocument).bind 'click.chosen', @click_test_action
137
- this.results_show()
138
- else if not @is_multiple and evt and (($(evt.target)[0] == @selected_item[0]) || $(evt.target).parents("a.chosen-single").length)
139
- evt.preventDefault()
140
- this.results_toggle()
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
- this.activate_field()
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).unbind "click.chosen", @click_test_action
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 if not @is_multiple
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 @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.bind 'click.chosen', (evt) => if @is_multiple then this.container_mousedown(evt) else this.activate_field()
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 "active-result" or $(evt.target).parents('.active-result').first()
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.bind 'click.chosen', (evt) => this.choice_destroy_link_click(evt)
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
- this.show_search_field_default()
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 @search_field.val().length < 1
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
- @form_field_jq.trigger "change"
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
- this.results_hide() unless (evt.metaKey or evt.ctrlKey) and @is_multiple
364
- this.show_search_field_default()
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
- @form_field_jq.trigger "change", {'selected': @form_field.options[item.options_index].value} if @is_multiple || @form_field.selectedIndex != @current_selectedIndex
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
- @form_field_jq.trigger "change", {deselected: @form_field.options[result_data.options_index].value}
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
- $('<div/>').text($.trim(@search_field.val())).html()
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 = $('<li class="no-results">' + @results_none_found + ' "<span></span>"</li>')
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
- if @is_multiple
492
- h = 0
493
- w = 0
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
- style_block = "position:absolute; left: -1000px; top: -1000px; display:none;"
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
- for style in styles
499
- style_block += style + ":" + @search_field.css(style) + ";"
496
+ for style in styles
497
+ style_block[style] = @search_field.css(style)
500
498
 
501
- div = $('<div />', { 'style' : style_block })
502
- div.text @search_field.val()
503
- $('body').append div
499
+ div = $('<div />').css(style_block)
500
+ div.text this.get_search_field_value()
501
+ $('body').append div
504
502
 
505
- w = div.width() + 25
506
- div.remove()
503
+ width = div.width() + 25
504
+ div.remove()
507
505
 
508
- f_width = @container.outerWidth()
506
+ if @container.is(':visible')
507
+ width = Math.min(@container.outerWidth() - 10, width)
509
508
 
510
- if( w > f_width - 10 )
511
- w = f_width - 10
509
+ @search_field.width(width)
512
510
 
513
- @search_field.css({'width': w + 'px'})
511
+ trigger_form_field_change: (extra) ->
512
+ @form_field_jq.trigger "input", extra
513
+ @form_field_jq.trigger "change", extra