chosen-rails 0.9.9 → 0.9.10

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.9"
4
- CHOSEN_VERSION = "0.9.9"
3
+ VERSION = "0.9.10"
4
+ CHOSEN_VERSION = "0.9.10"
5
5
  end
6
6
  end
@@ -32,11 +32,13 @@ class Chosen extends AbstractChosen
32
32
 
33
33
  @f_width = @form_field_jq.outerWidth()
34
34
 
35
- container_div = ($ "<div />", {
35
+ container_props =
36
36
  id: @container_id
37
37
  class: "chzn-container#{ if @is_rtl then ' chzn-rtl' else '' }"
38
38
  style: 'width: ' + (@f_width) + 'px;' #use parens around @f_width so coffeescript doesn't think + ' px' is a function parameter
39
- })
39
+ title: @form_field.title
40
+
41
+ container_div = ($ "<div />", container_props)
40
42
 
41
43
  if @is_multiple
42
44
  container_div.html '<ul class="chzn-choices"><li class="search-field"><input type="text" value="' + @default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>'
@@ -95,7 +97,7 @@ class Chosen extends AbstractChosen
95
97
  @search_choices.click (evt) => this.choices_click(evt)
96
98
  else
97
99
  @container.click (evt) => evt.preventDefault() # gobble click of anchor
98
-
100
+
99
101
 
100
102
  search_field_disabled: ->
101
103
  @is_disabled = @form_field_jq[0].disabled
@@ -113,7 +115,7 @@ class Chosen extends AbstractChosen
113
115
  if !@is_disabled
114
116
  target_closelink = if evt? then ($ evt.target).hasClass "search-choice-close" else false
115
117
  if evt and evt.type is "mousedown" and not @results_showing
116
- evt.stopPropagation()
118
+ evt.preventDefault()
117
119
  if not @pending_destroy_click and not target_closelink
118
120
  if not @active_field
119
121
  @search_field.val "" if @is_multiple
@@ -316,6 +318,8 @@ class Chosen extends AbstractChosen
316
318
 
317
319
  link.parents('li').first().remove()
318
320
 
321
+ this.search_field_scale()
322
+
319
323
  results_reset: ->
320
324
  @form_field.options[0].selected = true
321
325
  @selected_item.find("span").text @default_text
@@ -324,7 +328,7 @@ class Chosen extends AbstractChosen
324
328
  this.results_reset_cleanup()
325
329
  @form_field_jq.trigger "change"
326
330
  this.results_hide() if @active_field
327
-
331
+
328
332
  results_reset_cleanup: ->
329
333
  @current_value = @form_field_jq.val()
330
334
  @selected_item.find("abbr").remove()
@@ -357,7 +361,7 @@ class Chosen extends AbstractChosen
357
361
  @selected_item.find("span").first().text item.text
358
362
  this.single_deselect_control_build() if @allow_single_deselect
359
363
 
360
- this.results_hide() unless evt.metaKey and @is_multiple
364
+ this.results_hide() unless (evt.metaKey or evt.ctrlKey) and @is_multiple
361
365
 
362
366
  @search_field.val ""
363
367
 
@@ -376,7 +380,7 @@ class Chosen extends AbstractChosen
376
380
 
377
381
  if not @form_field.options[result_data.options_index].disabled
378
382
  result_data.selected = false
379
-
383
+
380
384
  @form_field.options[result_data.options_index].selected = false
381
385
  result = $("#" + @container_id + "_o_" + pos)
382
386
  result.removeClass("result-selected").addClass("active-result").show()
@@ -386,7 +390,7 @@ class Chosen extends AbstractChosen
386
390
 
387
391
  @form_field_jq.trigger "change", {deselected: @form_field.options[result_data.options_index].value}
388
392
  this.search_field_scale()
389
-
393
+
390
394
  return true
391
395
  else
392
396
  return false
@@ -416,7 +420,7 @@ class Chosen extends AbstractChosen
416
420
  if regex.test option.html
417
421
  found = true
418
422
  results += 1
419
- else if option.html.indexOf(" ") >= 0 or option.html.indexOf("[") == 0
423
+ else if @search_split_words and (option.html.indexOf(" ") >= 0 or option.html.indexOf("[") == 0)
420
424
  #TODO: replace this substitution of /\[\]/ with a list of characters to skip.
421
425
  parts = option.html.replace(/\[|\]/g, "").split(" ")
422
426
  if parts.length
@@ -569,6 +573,8 @@ class Chosen extends AbstractChosen
569
573
  string += this.generate_random_char()
570
574
  string
571
575
 
576
+ root.Chosen = Chosen
577
+
572
578
  get_side_border_padding = (elmt) ->
573
579
  side_border_padding = elmt.outerWidth() - elmt.width()
574
580
 
@@ -15,7 +15,7 @@ class Chosen extends AbstractChosen
15
15
 
16
16
  set_default_values: ->
17
17
  super()
18
-
18
+
19
19
  # HTML Templates
20
20
  @single_temp = new Template('<a href="javascript:void(0)" class="chzn-single chzn-default" tabindex="-1"><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>')
@@ -25,13 +25,14 @@ class Chosen extends AbstractChosen
25
25
 
26
26
  set_up_html: ->
27
27
  @container_id = @form_field.identify().replace(/[^\w]/g, '_') + "_chzn"
28
-
28
+
29
29
  @f_width = if @form_field.getStyle("width") then parseInt @form_field.getStyle("width"), 10 else @form_field.getWidth()
30
-
30
+
31
31
  container_props =
32
32
  'id': @container_id
33
33
  'class': "chzn-container#{ if @is_rtl then ' chzn-rtl' else '' }"
34
34
  'style': 'width: ' + (@f_width) + 'px' #use parens around @f_width so coffeescript doesn't think + ' px' is a function parameter
35
+ 'title': @form_field.title
35
36
 
36
37
  base_template = if @is_multiple then new Element('div', container_props).update( @multi_temp.evaluate({ "default": @default_text}) ) else new Element('div', container_props).update( @single_temp.evaluate({ "default":@default_text }) )
37
38
 
@@ -39,10 +40,10 @@ class Chosen extends AbstractChosen
39
40
  @container = $(@container_id)
40
41
  @container.addClassName( "chzn-container-" + (if @is_multiple then "multi" else "single") )
41
42
  @dropdown = @container.down('div.chzn-drop')
42
-
43
+
43
44
  dd_top = @container.getHeight()
44
45
  dd_width = (@f_width - get_side_border_padding(@dropdown))
45
-
46
+
46
47
  @dropdown.setStyle({"width": dd_width + "px", "top": dd_top + "px"})
47
48
 
48
49
  @search_field = @container.down('input')
@@ -50,7 +51,7 @@ class Chosen extends AbstractChosen
50
51
  this.search_field_scale()
51
52
 
52
53
  @search_no_results = @container.down('li.no-results')
53
-
54
+
54
55
  if @is_multiple
55
56
  @search_choices = @container.down('ul.chzn-choices')
56
57
  @search_container = @container.down('li.search-field')
@@ -59,7 +60,7 @@ class Chosen extends AbstractChosen
59
60
  @selected_item = @container.down('.chzn-single')
60
61
  sf_width = dd_width - get_side_border_padding(@search_container) - get_side_border_padding(@search_field)
61
62
  @search_field.setStyle( {"width" : sf_width + "px"} )
62
-
63
+
63
64
  this.results_build()
64
65
  this.set_tab_index()
65
66
  @form_field.fire("liszt:ready", {chosen: this})
@@ -69,11 +70,11 @@ class Chosen extends AbstractChosen
69
70
  @container.observe "mouseup", (evt) => this.container_mouseup(evt)
70
71
  @container.observe "mouseenter", (evt) => this.mouse_enter(evt)
71
72
  @container.observe "mouseleave", (evt) => this.mouse_leave(evt)
72
-
73
+
73
74
  @search_results.observe "mouseup", (evt) => this.search_results_mouseup(evt)
74
75
  @search_results.observe "mouseover", (evt) => this.search_results_mouseover(evt)
75
76
  @search_results.observe "mouseout", (evt) => this.search_results_mouseout(evt)
76
-
77
+
77
78
  @form_field.observe "liszt:updated", (evt) => this.results_update_field(evt)
78
79
  @form_field.observe "liszt:activate", (evt) => this.activate_field(evt)
79
80
  @form_field.observe "liszt:open", (evt) => this.container_mousedown(evt)
@@ -116,7 +117,7 @@ class Chosen extends AbstractChosen
116
117
  this.activate_field()
117
118
  else
118
119
  @pending_destroy_click = false
119
-
120
+
120
121
  container_mouseup: (evt) ->
121
122
  this.results_reset(evt) if evt.target.nodeName is "ABBR" and not @is_disabled
122
123
 
@@ -125,7 +126,7 @@ class Chosen extends AbstractChosen
125
126
 
126
127
  close_field: ->
127
128
  document.stopObserving "click", @click_test_action
128
-
129
+
129
130
  @active_field = false
130
131
  this.results_hide()
131
132
 
@@ -178,7 +179,7 @@ class Chosen extends AbstractChosen
178
179
  this.search_field_disabled()
179
180
  this.show_search_field_default()
180
181
  this.search_field_scale()
181
-
182
+
182
183
  @search_results.update content
183
184
  @parsing = false
184
185
 
@@ -189,7 +190,7 @@ class Chosen extends AbstractChosen
189
190
  '<li id="' + group.dom_id + '" class="group-result">' + group.label.escapeHTML() + '</li>'
190
191
  else
191
192
  ""
192
-
193
+
193
194
  result_do_highlight: (el) ->
194
195
  this.result_clear_highlight()
195
196
 
@@ -207,7 +208,7 @@ class Chosen extends AbstractChosen
207
208
  @search_results.scrollTop = if (high_bottom - maxHeight) > 0 then (high_bottom - maxHeight) else 0
208
209
  else if high_top < visible_top
209
210
  @search_results.scrollTop = high_top
210
-
211
+
211
212
  result_clear_highlight: ->
212
213
  @result_highlight.removeClassName('highlighted') if @result_highlight
213
214
  @result_highlight = null
@@ -303,6 +304,8 @@ class Chosen extends AbstractChosen
303
304
 
304
305
  link.up('li').remove()
305
306
 
307
+ this.search_field_scale()
308
+
306
309
  results_reset: ->
307
310
  @form_field.options[0].selected = true
308
311
  @selected_item.down("span").update(@default_text)
@@ -316,7 +319,7 @@ class Chosen extends AbstractChosen
316
319
  @current_value = @form_field.value
317
320
  deselect_trigger = @selected_item.down("abbr")
318
321
  deselect_trigger.remove() if(deselect_trigger)
319
-
322
+
320
323
  result_select: (evt) ->
321
324
  if @result_highlight
322
325
  high = @result_highlight
@@ -328,9 +331,9 @@ class Chosen extends AbstractChosen
328
331
  @search_results.descendants(".result-selected").invoke "removeClassName", "result-selected"
329
332
  @selected_item.removeClassName("chzn-default")
330
333
  @result_single_selected = high
331
-
334
+
332
335
  high.addClassName("result-selected")
333
-
336
+
334
337
  position = high.id.substr(high.id.lastIndexOf("_") + 1 )
335
338
  item = @results_data[position]
336
339
  item.selected = true
@@ -343,13 +346,13 @@ class Chosen extends AbstractChosen
343
346
  @selected_item.down("span").update(item.html)
344
347
  this.single_deselect_control_build() if @allow_single_deselect
345
348
 
346
- this.results_hide() unless evt.metaKey and @is_multiple
349
+ this.results_hide() unless (evt.metaKey or evt.ctrlKey) and @is_multiple
347
350
 
348
351
  @search_field.value = ""
349
-
352
+
350
353
  @form_field.simulate("change") if typeof Event.simulate is 'function' && (@is_multiple || @form_field.value != @current_value)
351
354
  @current_value = @form_field.value
352
-
355
+
353
356
  this.search_field_scale()
354
357
 
355
358
  result_activate: (el) ->
@@ -360,7 +363,7 @@ class Chosen extends AbstractChosen
360
363
 
361
364
  result_deselect: (pos) ->
362
365
  result_data = @results_data[pos]
363
-
366
+
364
367
  if not @form_field.options[result_data.options_index].disabled
365
368
  result_data.selected = false
366
369
 
@@ -376,7 +379,7 @@ class Chosen extends AbstractChosen
376
379
  return true
377
380
  else
378
381
  return false
379
-
382
+
380
383
  single_deselect_control_build: ->
381
384
  @selected_item.down("span").insert { after: "<abbr class=\"search-choice-close\"></abbr>" } if @allow_single_deselect and not @selected_item.down("abbr")
382
385
 
@@ -397,11 +400,11 @@ class Chosen extends AbstractChosen
397
400
  else if not (@is_multiple and option.selected)
398
401
  found = false
399
402
  result_id = option.dom_id
400
-
403
+
401
404
  if regex.test option.html
402
405
  found = true
403
406
  results += 1
404
- else if option.html.indexOf(" ") >= 0 or option.html.indexOf("[") == 0
407
+ else if @search_split_words and (option.html.indexOf(" ") >= 0 or option.html.indexOf("[") == 0)
405
408
  #TODO: replace this substitution of /\[\]/ with a list of characters to skip.
406
409
  parts = option.html.replace(/\[|\]/g, "").split(" ")
407
410
  if parts.length
@@ -452,10 +455,10 @@ class Chosen extends AbstractChosen
452
455
  do_high = @search_results.down(".active-result")
453
456
 
454
457
  this.result_do_highlight do_high if do_high?
455
-
458
+
456
459
  no_results: (terms) ->
457
460
  @search_results.insert @no_results_temp.evaluate( terms: terms )
458
-
461
+
459
462
  no_results_clear: ->
460
463
  nr = null
461
464
  nr.remove() while nr = @search_results.down(".no-results")
@@ -509,7 +512,7 @@ class Chosen extends AbstractChosen
509
512
  this.search_field_scale()
510
513
 
511
514
  this.clear_backstroke() if stroke != 8 and this.pending_backstroke
512
-
515
+
513
516
  switch stroke
514
517
  when 8
515
518
  @backstroke_length = this.search_field.value.length
@@ -536,10 +539,10 @@ class Chosen extends AbstractChosen
536
539
 
537
540
  style_block = "position:absolute; left: -1000px; top: -1000px; display:none;"
538
541
  styles = ['font-size','font-style', 'font-weight', 'font-family','line-height', 'text-transform', 'letter-spacing']
539
-
542
+
540
543
  for style in styles
541
544
  style_block += style + ":" + @search_field.getStyle(style) + ";"
542
-
545
+
543
546
  div = new Element('div', { 'style' : style_block }).update(@search_field.value.escapeHTML())
544
547
  document.body.appendChild(div)
545
548
 
@@ -557,7 +560,7 @@ class Chosen extends AbstractChosen
557
560
  root.Chosen = Chosen
558
561
 
559
562
  # Prototype does not support version numbers so we add it ourselves
560
- if Prototype.Browser.IE
563
+ if Prototype.Browser.IE
561
564
  if /MSIE (\d+\.\d+);/.test(navigator.userAgent)
562
565
  Prototype.BrowserFeatures['Version'] = new Number(RegExp.$1);
563
566
 
@@ -29,6 +29,7 @@ class AbstractChosen
29
29
  @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
30
30
  @disable_search_threshold = @options.disable_search_threshold || 0
31
31
  @disable_search = @options.disable_search || false
32
+ @search_split_words = not (@options.disable_search_split_words || false)
32
33
  @search_contains = @options.search_contains || false
33
34
  @choices = 0
34
35
  @single_backstroke_delete = @options.single_backstroke_delete || false
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.9
4
+ version: 0.9.10
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-11-29 00:00:00.000000000 Z
12
+ date: 2012-12-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties