chosen-rails 0.9.8 → 0.9.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/chosen-rails/version.rb +1 -1
- data/vendor/assets/javascripts/chosen.jquery.coffee +59 -44
- data/vendor/assets/javascripts/chosen.proto.coffee +26 -10
- data/vendor/assets/javascripts/lib/abstract-chosen.coffee +15 -3
- data/vendor/assets/stylesheets/chosen.css.sass +18 -15
- metadata +38 -13
data/README.md
CHANGED
data/lib/chosen-rails/version.rb
CHANGED
@@ -9,8 +9,9 @@ $.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
11
|
return this if $.browser.msie and ($.browser.version is "6.0" or $.browser.version is "7.0")
|
12
|
-
|
13
|
-
|
12
|
+
this.each((input_field) ->
|
13
|
+
$this = $ this
|
14
|
+
$this.data('chosen', new Chosen(this, options)) unless $this.hasClass "chzn-done"
|
14
15
|
)
|
15
16
|
})
|
16
17
|
|
@@ -18,25 +19,24 @@ class Chosen extends AbstractChosen
|
|
18
19
|
|
19
20
|
setup: ->
|
20
21
|
@form_field_jq = $ @form_field
|
22
|
+
@current_value = @form_field_jq.val()
|
21
23
|
@is_rtl = @form_field_jq.hasClass "chzn-rtl"
|
22
24
|
|
23
25
|
finish_setup: ->
|
24
26
|
@form_field_jq.addClass "chzn-done"
|
25
27
|
|
26
28
|
set_up_html: ->
|
27
|
-
@container_id = if @form_field.id.length then @form_field.id.replace(/
|
29
|
+
@container_id = if @form_field.id.length then @form_field.id.replace(/[^\w]/g, '_') else this.generate_field_id()
|
28
30
|
@container_id += "_chzn"
|
29
|
-
|
31
|
+
|
30
32
|
@f_width = @form_field_jq.outerWidth()
|
31
|
-
|
32
|
-
@default_text = if @form_field_jq.data 'placeholder' then @form_field_jq.data 'placeholder' else @default_text_default
|
33
|
-
|
33
|
+
|
34
34
|
container_div = ($ "<div />", {
|
35
35
|
id: @container_id
|
36
36
|
class: "chzn-container#{ if @is_rtl then ' chzn-rtl' else '' }"
|
37
37
|
style: 'width: ' + (@f_width) + 'px;' #use parens around @f_width so coffeescript doesn't think + ' px' is a function parameter
|
38
38
|
})
|
39
|
-
|
39
|
+
|
40
40
|
if @is_multiple
|
41
41
|
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>'
|
42
42
|
else
|
@@ -46,10 +46,10 @@ class Chosen extends AbstractChosen
|
|
46
46
|
@container = ($ '#' + @container_id)
|
47
47
|
@container.addClass( "chzn-container-" + (if @is_multiple then "multi" else "single") )
|
48
48
|
@dropdown = @container.find('div.chzn-drop').first()
|
49
|
-
|
49
|
+
|
50
50
|
dd_top = @container.height()
|
51
51
|
dd_width = (@f_width - get_side_border_padding(@dropdown))
|
52
|
-
|
52
|
+
|
53
53
|
@dropdown.css({"width": dd_width + "px", "top": dd_top + "px"})
|
54
54
|
|
55
55
|
@search_field = @container.find('input').first()
|
@@ -57,7 +57,7 @@ class Chosen extends AbstractChosen
|
|
57
57
|
this.search_field_scale()
|
58
58
|
|
59
59
|
@search_no_results = @container.find('li.no-results').first()
|
60
|
-
|
60
|
+
|
61
61
|
if @is_multiple
|
62
62
|
@search_choices = @container.find('ul.chzn-choices').first()
|
63
63
|
@search_container = @container.find('li.search-field').first()
|
@@ -66,7 +66,7 @@ class Chosen extends AbstractChosen
|
|
66
66
|
@selected_item = @container.find('.chzn-single').first()
|
67
67
|
sf_width = dd_width - get_side_border_padding(@search_container) - get_side_border_padding(@search_field)
|
68
68
|
@search_field.css( {"width" : sf_width + "px"} )
|
69
|
-
|
69
|
+
|
70
70
|
this.results_build()
|
71
71
|
this.set_tab_index()
|
72
72
|
@form_field_jq.trigger("liszt:ready", {chosen: this})
|
@@ -76,7 +76,7 @@ class Chosen extends AbstractChosen
|
|
76
76
|
@container.mouseup (evt) => this.container_mouseup(evt)
|
77
77
|
@container.mouseenter (evt) => this.mouse_enter(evt)
|
78
78
|
@container.mouseleave (evt) => this.mouse_leave(evt)
|
79
|
-
|
79
|
+
|
80
80
|
@search_results.mouseup (evt) => this.search_results_mouseup(evt)
|
81
81
|
@search_results.mouseover (evt) => this.search_results_mouseover(evt)
|
82
82
|
@search_results.mouseout (evt) => this.search_results_mouseout(evt)
|
@@ -124,18 +124,18 @@ class Chosen extends AbstractChosen
|
|
124
124
|
@pending_destroy_click = false
|
125
125
|
|
126
126
|
container_mouseup: (evt) ->
|
127
|
-
this.results_reset(evt) if evt.target.nodeName is "ABBR"
|
127
|
+
this.results_reset(evt) if evt.target.nodeName is "ABBR" and not @is_disabled
|
128
128
|
|
129
129
|
blur_test: (evt) ->
|
130
130
|
this.close_field() if not @active_field and @container.hasClass "chzn-container-active"
|
131
131
|
|
132
132
|
close_field: ->
|
133
133
|
$(document).unbind "click", @click_test_action
|
134
|
-
|
134
|
+
|
135
135
|
if not @is_multiple
|
136
136
|
@selected_item.attr "tabindex", @search_field.attr("tabindex")
|
137
137
|
@search_field.attr "tabindex", -1
|
138
|
-
|
138
|
+
|
139
139
|
@active_field = false
|
140
140
|
this.results_hide()
|
141
141
|
|
@@ -163,7 +163,7 @@ class Chosen extends AbstractChosen
|
|
163
163
|
@active_field = true
|
164
164
|
else
|
165
165
|
this.close_field()
|
166
|
-
|
166
|
+
|
167
167
|
results_build: ->
|
168
168
|
@parsing = true
|
169
169
|
@results_data = root.SelectParser.select_to_array @form_field
|
@@ -172,7 +172,7 @@ class Chosen extends AbstractChosen
|
|
172
172
|
@search_choices.find("li.search-choice").remove()
|
173
173
|
@choices = 0
|
174
174
|
else if not @is_multiple
|
175
|
-
@selected_item.find("span").text
|
175
|
+
@selected_item.addClass("chzn-default").find("span").text(@default_text)
|
176
176
|
if @form_field.options.length <= @disable_search_threshold
|
177
177
|
@container.addClass "chzn-container-single-nosearch"
|
178
178
|
else
|
@@ -193,7 +193,7 @@ class Chosen extends AbstractChosen
|
|
193
193
|
this.search_field_disabled()
|
194
194
|
this.show_search_field_default()
|
195
195
|
this.search_field_scale()
|
196
|
-
|
196
|
+
|
197
197
|
@search_results.html content
|
198
198
|
@parsing = false
|
199
199
|
|
@@ -204,7 +204,7 @@ class Chosen extends AbstractChosen
|
|
204
204
|
'<li id="' + group.dom_id + '" class="group-result">' + $("<div />").text(group.label).html() + '</li>'
|
205
205
|
else
|
206
206
|
""
|
207
|
-
|
207
|
+
|
208
208
|
result_do_highlight: (el) ->
|
209
209
|
if el.length
|
210
210
|
this.result_clear_highlight()
|
@@ -215,7 +215,7 @@ class Chosen extends AbstractChosen
|
|
215
215
|
maxHeight = parseInt @search_results.css("maxHeight"), 10
|
216
216
|
visible_top = @search_results.scrollTop()
|
217
217
|
visible_bottom = maxHeight + visible_top
|
218
|
-
|
218
|
+
|
219
219
|
high_top = @result_highlight.position().top + @search_results.scrollTop()
|
220
220
|
high_bottom = high_top + @result_highlight.outerHeight()
|
221
221
|
|
@@ -223,7 +223,7 @@ class Chosen extends AbstractChosen
|
|
223
223
|
@search_results.scrollTop if (high_bottom - maxHeight) > 0 then (high_bottom - maxHeight) else 0
|
224
224
|
else if high_top < visible_top
|
225
225
|
@search_results.scrollTop high_top
|
226
|
-
|
226
|
+
|
227
227
|
result_clear_highlight: ->
|
228
228
|
@result_highlight.removeClass "highlighted" if @result_highlight
|
229
229
|
@result_highlight = null
|
@@ -233,8 +233,12 @@ class Chosen extends AbstractChosen
|
|
233
233
|
@selected_item.addClass "chzn-single-with-drop"
|
234
234
|
if @result_single_selected
|
235
235
|
this.result_do_highlight( @result_single_selected )
|
236
|
+
else if @max_selected_options <= @choices
|
237
|
+
@form_field_jq.trigger("liszt:maxselected", {chosen: this})
|
238
|
+
return false
|
236
239
|
|
237
240
|
dd_top = if @is_multiple then @container.height() else (@container.height() - 1)
|
241
|
+
@form_field_jq.trigger("liszt:showing_dropdown", {chosen: this})
|
238
242
|
@dropdown.css {"top": dd_top + "px", "left":0}
|
239
243
|
@results_showing = true
|
240
244
|
|
@@ -246,6 +250,7 @@ class Chosen extends AbstractChosen
|
|
246
250
|
results_hide: ->
|
247
251
|
@selected_item.removeClass "chzn-single-with-drop" unless @is_multiple
|
248
252
|
this.result_clear_highlight()
|
253
|
+
@form_field_jq.trigger("liszt:hiding_dropdown", {chosen: this})
|
249
254
|
@dropdown.css {"left":"-9000px"}
|
250
255
|
@results_showing = false
|
251
256
|
|
@@ -289,6 +294,9 @@ class Chosen extends AbstractChosen
|
|
289
294
|
this.results_show()
|
290
295
|
|
291
296
|
choice_build: (item) ->
|
297
|
+
if @is_multiple and @max_selected_options <= @choices
|
298
|
+
@form_field_jq.trigger("liszt:maxselected", {chosen: this})
|
299
|
+
return false # fire event
|
292
300
|
choice_id = @container_id + "_c_" + item.array_index
|
293
301
|
@choices += 1
|
294
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>'
|
@@ -312,20 +320,23 @@ class Chosen extends AbstractChosen
|
|
312
320
|
this.result_deselect (link.attr "rel")
|
313
321
|
link.parents('li').first().remove()
|
314
322
|
|
315
|
-
results_reset:
|
323
|
+
results_reset: ->
|
316
324
|
@form_field.options[0].selected = true
|
317
325
|
@selected_item.find("span").text @default_text
|
318
326
|
@selected_item.addClass("chzn-default") if not @is_multiple
|
319
327
|
this.show_search_field_default()
|
320
|
-
|
328
|
+
this.results_reset_cleanup()
|
321
329
|
@form_field_jq.trigger "change"
|
322
330
|
this.results_hide() if @active_field
|
331
|
+
|
332
|
+
results_reset_cleanup: ->
|
333
|
+
@selected_item.find("abbr").remove()
|
323
334
|
|
324
335
|
result_select: (evt) ->
|
325
336
|
if @result_highlight
|
326
337
|
high = @result_highlight
|
327
338
|
high_id = high.attr "id"
|
328
|
-
|
339
|
+
|
329
340
|
this.result_clear_highlight()
|
330
341
|
|
331
342
|
if @is_multiple
|
@@ -334,9 +345,9 @@ class Chosen extends AbstractChosen
|
|
334
345
|
@search_results.find(".result-selected").removeClass "result-selected"
|
335
346
|
@result_single_selected = high
|
336
347
|
@selected_item.removeClass("chzn-default")
|
337
|
-
|
348
|
+
|
338
349
|
high.addClass "result-selected"
|
339
|
-
|
350
|
+
|
340
351
|
position = high_id.substr(high_id.lastIndexOf("_") + 1 )
|
341
352
|
item = @results_data[position]
|
342
353
|
item.selected = true
|
@@ -348,12 +359,13 @@ class Chosen extends AbstractChosen
|
|
348
359
|
else
|
349
360
|
@selected_item.find("span").first().text item.text
|
350
361
|
this.single_deselect_control_build() if @allow_single_deselect
|
351
|
-
|
362
|
+
|
352
363
|
this.results_hide() unless evt.metaKey and @is_multiple
|
353
364
|
|
354
365
|
@search_field.val ""
|
355
366
|
|
356
|
-
@form_field_jq.trigger "change"
|
367
|
+
@form_field_jq.trigger "change", {'selected': @form_field.options[item.options_index].value} if @is_multiple || @form_field_jq.val() != @current_value
|
368
|
+
@current_value = @form_field_jq.val()
|
357
369
|
this.search_field_scale()
|
358
370
|
|
359
371
|
result_activate: (el) ->
|
@@ -373,7 +385,7 @@ class Chosen extends AbstractChosen
|
|
373
385
|
this.result_clear_highlight()
|
374
386
|
this.winnow_results()
|
375
387
|
|
376
|
-
@form_field_jq.trigger "change"
|
388
|
+
@form_field_jq.trigger "change", {deselected: @form_field.options[result_data.options_index].value}
|
377
389
|
this.search_field_scale()
|
378
390
|
|
379
391
|
single_deselect_control_build: ->
|
@@ -381,7 +393,7 @@ class Chosen extends AbstractChosen
|
|
381
393
|
|
382
394
|
winnow_results: ->
|
383
395
|
this.no_results_clear()
|
384
|
-
|
396
|
+
|
385
397
|
results = 0
|
386
398
|
|
387
399
|
searchText = if @search_field.val() is @default_text then "" else $('<div/>').text($.trim(@search_field.val())).html()
|
@@ -397,7 +409,7 @@ class Chosen extends AbstractChosen
|
|
397
409
|
found = false
|
398
410
|
result_id = option.dom_id
|
399
411
|
result = $("#" + result_id)
|
400
|
-
|
412
|
+
|
401
413
|
if regex.test option.html
|
402
414
|
found = true
|
403
415
|
results += 1
|
@@ -417,7 +429,7 @@ class Chosen extends AbstractChosen
|
|
417
429
|
text = text.substr(0, startpos) + '<em>' + text.substr(startpos)
|
418
430
|
else
|
419
431
|
text = option.html
|
420
|
-
|
432
|
+
|
421
433
|
result.html(text)
|
422
434
|
this.result_activate result
|
423
435
|
|
@@ -449,13 +461,13 @@ class Chosen extends AbstractChosen
|
|
449
461
|
do_high = if selected_results.length then selected_results.first() else @search_results.find(".active-result").first()
|
450
462
|
|
451
463
|
this.result_do_highlight do_high if do_high?
|
452
|
-
|
464
|
+
|
453
465
|
no_results: (terms) ->
|
454
466
|
no_results_html = $('<li class="no-results">' + @results_none_found + ' "<span></span>"</li>')
|
455
467
|
no_results_html.find("span").first().html(terms)
|
456
468
|
|
457
469
|
@search_results.append no_results_html
|
458
|
-
|
470
|
+
|
459
471
|
no_results_clear: ->
|
460
472
|
@search_results.find(".no-results").remove()
|
461
473
|
|
@@ -473,7 +485,7 @@ class Chosen extends AbstractChosen
|
|
473
485
|
this.results_show()
|
474
486
|
else if @result_highlight
|
475
487
|
prev_sibs = @result_highlight.prevAll("li.active-result")
|
476
|
-
|
488
|
+
|
477
489
|
if prev_sibs.length
|
478
490
|
this.result_do_highlight prev_sibs.first()
|
479
491
|
else
|
@@ -486,7 +498,10 @@ class Chosen extends AbstractChosen
|
|
486
498
|
this.clear_backstroke()
|
487
499
|
else
|
488
500
|
@pending_backstroke = @search_container.siblings("li.search-choice").last()
|
489
|
-
@
|
501
|
+
if @single_backstroke_delete
|
502
|
+
@keydown_backstroke()
|
503
|
+
else
|
504
|
+
@pending_backstroke.addClass "search-choice-focus"
|
490
505
|
|
491
506
|
clear_backstroke: ->
|
492
507
|
@pending_backstroke.removeClass "search-choice-focus" if @pending_backstroke
|
@@ -495,9 +510,9 @@ class Chosen extends AbstractChosen
|
|
495
510
|
keydown_checker: (evt) ->
|
496
511
|
stroke = evt.which ? evt.keyCode
|
497
512
|
this.search_field_scale()
|
498
|
-
|
513
|
+
|
499
514
|
this.clear_backstroke() if stroke != 8 and this.pending_backstroke
|
500
|
-
|
515
|
+
|
501
516
|
switch stroke
|
502
517
|
when 8
|
503
518
|
@backstroke_length = this.search_field.val().length
|
@@ -516,7 +531,7 @@ class Chosen extends AbstractChosen
|
|
516
531
|
when 40
|
517
532
|
this.keydown_arrow()
|
518
533
|
break
|
519
|
-
|
534
|
+
|
520
535
|
search_field_scale: ->
|
521
536
|
if @is_multiple
|
522
537
|
h = 0
|
@@ -524,10 +539,10 @@ class Chosen extends AbstractChosen
|
|
524
539
|
|
525
540
|
style_block = "position:absolute; left: -1000px; top: -1000px; display:none;"
|
526
541
|
styles = ['font-size','font-style', 'font-weight', 'font-family','line-height', 'text-transform', 'letter-spacing']
|
527
|
-
|
542
|
+
|
528
543
|
for style in styles
|
529
544
|
style_block += style + ":" + @search_field.css(style) + ";"
|
530
|
-
|
545
|
+
|
531
546
|
div = $('<div />', { 'style' : style_block })
|
532
547
|
div.text @search_field.val()
|
533
548
|
$('body').append div
|
@@ -542,13 +557,13 @@ class Chosen extends AbstractChosen
|
|
542
557
|
|
543
558
|
dd_top = @container.height()
|
544
559
|
@dropdown.css({"top": dd_top + "px"})
|
545
|
-
|
560
|
+
|
546
561
|
generate_random_id: ->
|
547
562
|
string = "sel" + this.generate_random_char() + this.generate_random_char() + this.generate_random_char()
|
548
563
|
while $("#" + string).length > 0
|
549
564
|
string += this.generate_random_char()
|
550
565
|
string
|
551
|
-
|
566
|
+
|
552
567
|
get_side_border_padding = (elmt) ->
|
553
568
|
side_border_padding = elmt.outerWidth() - elmt.width()
|
554
569
|
|
@@ -7,6 +7,7 @@ root = this
|
|
7
7
|
class Chosen extends AbstractChosen
|
8
8
|
|
9
9
|
setup: ->
|
10
|
+
@current_value = @form_field.value
|
10
11
|
@is_rtl = @form_field.hasClassName "chzn-rtl"
|
11
12
|
|
12
13
|
finish_setup: ->
|
@@ -22,7 +23,7 @@ class Chosen extends AbstractChosen
|
|
22
23
|
@no_results_temp = new Template('<li class="no-results">' + @results_none_found + ' "<span>#{terms}</span>"</li>')
|
23
24
|
|
24
25
|
set_up_html: ->
|
25
|
-
@container_id = @form_field.identify().replace(/
|
26
|
+
@container_id = @form_field.identify().replace(/[^\w]/g, '_') + "_chzn"
|
26
27
|
|
27
28
|
@f_width = if @form_field.getStyle("width") then parseInt @form_field.getStyle("width"), 10 else @form_field.getWidth()
|
28
29
|
|
@@ -31,8 +32,6 @@ class Chosen extends AbstractChosen
|
|
31
32
|
'class': "chzn-container#{ if @is_rtl then ' chzn-rtl' else '' }"
|
32
33
|
'style': 'width: ' + (@f_width) + 'px' #use parens around @f_width so coffeescript doesn't think + ' px' is a function parameter
|
33
34
|
|
34
|
-
@default_text = if @form_field.readAttribute 'data-placeholder' then @form_field.readAttribute 'data-placeholder' else @default_text_default
|
35
|
-
|
36
35
|
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
36
|
|
38
37
|
@form_field.hide().insert({ after: base_template })
|
@@ -116,7 +115,7 @@ class Chosen extends AbstractChosen
|
|
116
115
|
@pending_destroy_click = false
|
117
116
|
|
118
117
|
container_mouseup: (evt) ->
|
119
|
-
this.results_reset(evt) if evt.target.nodeName is "ABBR"
|
118
|
+
this.results_reset(evt) if evt.target.nodeName is "ABBR" and not @is_disabled
|
120
119
|
|
121
120
|
blur_test: (evt) ->
|
122
121
|
this.close_field() if not @active_field and @container.hasClassName("chzn-container-active")
|
@@ -164,7 +163,7 @@ class Chosen extends AbstractChosen
|
|
164
163
|
@search_choices.select("li.search-choice").invoke("remove")
|
165
164
|
@choices = 0
|
166
165
|
else if not @is_multiple
|
167
|
-
@selected_item.down("span").update(@default_text)
|
166
|
+
@selected_item.addClassName("chzn-default").down("span").update(@default_text)
|
168
167
|
if @form_field.options.length <= @disable_search_threshold
|
169
168
|
@container.addClassName "chzn-container-single-nosearch"
|
170
169
|
else
|
@@ -224,8 +223,12 @@ class Chosen extends AbstractChosen
|
|
224
223
|
@selected_item.addClassName('chzn-single-with-drop')
|
225
224
|
if @result_single_selected
|
226
225
|
this.result_do_highlight( @result_single_selected )
|
226
|
+
else if @max_selected_options <= @choices
|
227
|
+
@form_field.fire("liszt:maxselected", {chosen: this})
|
228
|
+
return false
|
227
229
|
|
228
230
|
dd_top = if @is_multiple then @container.getHeight() else (@container.getHeight() - 1)
|
231
|
+
@form_field.fire("liszt:showing_dropdown", {chosen: this})
|
229
232
|
@dropdown.setStyle {"top": dd_top + "px", "left":0}
|
230
233
|
@results_showing = true
|
231
234
|
|
@@ -237,6 +240,7 @@ class Chosen extends AbstractChosen
|
|
237
240
|
results_hide: ->
|
238
241
|
@selected_item.removeClassName('chzn-single-with-drop') unless @is_multiple
|
239
242
|
this.result_clear_highlight()
|
243
|
+
@form_field.fire("liszt:hiding_dropdown", {chosen: this})
|
240
244
|
@dropdown.setStyle({"left":"-9000px"})
|
241
245
|
@results_showing = false
|
242
246
|
|
@@ -280,6 +284,9 @@ class Chosen extends AbstractChosen
|
|
280
284
|
this.results_show()
|
281
285
|
|
282
286
|
choice_build: (item) ->
|
287
|
+
if @is_multiple and @max_selected_options <= @choices
|
288
|
+
@form_field.fire("liszt:maxselected", {chosen: this})
|
289
|
+
return false
|
283
290
|
choice_id = @container_id + "_c_" + item.array_index
|
284
291
|
@choices += 1
|
285
292
|
@search_container.insert
|
@@ -305,14 +312,18 @@ class Chosen extends AbstractChosen
|
|
305
312
|
this.result_deselect link.readAttribute("rel")
|
306
313
|
link.up('li').remove()
|
307
314
|
|
308
|
-
results_reset:
|
315
|
+
results_reset: ->
|
309
316
|
@form_field.options[0].selected = true
|
310
317
|
@selected_item.down("span").update(@default_text)
|
311
318
|
@selected_item.addClassName("chzn-default") if not @is_multiple
|
312
319
|
this.show_search_field_default()
|
313
|
-
|
320
|
+
this.results_reset_cleanup()
|
314
321
|
@form_field.simulate("change") if typeof Event.simulate is 'function'
|
315
322
|
this.results_hide() if @active_field
|
323
|
+
|
324
|
+
results_reset_cleanup: ->
|
325
|
+
deselect_trigger = @selected_item.down("abbr")
|
326
|
+
deselect_trigger.remove() if(deselect_trigger)
|
316
327
|
|
317
328
|
result_select: (evt) ->
|
318
329
|
if @result_highlight
|
@@ -343,8 +354,10 @@ class Chosen extends AbstractChosen
|
|
343
354
|
this.results_hide() unless evt.metaKey and @is_multiple
|
344
355
|
|
345
356
|
@search_field.value = ""
|
346
|
-
|
347
|
-
@form_field.simulate("change") if typeof Event.simulate is 'function'
|
357
|
+
|
358
|
+
@form_field.simulate("change") if typeof Event.simulate is 'function' && (@is_multiple || @form_field.value != @current_value)
|
359
|
+
@current_value = @form_field.value
|
360
|
+
|
348
361
|
this.search_field_scale()
|
349
362
|
|
350
363
|
result_activate: (el) ->
|
@@ -482,7 +495,10 @@ class Chosen extends AbstractChosen
|
|
482
495
|
this.clear_backstroke()
|
483
496
|
else
|
484
497
|
@pending_backstroke = @search_container.siblings("li.search-choice").last()
|
485
|
-
@
|
498
|
+
if @single_backstroke_delete
|
499
|
+
@keydown_backstroke()
|
500
|
+
else
|
501
|
+
@pending_backstroke.addClassName("search-choice-focus")
|
486
502
|
|
487
503
|
clear_backstroke: ->
|
488
504
|
@pending_backstroke.removeClassName("search-choice-focus") if @pending_backstroke
|
@@ -10,7 +10,7 @@ class AbstractChosen
|
|
10
10
|
this.set_default_values()
|
11
11
|
|
12
12
|
@is_multiple = @form_field.multiple
|
13
|
-
|
13
|
+
this.set_default_text()
|
14
14
|
|
15
15
|
this.setup()
|
16
16
|
|
@@ -31,7 +31,18 @@ class AbstractChosen
|
|
31
31
|
@disable_search_threshold = @options.disable_search_threshold || 0
|
32
32
|
@search_contains = @options.search_contains || false
|
33
33
|
@choices = 0
|
34
|
-
@
|
34
|
+
@single_backstroke_delete = @options.single_backstroke_delete || false
|
35
|
+
@max_selected_options = @options.max_selected_options || Infinity
|
36
|
+
|
37
|
+
set_default_text: ->
|
38
|
+
if @form_field.getAttribute("data-placeholder")
|
39
|
+
@default_text = @form_field.getAttribute("data-placeholder")
|
40
|
+
else if @is_multiple
|
41
|
+
@default_text = @options.placeholder_text_multiple || @options.placeholder_text || "Select Some Options"
|
42
|
+
else
|
43
|
+
@default_text = @options.placeholder_text_single || @options.placeholder_text || "Select an Option"
|
44
|
+
|
45
|
+
@results_none_found = @form_field.getAttribute("data-no_results_text") || @options.no_results_text || "No results match"
|
35
46
|
|
36
47
|
mouse_enter: -> @mouse_on_container = true
|
37
48
|
mouse_leave: -> @mouse_on_container = false
|
@@ -60,6 +71,7 @@ class AbstractChosen
|
|
60
71
|
""
|
61
72
|
|
62
73
|
results_update_field: ->
|
74
|
+
this.results_reset_cleanup() if not @is_multiple
|
63
75
|
this.result_clear_highlight()
|
64
76
|
@result_single_selected = null
|
65
77
|
this.results_build()
|
@@ -103,7 +115,7 @@ class AbstractChosen
|
|
103
115
|
new_id
|
104
116
|
|
105
117
|
generate_random_char: ->
|
106
|
-
chars = "
|
118
|
+
chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
107
119
|
rand = Math.floor(Math.random() * chars.length)
|
108
120
|
newchar = chars.substring rand, rand+1
|
109
121
|
|
@@ -17,7 +17,7 @@
|
|
17
17
|
-moz-box-shadow: 0 4px 5px rgba(0, 0, 0, 0.15)
|
18
18
|
-o-box-shadow: 0 4px 5px rgba(0, 0, 0, 0.15)
|
19
19
|
box-shadow: 0 4px 5px rgba(0, 0, 0, 0.15)
|
20
|
-
z-index:
|
20
|
+
z-index: 1010
|
21
21
|
|
22
22
|
/* @end
|
23
23
|
|
@@ -74,18 +74,20 @@
|
|
74
74
|
background: image-url('chosen-sprite.png') right top no-repeat
|
75
75
|
&:hover
|
76
76
|
background-position: right -11px
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
77
|
+
&.chzn-disabled abbr:hover
|
78
|
+
background-position: right top
|
79
|
+
.chzn-single div
|
80
|
+
position: absolute
|
81
|
+
right: 0
|
82
|
+
top: 0
|
83
|
+
display: block
|
84
|
+
height: 100%
|
85
|
+
width: 18px
|
86
|
+
b
|
87
|
+
background: image-url('chosen-sprite.png') no-repeat 0 0
|
81
88
|
display: block
|
89
|
+
width: 100%
|
82
90
|
height: 100%
|
83
|
-
width: 18px
|
84
|
-
b
|
85
|
-
background: image-url('chosen-sprite.png') no-repeat 0 0
|
86
|
-
display: block
|
87
|
-
width: 100%
|
88
|
-
height: 100%
|
89
91
|
.chzn-search
|
90
92
|
padding: 3px 4px
|
91
93
|
position: relative
|
@@ -116,7 +118,7 @@
|
|
116
118
|
|
117
119
|
/* @end
|
118
120
|
|
119
|
-
.chzn-container-single-nosearch
|
121
|
+
.chzn-container-single-nosearch input
|
120
122
|
position: absolute
|
121
123
|
left: -9000px
|
122
124
|
|
@@ -213,6 +215,7 @@
|
|
213
215
|
position: relative
|
214
216
|
overflow-x: hidden
|
215
217
|
overflow-y: auto
|
218
|
+
-webkit-overflow-scrolling: touch
|
216
219
|
|
217
220
|
.chzn-container-multi .chzn-results
|
218
221
|
margin: -1px 0 0
|
@@ -253,7 +256,7 @@
|
|
253
256
|
.group-option
|
254
257
|
padding-left: 15px
|
255
258
|
|
256
|
-
.chzn-container-multi .
|
259
|
+
.chzn-container-multi .result-selected
|
257
260
|
display: none
|
258
261
|
|
259
262
|
.chzn-container
|
@@ -329,7 +332,7 @@
|
|
329
332
|
.chzn-disabled
|
330
333
|
cursor: default
|
331
334
|
opacity: 0.5 !important
|
332
|
-
.chzn-single, .chzn-choices .search-choice
|
335
|
+
.chzn-single, .chzn-choices .search-choice-close
|
333
336
|
cursor: default
|
334
337
|
|
335
338
|
/* @group Right to Left
|
@@ -367,7 +370,7 @@
|
|
367
370
|
.chzn-results .group-option
|
368
371
|
padding-left: 0
|
369
372
|
padding-right: 15px
|
370
|
-
&.chzn-container-active
|
373
|
+
&.chzn-container-active div
|
371
374
|
border-right: none
|
372
375
|
.chzn-search input
|
373
376
|
background: white image-url('chosen-sprite.png') no-repeat -38px -22px
|
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
|
4
|
+
version: 0.9.8.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: thor
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ~>
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: '0.14'
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0.14'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: bundler
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ~>
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: '1.0'
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: rails
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ~>
|
@@ -54,10 +69,15 @@ dependencies:
|
|
54
69
|
version: '3.0'
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '3.0'
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: sass
|
60
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
61
81
|
none: false
|
62
82
|
requirements:
|
63
83
|
- - ~>
|
@@ -65,7 +85,12 @@ dependencies:
|
|
65
85
|
version: '3.1'
|
66
86
|
type: :development
|
67
87
|
prerelease: false
|
68
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '3.1'
|
69
94
|
description: Chosen is a javascript library of select box enhancer for jQuery and
|
70
95
|
Protoype. This gem integrates Chosen with Rails asset pipeline for easy of use.
|
71
96
|
email:
|
@@ -113,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
138
|
version: '0'
|
114
139
|
requirements: []
|
115
140
|
rubyforge_project:
|
116
|
-
rubygems_version: 1.8.
|
141
|
+
rubygems_version: 1.8.24
|
117
142
|
signing_key:
|
118
143
|
specification_version: 3
|
119
144
|
summary: Integrate Chosen javascript library with Rails asset pipeline
|