chosen-rails 0.9.8.2 → 0.9.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  module Chosen
2
2
  module Rails
3
- VERSION = "0.9.8.2"
4
- EDITOR_VERSION = "0.9.8"
3
+ VERSION = "0.9.8.3"
4
+ CHOSEN_VERSION = "0.9.8"
5
5
  end
6
6
  end
@@ -8,7 +8,8 @@ $ = jQuery
8
8
  $.fn.extend({
9
9
  chosen: (options) ->
10
10
  # Do no harm and return as soon as possible for unsupported browsers, namely IE6 and IE7
11
- return this if $.browser.msie and ($.browser.version is "6.0" or $.browser.version is "7.0")
11
+ # Continue on if running IE document type but in compatibility mode
12
+ return this if $.browser.msie and ($.browser.version is "6.0" or ($.browser.version is "7.0" and document.documentMode is 7 ))
12
13
  this.each((input_field) ->
13
14
  $this = $ this
14
15
  $this.data('chosen', new Chosen(this, options)) unless $this.hasClass "chzn-done"
@@ -82,6 +83,8 @@ class Chosen extends AbstractChosen
82
83
  @search_results.mouseout (evt) => this.search_results_mouseout(evt)
83
84
 
84
85
  @form_field_jq.bind "liszt:updated", (evt) => this.results_update_field(evt)
86
+ @form_field_jq.bind "liszt:activate", (evt) => this.activate_field(evt)
87
+ @form_field_jq.bind "liszt:open", (evt) => this.container_mousedown(evt)
85
88
 
86
89
  @search_field.blur (evt) => this.input_blur(evt)
87
90
  @search_field.keyup (evt) => this.keyup_checker(evt)
@@ -173,7 +176,7 @@ class Chosen extends AbstractChosen
173
176
  @choices = 0
174
177
  else if not @is_multiple
175
178
  @selected_item.addClass("chzn-default").find("span").text(@default_text)
176
- if @form_field.options.length <= @disable_search_threshold
179
+ if @disable_search or @form_field.options.length <= @disable_search_threshold
177
180
  @container.addClass "chzn-container-single-nosearch"
178
181
  else
179
182
  @container.removeClass "chzn-container-single-nosearch"
@@ -299,7 +302,11 @@ class Chosen extends AbstractChosen
299
302
  return false # fire event
300
303
  choice_id = @container_id + "_c_" + item.array_index
301
304
  @choices += 1
302
- @search_container.before '<li class="search-choice" id="' + choice_id + '"><span>' + item.html + '</span><a href="javascript:void(0)" class="search-choice-close" rel="' + item.array_index + '"></a></li>'
305
+ if item.disabled
306
+ html = '<li class="search-choice search-choice-disabled" id="' + choice_id + '"><span>' + item.html + '</span></li>'
307
+ else
308
+ html = '<li class="search-choice" id="' + choice_id + '"><span>' + item.html + '</span><a href="javascript:void(0)" class="search-choice-close" rel="' + item.array_index + '"></a></li>'
309
+ @search_container.before html
303
310
  link = $('#' + choice_id).find("a").first()
304
311
  link.click (evt) => this.choice_destroy_link_click(evt)
305
312
 
@@ -312,13 +319,13 @@ class Chosen extends AbstractChosen
312
319
  evt.stopPropagation
313
320
 
314
321
  choice_destroy: (link) ->
315
- @choices -= 1
316
- this.show_search_field_default()
322
+ if this.result_deselect (link.attr "rel")
323
+ @choices -= 1
324
+ this.show_search_field_default()
317
325
 
318
- this.results_hide() if @is_multiple and @choices > 0 and @search_field.val().length < 1
326
+ this.results_hide() if @is_multiple and @choices > 0 and @search_field.val().length < 1
319
327
 
320
- this.result_deselect (link.attr "rel")
321
- link.parents('li').first().remove()
328
+ link.parents('li').first().remove()
322
329
 
323
330
  results_reset: ->
324
331
  @form_field.options[0].selected = true
@@ -330,6 +337,7 @@ class Chosen extends AbstractChosen
330
337
  this.results_hide() if @active_field
331
338
 
332
339
  results_reset_cleanup: ->
340
+ @current_value = @form_field_jq.val()
333
341
  @selected_item.find("abbr").remove()
334
342
 
335
343
  result_select: (evt) ->
@@ -376,17 +384,23 @@ class Chosen extends AbstractChosen
376
384
 
377
385
  result_deselect: (pos) ->
378
386
  result_data = @results_data[pos]
379
- result_data.selected = false
380
387
 
381
- @form_field.options[result_data.options_index].selected = false
382
- result = $("#" + @container_id + "_o_" + pos)
383
- result.removeClass("result-selected").addClass("active-result").show()
388
+ if not @form_field.options[result_data.options_index].disabled
389
+ result_data.selected = false
390
+
391
+ @form_field.options[result_data.options_index].selected = false
392
+ result = $("#" + @container_id + "_o_" + pos)
393
+ result.removeClass("result-selected").addClass("active-result").show()
384
394
 
385
- this.result_clear_highlight()
386
- this.winnow_results()
395
+ this.result_clear_highlight()
396
+ this.winnow_results()
387
397
 
388
- @form_field_jq.trigger "change", {deselected: @form_field.options[result_data.options_index].value}
389
- this.search_field_scale()
398
+ @form_field_jq.trigger "change", {deselected: @form_field.options[result_data.options_index].value}
399
+ this.search_field_scale()
400
+
401
+ return true
402
+ else
403
+ return false
390
404
 
391
405
  single_deselect_control_build: ->
392
406
  @selected_item.find("span").first().after "<abbr class=\"search-choice-close\"></abbr>" if @allow_single_deselect and @selected_item.find("abbr").length < 1
@@ -497,11 +511,13 @@ class Chosen extends AbstractChosen
497
511
  this.choice_destroy @pending_backstroke.find("a").first()
498
512
  this.clear_backstroke()
499
513
  else
500
- @pending_backstroke = @search_container.siblings("li.search-choice").last()
501
- if @single_backstroke_delete
502
- @keydown_backstroke()
503
- else
504
- @pending_backstroke.addClass "search-choice-focus"
514
+ next_available_destroy = @search_container.siblings("li.search-choice").last()
515
+ if next_available_destroy.length and not next_available_destroy.hasClass("search-choice-disabled")
516
+ @pending_backstroke = next_available_destroy
517
+ if @single_backstroke_delete
518
+ @keydown_backstroke()
519
+ else
520
+ @pending_backstroke.addClass "search-choice-focus"
505
521
 
506
522
  clear_backstroke: ->
507
523
  @pending_backstroke.removeClass "search-choice-focus" if @pending_backstroke
@@ -20,6 +20,7 @@ class Chosen extends AbstractChosen
20
20
  @single_temp = new Template('<a href="javascript:void(0)" class="chzn-single chzn-default"><span>#{default}</span><div><b></b></div></a><div class="chzn-drop" style="left:-9000px;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>')
21
21
  @multi_temp = new Template('<ul class="chzn-choices"><li class="search-field"><input type="text" value="#{default}" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>')
22
22
  @choice_temp = new Template('<li class="search-choice" id="#{id}"><span>#{choice}</span><a href="javascript:void(0)" class="search-choice-close" rel="#{position}"></a></li>')
23
+ @choice_noclose_temp = new Template('<li class="search-choice search-choice-disabled" id="#{id}"><span>#{choice}</span></li>')
23
24
  @no_results_temp = new Template('<li class="no-results">' + @results_none_found + ' "<span>#{terms}</span>"</li>')
24
25
 
25
26
  set_up_html: ->
@@ -74,6 +75,8 @@ class Chosen extends AbstractChosen
74
75
  @search_results.observe "mouseout", (evt) => this.search_results_mouseout(evt)
75
76
 
76
77
  @form_field.observe "liszt:updated", (evt) => this.results_update_field(evt)
78
+ @form_field.observe "liszt:activate", (evt) => this.activate_field(evt)
79
+ @form_field.observe "liszt:open", (evt) => this.container_mousedown(evt)
77
80
 
78
81
  @search_field.observe "blur", (evt) => this.input_blur(evt)
79
82
  @search_field.observe "keyup", (evt) => this.keyup_checker(evt)
@@ -164,7 +167,7 @@ class Chosen extends AbstractChosen
164
167
  @choices = 0
165
168
  else if not @is_multiple
166
169
  @selected_item.addClassName("chzn-default").down("span").update(@default_text)
167
- if @form_field.options.length <= @disable_search_threshold
170
+ if @disable_search or @form_field.options.length <= @disable_search_threshold
168
171
  @container.addClassName "chzn-container-single-nosearch"
169
172
  else
170
173
  @container.removeClassName "chzn-container-single-nosearch"
@@ -290,12 +293,13 @@ class Chosen extends AbstractChosen
290
293
  choice_id = @container_id + "_c_" + item.array_index
291
294
  @choices += 1
292
295
  @search_container.insert
293
- before: @choice_temp.evaluate
296
+ before: (if item.disabled then @choice_noclose_temp else @choice_temp).evaluate
294
297
  id: choice_id
295
298
  choice: item.html
296
299
  position: item.array_index
297
- link = $(choice_id).down('a')
298
- link.observe "click", (evt) => this.choice_destroy_link_click(evt)
300
+ if not item.disabled
301
+ link = $(choice_id).down('a')
302
+ link.observe "click", (evt) => this.choice_destroy_link_click(evt)
299
303
 
300
304
  choice_destroy_link_click: (evt) ->
301
305
  evt.preventDefault()
@@ -304,13 +308,13 @@ class Chosen extends AbstractChosen
304
308
  this.choice_destroy evt.target
305
309
 
306
310
  choice_destroy: (link) ->
307
- @choices -= 1
308
- this.show_search_field_default()
311
+ if this.result_deselect link.readAttribute("rel")
312
+ @choices -= 1
313
+ this.show_search_field_default()
309
314
 
310
- this.results_hide() if @is_multiple and @choices > 0 and @search_field.value.length < 1
315
+ this.results_hide() if @is_multiple and @choices > 0 and @search_field.value.length < 1
311
316
 
312
- this.result_deselect link.readAttribute("rel")
313
- link.up('li').remove()
317
+ link.up('li').remove()
314
318
 
315
319
  results_reset: ->
316
320
  @form_field.options[0].selected = true
@@ -322,6 +326,7 @@ class Chosen extends AbstractChosen
322
326
  this.results_hide() if @active_field
323
327
 
324
328
  results_reset_cleanup: ->
329
+ @current_value = @form_field.value
325
330
  deselect_trigger = @selected_item.down("abbr")
326
331
  deselect_trigger.remove() if(deselect_trigger)
327
332
 
@@ -368,17 +373,22 @@ class Chosen extends AbstractChosen
368
373
 
369
374
  result_deselect: (pos) ->
370
375
  result_data = @results_data[pos]
371
- result_data.selected = false
376
+
377
+ if not @form_field.options[result_data.options_index].disabled
378
+ result_data.selected = false
372
379
 
373
- @form_field.options[result_data.options_index].selected = false
374
- result = $(@container_id + "_o_" + pos)
375
- result.removeClassName("result-selected").addClassName("active-result").show()
380
+ @form_field.options[result_data.options_index].selected = false
381
+ result = $(@container_id + "_o_" + pos)
382
+ result.removeClassName("result-selected").addClassName("active-result").show()
376
383
 
377
- this.result_clear_highlight()
378
- this.winnow_results()
384
+ this.result_clear_highlight()
385
+ this.winnow_results()
379
386
 
380
- @form_field.simulate("change") if typeof Event.simulate is 'function'
381
- this.search_field_scale()
387
+ @form_field.simulate("change") if typeof Event.simulate is 'function'
388
+ this.search_field_scale()
389
+ return true
390
+ else
391
+ return false
382
392
 
383
393
  single_deselect_control_build: ->
384
394
  @selected_item.down("span").insert { after: "<abbr class=\"search-choice-close\"></abbr>" } if @allow_single_deselect and not @selected_item.down("abbr")
@@ -494,11 +504,14 @@ class Chosen extends AbstractChosen
494
504
  this.choice_destroy @pending_backstroke.down("a")
495
505
  this.clear_backstroke()
496
506
  else
497
- @pending_backstroke = @search_container.siblings("li.search-choice").last()
498
- if @single_backstroke_delete
499
- @keydown_backstroke()
500
- else
501
- @pending_backstroke.addClassName("search-choice-focus")
507
+ next_available_destroy = @search_container.siblings().last()
508
+ if next_available_destroy and next_available_destroy.hasClassName("search-choice") and not next_available_destroy.hasClassName("search-choice-disabled")
509
+ @pending_backstroke = next_available_destroy
510
+ @pending_backstroke.addClassName("search-choice-focus") if @pending_backstroke
511
+ if @single_backstroke_delete
512
+ @keydown_backstroke()
513
+ else
514
+ @pending_backstroke.addClassName("search-choice-focus")
502
515
 
503
516
  clear_backstroke: ->
504
517
  @pending_backstroke.removeClassName("search-choice-focus") if @pending_backstroke
@@ -29,6 +29,7 @@ class AbstractChosen
29
29
  @result_single_selected = null
30
30
  @allow_single_deselect = if @options.allow_single_deselect? and @form_field.options[0]? and @form_field.options[0].text is "" then @options.allow_single_deselect else false
31
31
  @disable_search_threshold = @options.disable_search_threshold || 0
32
+ @disable_search = @options.disable_search || false
32
33
  @search_contains = @options.search_contains || false
33
34
  @choices = 0
34
35
  @single_backstroke_delete = @options.single_backstroke_delete || false
@@ -5,7 +5,7 @@ class SelectParser
5
5
  @parsed = []
6
6
 
7
7
  add_node: (child) ->
8
- if child.nodeName is "OPTGROUP"
8
+ if child.nodeName.toUpperCase() is "OPTGROUP"
9
9
  this.add_group child
10
10
  else
11
11
  this.add_option child
@@ -21,7 +21,7 @@ class SelectParser
21
21
  this.add_option( option, group_position, group.disabled ) for option in group.childNodes
22
22
 
23
23
  add_option: (option, group_position, group_disabled) ->
24
- if option.nodeName is "OPTION"
24
+ if option.nodeName.toUpperCase() is "OPTION"
25
25
  if option.text != ""
26
26
  if group_position?
27
27
  @parsed[group_position].children += 1
@@ -182,6 +182,18 @@
182
182
  margin: 3px 0 3px 5px
183
183
  position: relative
184
184
  cursor: default
185
+ &.search-choice-disabled
186
+ background-color: #e4e4e4
187
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#f4f4f4', endColorstr='#eeeeee', GradientType=0 )
188
+ background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, color-stop(20%, #f4f4f4), color-stop(50%, #f0f0f0), color-stop(52%, #e8e8e8), color-stop(100%, #eeeeee))
189
+ background-image: -webkit-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%)
190
+ background-image: -moz-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%)
191
+ background-image: -o-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%)
192
+ background-image: -ms-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%)
193
+ background-image: linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%)
194
+ color: #666
195
+ border: 1px solid #cccccc
196
+ padding-right: 5px
185
197
  .search-choice-focus
186
198
  background: #d4d4d4
187
199
  .search-choice .search-choice-close
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chosen-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8.2
4
+ version: 0.9.8.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-20 00:00:00.000000000 Z
12
+ date: 2012-09-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -130,18 +130,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
130
130
  - - ! '>='
131
131
  - !ruby/object:Gem::Version
132
132
  version: '0'
133
- segments:
134
- - 0
135
- hash: 1777641325023975397
136
133
  required_rubygems_version: !ruby/object:Gem::Requirement
137
134
  none: false
138
135
  requirements:
139
136
  - - ! '>='
140
137
  - !ruby/object:Gem::Version
141
138
  version: '0'
142
- segments:
143
- - 0
144
- hash: 1777641325023975397
145
139
  requirements: []
146
140
  rubyforge_project:
147
141
  rubygems_version: 1.8.24