chosen-rails 0.10.0 → 0.12.0
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.
- checksums.yaml +4 -4
- data/lib/chosen-rails/version.rb +2 -2
- data/vendor/assets/javascripts/chosen.jquery.coffee +19 -82
- data/vendor/assets/javascripts/chosen.proto.coffee +21 -87
- data/vendor/assets/javascripts/lib/abstract-chosen.coffee +67 -1
- data/vendor/assets/stylesheets/chosen.css.sass +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a32fb00872ecb69436db4a92a31779096517bff1
|
4
|
+
data.tar.gz: f31803b1c81d6438de864a8d8e1a3dc03167df56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d3f9452482557374dad4d67089b70eae5174b970f33102fe445903ae5f2317e2d9aa9bd61be96a2cc73cd0ac4bf31d1faa74e9799c21b0e2a1a59f8044e18f4
|
7
|
+
data.tar.gz: c68dfb92a883c6092dc53a1a9c098430b40d978b59c9ec3adf01e6a7c8855d0d9b27dd18a7c2c1d77b9b21e52a92e9f1ba2528e4d3927a055ad8cf31588b1be9
|
data/lib/chosen-rails/version.rb
CHANGED
@@ -166,7 +166,7 @@ class Chosen extends AbstractChosen
|
|
166
166
|
if @is_multiple
|
167
167
|
@search_choices.find("li.search-choice").remove()
|
168
168
|
else if not @is_multiple
|
169
|
-
|
169
|
+
this.single_set_selected_text()
|
170
170
|
if @disable_search or @form_field.options.length <= @disable_search_threshold
|
171
171
|
@search_field[0].readOnly = true
|
172
172
|
@container.addClass "chzn-container-single-nosearch"
|
@@ -174,23 +174,12 @@ class Chosen extends AbstractChosen
|
|
174
174
|
@search_field[0].readOnly = false
|
175
175
|
@container.removeClass "chzn-container-single-nosearch"
|
176
176
|
|
177
|
-
|
178
|
-
for data in @results_data
|
179
|
-
if data.group
|
180
|
-
content += this.result_add_group data
|
181
|
-
else if !data.empty
|
182
|
-
content += this.result_add_option data
|
183
|
-
if data.selected and @is_multiple
|
184
|
-
this.choice_build data
|
185
|
-
else if data.selected and not @is_multiple
|
186
|
-
@selected_item.removeClass("chzn-default").find("span").text data.text
|
187
|
-
this.single_deselect_control_build() if @allow_single_deselect
|
177
|
+
this.update_results_content this.results_option_build({first:true})
|
188
178
|
|
189
179
|
this.search_field_disabled()
|
190
180
|
this.show_search_field_default()
|
191
181
|
this.search_field_scale()
|
192
182
|
|
193
|
-
@search_results.html content
|
194
183
|
@parsing = false
|
195
184
|
|
196
185
|
result_add_group: (group) ->
|
@@ -235,6 +224,9 @@ class Chosen extends AbstractChosen
|
|
235
224
|
|
236
225
|
this.winnow_results()
|
237
226
|
|
227
|
+
update_results_content: (content) ->
|
228
|
+
@search_results.html content
|
229
|
+
|
238
230
|
results_hide: ->
|
239
231
|
if @results_showing
|
240
232
|
this.result_clear_highlight()
|
@@ -311,8 +303,7 @@ class Chosen extends AbstractChosen
|
|
311
303
|
results_reset: ->
|
312
304
|
@form_field.options[0].selected = true
|
313
305
|
@selected_option_count = null
|
314
|
-
|
315
|
-
@selected_item.addClass("chzn-default") if not @is_multiple
|
306
|
+
this.single_set_selected_text()
|
316
307
|
this.show_search_field_default()
|
317
308
|
this.results_reset_cleanup()
|
318
309
|
@form_field_jq.trigger "change"
|
@@ -338,7 +329,6 @@ class Chosen extends AbstractChosen
|
|
338
329
|
else
|
339
330
|
@search_results.find(".result-selected").removeClass "result-selected"
|
340
331
|
@result_single_selected = high
|
341
|
-
@selected_item.removeClass("chzn-default")
|
342
332
|
|
343
333
|
high.addClass "result-selected"
|
344
334
|
|
@@ -352,8 +342,7 @@ class Chosen extends AbstractChosen
|
|
352
342
|
if @is_multiple
|
353
343
|
this.choice_build item
|
354
344
|
else
|
355
|
-
|
356
|
-
this.single_deselect_control_build() if @allow_single_deselect
|
345
|
+
this.single_set_selected_text(item.text)
|
357
346
|
|
358
347
|
this.results_hide() unless (evt.metaKey or evt.ctrlKey) and @is_multiple
|
359
348
|
|
@@ -363,16 +352,14 @@ class Chosen extends AbstractChosen
|
|
363
352
|
@current_selectedIndex = @form_field.selectedIndex
|
364
353
|
this.search_field_scale()
|
365
354
|
|
366
|
-
|
367
|
-
if
|
368
|
-
|
369
|
-
else if @is_multiple and option.selected
|
370
|
-
el.addClass("result-selected")
|
355
|
+
single_set_selected_text: (text=@default_text) ->
|
356
|
+
if text is @default_text
|
357
|
+
@selected_item.addClass("chzn-default")
|
371
358
|
else
|
372
|
-
|
359
|
+
this.single_deselect_control_build()
|
360
|
+
@selected_item.removeClass("chzn-default")
|
373
361
|
|
374
|
-
|
375
|
-
el.removeClass("active-result result-selected disabled-result")
|
362
|
+
@selected_item.find("span").text(text)
|
376
363
|
|
377
364
|
result_deselect: (pos) ->
|
378
365
|
result_data = @results_data[pos]
|
@@ -387,7 +374,7 @@ class Chosen extends AbstractChosen
|
|
387
374
|
result.removeClass("result-selected").addClass("active-result").show()
|
388
375
|
|
389
376
|
this.result_clear_highlight()
|
390
|
-
this.winnow_results()
|
377
|
+
this.winnow_results() if @results_showing
|
391
378
|
|
392
379
|
@form_field_jq.trigger "change", {deselected: @form_field.options[result_data.options_index].value}
|
393
380
|
this.search_field_scale()
|
@@ -401,65 +388,15 @@ class Chosen extends AbstractChosen
|
|
401
388
|
@selected_item.find("span").first().after "<abbr class=\"search-choice-close\"></abbr>" unless @selected_item.find("abbr").length
|
402
389
|
@selected_item.addClass("chzn-single-with-deselect")
|
403
390
|
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
results = 0
|
408
|
-
|
409
|
-
searchText = if @search_field.val() is @default_text then "" else $('<div/>').text($.trim(@search_field.val())).html()
|
410
|
-
regexAnchor = if @search_contains then "" else "^"
|
411
|
-
regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')
|
412
|
-
zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')
|
413
|
-
|
414
|
-
for option in @results_data
|
415
|
-
if not option.empty
|
416
|
-
if option.group
|
417
|
-
$('#' + option.dom_id).css('display', 'none')
|
418
|
-
else
|
419
|
-
found = false
|
420
|
-
result_id = option.dom_id
|
421
|
-
result = $("#" + result_id)
|
422
|
-
|
423
|
-
if regex.test option.html
|
424
|
-
found = true
|
425
|
-
results += 1
|
426
|
-
else if @enable_split_word_search and (option.html.indexOf(" ") >= 0 or option.html.indexOf("[") == 0)
|
427
|
-
#TODO: replace this substitution of /\[\]/ with a list of characters to skip.
|
428
|
-
parts = option.html.replace(/\[|\]/g, "").split(" ")
|
429
|
-
if parts.length
|
430
|
-
for part in parts
|
431
|
-
if regex.test part
|
432
|
-
found = true
|
433
|
-
results += 1
|
434
|
-
|
435
|
-
if found
|
436
|
-
if searchText.length
|
437
|
-
startpos = option.html.search zregex
|
438
|
-
text = option.html.substr(0, startpos + searchText.length) + '</em>' + option.html.substr(startpos + searchText.length)
|
439
|
-
text = text.substr(0, startpos) + '<em>' + text.substr(startpos)
|
440
|
-
else
|
441
|
-
text = option.html
|
442
|
-
|
443
|
-
result.html(text)
|
444
|
-
this.result_activate result, option
|
445
|
-
|
446
|
-
$("#" + @results_data[option.group_array_index].dom_id).css('display', 'list-item') if option.group_array_index?
|
447
|
-
else
|
448
|
-
this.result_clear_highlight() if @result_highlight and result_id is @result_highlight.attr 'id'
|
449
|
-
this.result_deactivate result
|
450
|
-
|
451
|
-
if results < 1 and searchText.length
|
452
|
-
this.no_results searchText
|
453
|
-
else
|
454
|
-
this.winnow_results_set_highlight()
|
391
|
+
get_search_text: ->
|
392
|
+
if @search_field.val() is @default_text then "" else $('<div/>').text($.trim(@search_field.val())).html()
|
455
393
|
|
456
394
|
winnow_results_set_highlight: ->
|
457
|
-
if not @result_highlight
|
458
395
|
|
459
|
-
|
460
|
-
|
396
|
+
selected_results = if not @is_multiple then @search_results.find(".result-selected.active-result") else []
|
397
|
+
do_high = if selected_results.length then selected_results.first() else @search_results.find(".active-result").first()
|
461
398
|
|
462
|
-
|
399
|
+
this.result_do_highlight do_high if do_high?
|
463
400
|
|
464
401
|
no_results: (terms) ->
|
465
402
|
no_results_html = $('<li class="no-results">' + @results_none_found + ' "<span></span>"</li>')
|
@@ -154,7 +154,7 @@ class Chosen extends AbstractChosen
|
|
154
154
|
if @is_multiple
|
155
155
|
@search_choices.select("li.search-choice").invoke("remove")
|
156
156
|
else if not @is_multiple
|
157
|
-
|
157
|
+
this.single_set_selected_text()
|
158
158
|
if @disable_search or @form_field.options.length <= @disable_search_threshold
|
159
159
|
@search_field.readOnly = true
|
160
160
|
@container.addClassName "chzn-container-single-nosearch"
|
@@ -162,23 +162,12 @@ class Chosen extends AbstractChosen
|
|
162
162
|
@search_field.readOnly = false
|
163
163
|
@container.removeClassName "chzn-container-single-nosearch"
|
164
164
|
|
165
|
-
|
166
|
-
for data in @results_data
|
167
|
-
if data.group
|
168
|
-
content += this.result_add_group data
|
169
|
-
else if !data.empty
|
170
|
-
content += this.result_add_option data
|
171
|
-
if data.selected and @is_multiple
|
172
|
-
this.choice_build data
|
173
|
-
else if data.selected and not @is_multiple
|
174
|
-
@selected_item.removeClassName("chzn-default").down("span").update( data.html )
|
175
|
-
this.single_deselect_control_build() if @allow_single_deselect
|
165
|
+
this.update_results_content this.results_option_build({first:true})
|
176
166
|
|
177
167
|
this.search_field_disabled()
|
178
168
|
this.show_search_field_default()
|
179
169
|
this.search_field_scale()
|
180
170
|
|
181
|
-
@search_results.update content
|
182
171
|
@parsing = false
|
183
172
|
|
184
173
|
result_add_group: (group) ->
|
@@ -222,6 +211,9 @@ class Chosen extends AbstractChosen
|
|
222
211
|
|
223
212
|
this.winnow_results()
|
224
213
|
|
214
|
+
update_results_content: (content) ->
|
215
|
+
@search_results.update content
|
216
|
+
|
225
217
|
results_hide: ->
|
226
218
|
if @results_showing
|
227
219
|
this.result_clear_highlight()
|
@@ -298,8 +290,7 @@ class Chosen extends AbstractChosen
|
|
298
290
|
results_reset: ->
|
299
291
|
@form_field.options[0].selected = true
|
300
292
|
@selected_option_count = null
|
301
|
-
|
302
|
-
@selected_item.addClassName("chzn-default") if not @is_multiple
|
293
|
+
this.single_set_selected_text()
|
303
294
|
this.show_search_field_default()
|
304
295
|
this.results_reset_cleanup()
|
305
296
|
@form_field.simulate("change") if typeof Event.simulate is 'function'
|
@@ -323,7 +314,6 @@ class Chosen extends AbstractChosen
|
|
323
314
|
high.removeClassName("active-result")
|
324
315
|
else
|
325
316
|
@search_results.descendants(".result-selected").invoke "removeClassName", "result-selected"
|
326
|
-
@selected_item.removeClassName("chzn-default")
|
327
317
|
@result_single_selected = high
|
328
318
|
|
329
319
|
high.addClassName("result-selected")
|
@@ -338,8 +328,7 @@ class Chosen extends AbstractChosen
|
|
338
328
|
if @is_multiple
|
339
329
|
this.choice_build item
|
340
330
|
else
|
341
|
-
|
342
|
-
this.single_deselect_control_build() if @allow_single_deselect
|
331
|
+
this.single_set_selected_text(item.text)
|
343
332
|
|
344
333
|
this.results_hide() unless (evt.metaKey or evt.ctrlKey) and @is_multiple
|
345
334
|
|
@@ -350,18 +339,14 @@ class Chosen extends AbstractChosen
|
|
350
339
|
|
351
340
|
this.search_field_scale()
|
352
341
|
|
353
|
-
|
354
|
-
if
|
355
|
-
|
356
|
-
else if @is_multiple and option.selected
|
357
|
-
el.addClassName("result-selected")
|
342
|
+
single_set_selected_text: (text=@default_text) ->
|
343
|
+
if text is @default_text
|
344
|
+
@selected_item.addClassName("chzn-default")
|
358
345
|
else
|
359
|
-
|
346
|
+
this.single_deselect_control_build()
|
347
|
+
@selected_item.removeClassName("chzn-default")
|
360
348
|
|
361
|
-
|
362
|
-
el.removeClassName("active-result")
|
363
|
-
el.removeClassName("result-selected")
|
364
|
-
el.removeClassName("disabled-result")
|
349
|
+
@selected_item.down("span").update(text)
|
365
350
|
|
366
351
|
result_deselect: (pos) ->
|
367
352
|
result_data = @results_data[pos]
|
@@ -376,7 +361,7 @@ class Chosen extends AbstractChosen
|
|
376
361
|
result.removeClassName("result-selected").addClassName("active-result").show()
|
377
362
|
|
378
363
|
this.result_clear_highlight()
|
379
|
-
this.winnow_results()
|
364
|
+
this.winnow_results() if @results_showing
|
380
365
|
|
381
366
|
@form_field.simulate("change") if typeof Event.simulate is 'function'
|
382
367
|
this.search_field_scale()
|
@@ -389,68 +374,17 @@ class Chosen extends AbstractChosen
|
|
389
374
|
@selected_item.down("span").insert { after: "<abbr class=\"search-choice-close\"></abbr>" } unless @selected_item.down("abbr")
|
390
375
|
@selected_item.addClassName("chzn-single-with-deselect")
|
391
376
|
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
results = 0
|
396
|
-
|
397
|
-
searchText = if @search_field.value is @default_text then "" else @search_field.value.strip().escapeHTML()
|
398
|
-
regexAnchor = if @search_contains then "" else "^"
|
399
|
-
regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')
|
400
|
-
zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')
|
401
|
-
|
402
|
-
for option in @results_data
|
403
|
-
if not option.empty
|
404
|
-
if option.group
|
405
|
-
$(option.dom_id).hide()
|
406
|
-
else
|
407
|
-
found = false
|
408
|
-
result_id = option.dom_id
|
409
|
-
|
410
|
-
if regex.test option.html
|
411
|
-
found = true
|
412
|
-
results += 1
|
413
|
-
else if @enable_split_word_search and (option.html.indexOf(" ") >= 0 or option.html.indexOf("[") == 0)
|
414
|
-
#TODO: replace this substitution of /\[\]/ with a list of characters to skip.
|
415
|
-
parts = option.html.replace(/\[|\]/g, "").split(" ")
|
416
|
-
if parts.length
|
417
|
-
for part in parts
|
418
|
-
if regex.test part
|
419
|
-
found = true
|
420
|
-
results += 1
|
421
|
-
|
422
|
-
if found
|
423
|
-
if searchText.length
|
424
|
-
startpos = option.html.search zregex
|
425
|
-
text = option.html.substr(0, startpos + searchText.length) + '</em>' + option.html.substr(startpos + searchText.length)
|
426
|
-
text = text.substr(0, startpos) + '<em>' + text.substr(startpos)
|
427
|
-
else
|
428
|
-
text = option.html
|
429
|
-
|
430
|
-
$(result_id).update text if $(result_id).innerHTML != text
|
431
|
-
|
432
|
-
this.result_activate $(result_id), option
|
433
|
-
|
434
|
-
$(@results_data[option.group_array_index].dom_id).setStyle({display: 'list-item'}) if option.group_array_index?
|
435
|
-
else
|
436
|
-
this.result_clear_highlight() if $(result_id) is @result_highlight
|
437
|
-
this.result_deactivate $(result_id)
|
438
|
-
|
439
|
-
if results < 1 and searchText.length
|
440
|
-
this.no_results(searchText)
|
441
|
-
else
|
442
|
-
this.winnow_results_set_highlight()
|
377
|
+
get_search_text: ->
|
378
|
+
if @search_field.value is @default_text then "" else @search_field.value.strip().escapeHTML()
|
443
379
|
|
444
380
|
winnow_results_set_highlight: ->
|
445
|
-
if not @
|
446
|
-
|
447
|
-
if not @is_multiple
|
448
|
-
do_high = @search_results.down(".result-selected.active-result")
|
381
|
+
if not @is_multiple
|
382
|
+
do_high = @search_results.down(".result-selected.active-result")
|
449
383
|
|
450
|
-
|
451
|
-
|
384
|
+
if not do_high?
|
385
|
+
do_high = @search_results.down(".active-result")
|
452
386
|
|
453
|
-
|
387
|
+
this.result_do_highlight do_high if do_high?
|
454
388
|
|
455
389
|
no_results: (terms) ->
|
456
390
|
@search_results.insert @no_results_temp.evaluate( terms: terms )
|
@@ -56,6 +56,24 @@ class AbstractChosen
|
|
56
56
|
@active_field = false
|
57
57
|
setTimeout (=> this.blur_test()), 100
|
58
58
|
|
59
|
+
results_option_build: (options) ->
|
60
|
+
content = ''
|
61
|
+
for data in @results_data
|
62
|
+
if data.group && data.search_match
|
63
|
+
content += this.result_add_group data
|
64
|
+
else if !data.empty && data.search_match
|
65
|
+
content += this.result_add_option data
|
66
|
+
|
67
|
+
# this select logic pins on an awkward flag
|
68
|
+
# we can make it better
|
69
|
+
if options?.first
|
70
|
+
if data.selected and @is_multiple
|
71
|
+
this.choice_build data
|
72
|
+
else if data.selected and not @is_multiple
|
73
|
+
this.single_set_selected_text(data.text)
|
74
|
+
|
75
|
+
content
|
76
|
+
|
59
77
|
result_add_option: (option) ->
|
60
78
|
option.dom_id = @container_id + "_o_" + option.array_index
|
61
79
|
|
@@ -68,7 +86,7 @@ class AbstractChosen
|
|
68
86
|
|
69
87
|
style = if option.style.cssText != "" then " style=\"#{option.style}\"" else ""
|
70
88
|
|
71
|
-
|
89
|
+
"""<li id="#{option.dom_id}" class="#{classes.join(' ')}"#{style}>#{option.search_text}</li>"""
|
72
90
|
|
73
91
|
results_update_field: ->
|
74
92
|
this.set_default_text()
|
@@ -89,6 +107,54 @@ class AbstractChosen
|
|
89
107
|
else
|
90
108
|
this.results_show()
|
91
109
|
|
110
|
+
winnow_results: ->
|
111
|
+
this.no_results_clear()
|
112
|
+
|
113
|
+
results = 0
|
114
|
+
|
115
|
+
searchText = this.get_search_text()
|
116
|
+
regexAnchor = if @search_contains then "" else "^"
|
117
|
+
regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')
|
118
|
+
zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')
|
119
|
+
|
120
|
+
for option in @results_data
|
121
|
+
if not option.empty
|
122
|
+
if option.group
|
123
|
+
option.search_match = false
|
124
|
+
else
|
125
|
+
option.search_match = false
|
126
|
+
|
127
|
+
if regex.test option.html
|
128
|
+
option.search_match = true
|
129
|
+
results += 1
|
130
|
+
else if @enable_split_word_search and (option.html.indexOf(" ") >= 0 or option.html.indexOf("[") == 0)
|
131
|
+
#TODO: replace this substitution of /\[\]/ with a list of characters to skip.
|
132
|
+
parts = option.html.replace(/\[|\]/g, "").split(" ")
|
133
|
+
if parts.length
|
134
|
+
for part in parts
|
135
|
+
if regex.test part
|
136
|
+
option.search_match = true
|
137
|
+
results += 1
|
138
|
+
|
139
|
+
if option.search_match
|
140
|
+
if searchText.length
|
141
|
+
startpos = option.html.search zregex
|
142
|
+
text = option.html.substr(0, startpos + searchText.length) + '</em>' + option.html.substr(startpos + searchText.length)
|
143
|
+
text = text.substr(0, startpos) + '<em>' + text.substr(startpos)
|
144
|
+
else
|
145
|
+
text = option.html
|
146
|
+
|
147
|
+
option.search_text = text
|
148
|
+
|
149
|
+
@results_data[option.group_array_index].search_match = true if option.group_array_index?
|
150
|
+
|
151
|
+
if results < 1 and searchText.length
|
152
|
+
this.update_results_content ""
|
153
|
+
this.no_results searchText
|
154
|
+
else
|
155
|
+
this.update_results_content this.results_option_build()
|
156
|
+
this.winnow_results_set_highlight()
|
157
|
+
|
92
158
|
choices_count: ->
|
93
159
|
return @selected_option_count if @selected_option_count?
|
94
160
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chosen-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tse-Ching Ho
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|