chosen-rails 0.9.14 → 0.9.15
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
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bac675bdf969fb0dc587c152a924a2eadff6d44f
|
4
|
+
data.tar.gz: 727f3bb3d99c34502ce16b8d32b60b693eb3c1b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f8d165ce179fe3882a0846d1d3be752a192f2633f61ee4bf04ea9c2f1b2d874f52f9930bf506f880fe3ba4596c2fa13bfdbdbb3c1e4180e53c3124bd7bfa0b4
|
7
|
+
data.tar.gz: 56b856a0637d3f5c09d49be9c376af8d78249691b55fc5b285bb0966759998f7053fe3717e47be34e4453826ff3a64974e2a1e671290b6e3b3084ed79d7768c4
|
data/lib/chosen-rails.rb
CHANGED
@@ -2,13 +2,14 @@ require 'chosen-rails/version'
|
|
2
2
|
|
3
3
|
module Chosen
|
4
4
|
module Rails
|
5
|
-
case ::Rails.version.to_s
|
6
|
-
when /^4/
|
7
|
-
require 'chosen-rails/engine'
|
8
|
-
when /^3\.[12]/
|
9
|
-
require 'chosen-rails/engine3'
|
10
|
-
when /^3\.[0]/
|
11
|
-
require 'chosen-rails/railtie'
|
12
|
-
end
|
13
5
|
end
|
14
6
|
end
|
7
|
+
|
8
|
+
case ::Rails.version.to_s
|
9
|
+
when /^4/
|
10
|
+
require 'chosen-rails/engine'
|
11
|
+
when /^3\.[12]/
|
12
|
+
require 'chosen-rails/engine3'
|
13
|
+
when /^3\.[0]/
|
14
|
+
require 'chosen-rails/railtie'
|
15
|
+
end
|
data/lib/chosen-rails/version.rb
CHANGED
@@ -164,11 +164,12 @@ class Chosen extends AbstractChosen
|
|
164
164
|
|
165
165
|
results_build: ->
|
166
166
|
@parsing = true
|
167
|
+
@selected_option_count = null
|
168
|
+
|
167
169
|
@results_data = root.SelectParser.select_to_array @form_field
|
168
170
|
|
169
|
-
if @is_multiple and
|
171
|
+
if @is_multiple and this.choices_count() > 0
|
170
172
|
@search_choices.find("li.search-choice").remove()
|
171
|
-
@choices = 0
|
172
173
|
else if not @is_multiple
|
173
174
|
@selected_item.addClass("chzn-default").find("span").text(@default_text)
|
174
175
|
if @disable_search or @form_field.options.length <= @disable_search_threshold
|
@@ -229,7 +230,7 @@ class Chosen extends AbstractChosen
|
|
229
230
|
results_show: ->
|
230
231
|
if @result_single_selected?
|
231
232
|
this.result_do_highlight @result_single_selected
|
232
|
-
else if @is_multiple and @max_selected_options <=
|
233
|
+
else if @is_multiple and @max_selected_options <= this.choices_count()
|
233
234
|
@form_field_jq.trigger("liszt:maxselected", {chosen: this})
|
234
235
|
return false
|
235
236
|
|
@@ -261,13 +262,13 @@ class Chosen extends AbstractChosen
|
|
261
262
|
set_label_behavior: ->
|
262
263
|
@form_field_label = @form_field_jq.parents("label") # first check for a parent label
|
263
264
|
if not @form_field_label.length and @form_field.id.length
|
264
|
-
@form_field_label = $("label[for
|
265
|
+
@form_field_label = $("label[for='#{@form_field.id}']") #next check for a for=#{id}
|
265
266
|
|
266
267
|
if @form_field_label.length > 0
|
267
268
|
@form_field_label.click (evt) => if @is_multiple then this.container_mousedown(evt) else this.activate_field()
|
268
269
|
|
269
270
|
show_search_field_default: ->
|
270
|
-
if @is_multiple and
|
271
|
+
if @is_multiple and this.choices_count() < 1 and not @active_field
|
271
272
|
@search_field.val(@default_text)
|
272
273
|
@search_field.addClass "default"
|
273
274
|
else
|
@@ -289,18 +290,16 @@ class Chosen extends AbstractChosen
|
|
289
290
|
this.result_clear_highlight() if $(evt.target).hasClass "active-result" or $(evt.target).parents('.active-result').first()
|
290
291
|
|
291
292
|
choice_build: (item) ->
|
292
|
-
|
293
|
-
|
294
|
-
return false # fire event
|
295
|
-
choice_id = @container_id + "_c_" + item.array_index
|
296
|
-
@choices += 1
|
293
|
+
choice = $('<li />', { class: "search-choice" }).html("<span>#{item.html}</span>")
|
294
|
+
|
297
295
|
if item.disabled
|
298
|
-
|
296
|
+
choice.addClass 'search-choice-disabled'
|
299
297
|
else
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
298
|
+
close_link = $('<a />', { href: '#', class: 'search-choice-close', rel: item.array_index })
|
299
|
+
close_link.click (evt) => this.choice_destroy_link_click(evt)
|
300
|
+
choice.append close_link
|
301
|
+
|
302
|
+
@search_container.before choice
|
304
303
|
|
305
304
|
choice_destroy_link_click: (evt) ->
|
306
305
|
evt.preventDefault()
|
@@ -309,10 +308,9 @@ class Chosen extends AbstractChosen
|
|
309
308
|
|
310
309
|
choice_destroy: (link) ->
|
311
310
|
if this.result_deselect (link.attr "rel")
|
312
|
-
@choices -= 1
|
313
311
|
this.show_search_field_default()
|
314
312
|
|
315
|
-
this.results_hide() if @is_multiple and
|
313
|
+
this.results_hide() if @is_multiple and this.choices_count() > 0 and @search_field.val().length < 1
|
316
314
|
|
317
315
|
link.parents('li').first().remove()
|
318
316
|
|
@@ -320,6 +318,7 @@ class Chosen extends AbstractChosen
|
|
320
318
|
|
321
319
|
results_reset: ->
|
322
320
|
@form_field.options[0].selected = true
|
321
|
+
@selected_option_count = null
|
323
322
|
@selected_item.find("span").text @default_text
|
324
323
|
@selected_item.addClass("chzn-default") if not @is_multiple
|
325
324
|
this.show_search_field_default()
|
@@ -338,6 +337,10 @@ class Chosen extends AbstractChosen
|
|
338
337
|
|
339
338
|
this.result_clear_highlight()
|
340
339
|
|
340
|
+
if @is_multiple and @max_selected_options <= this.choices_count()
|
341
|
+
@form_field_jq.trigger("liszt:maxselected", {chosen: this})
|
342
|
+
return false
|
343
|
+
|
341
344
|
if @is_multiple
|
342
345
|
this.result_deactivate high
|
343
346
|
else
|
@@ -352,6 +355,7 @@ class Chosen extends AbstractChosen
|
|
352
355
|
item.selected = true
|
353
356
|
|
354
357
|
@form_field.options[item.options_index].selected = true
|
358
|
+
@selected_option_count = null
|
355
359
|
|
356
360
|
if @is_multiple
|
357
361
|
this.choice_build item
|
@@ -380,6 +384,8 @@ class Chosen extends AbstractChosen
|
|
380
384
|
result_data.selected = false
|
381
385
|
|
382
386
|
@form_field.options[result_data.options_index].selected = false
|
387
|
+
@selected_option_count = null
|
388
|
+
|
383
389
|
result = $("#" + @container_id + "_o_" + pos)
|
384
390
|
result.removeClass("result-selected").addClass("active-result").show()
|
385
391
|
|
@@ -494,7 +500,7 @@ class Chosen extends AbstractChosen
|
|
494
500
|
if prev_sibs.length
|
495
501
|
this.result_do_highlight prev_sibs.first()
|
496
502
|
else
|
497
|
-
this.results_hide() if
|
503
|
+
this.results_hide() if this.choices_count() > 0
|
498
504
|
this.result_clear_highlight()
|
499
505
|
|
500
506
|
keydown_backstroke: ->
|
@@ -19,8 +19,6 @@ class Chosen extends AbstractChosen
|
|
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"><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"><ul class="chzn-results"></ul></div>')
|
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>')
|
24
22
|
@no_results_temp = new Template('<li class="no-results">' + @results_none_found + ' "<span>#{terms}</span>"</li>')
|
25
23
|
|
26
24
|
set_up_html: ->
|
@@ -154,11 +152,12 @@ class Chosen extends AbstractChosen
|
|
154
152
|
|
155
153
|
results_build: ->
|
156
154
|
@parsing = true
|
155
|
+
@selected_option_count = null
|
156
|
+
|
157
157
|
@results_data = root.SelectParser.select_to_array @form_field
|
158
158
|
|
159
|
-
if @is_multiple and
|
159
|
+
if @is_multiple and this.choices_count() > 0
|
160
160
|
@search_choices.select("li.search-choice").invoke("remove")
|
161
|
-
@choices = 0
|
162
161
|
else if not @is_multiple
|
163
162
|
@selected_item.addClassName("chzn-default").down("span").update(@default_text)
|
164
163
|
if @disable_search or @form_field.options.length <= @disable_search_threshold
|
@@ -203,7 +202,7 @@ class Chosen extends AbstractChosen
|
|
203
202
|
visible_top = @search_results.scrollTop
|
204
203
|
visible_bottom = maxHeight + visible_top
|
205
204
|
|
206
|
-
high_top = @result_highlight.positionedOffset().top
|
205
|
+
high_top = @result_highlight.positionedOffset().top + @search_results.scrollTop
|
207
206
|
high_bottom = high_top + @result_highlight.getHeight()
|
208
207
|
|
209
208
|
if high_bottom >= visible_bottom
|
@@ -218,7 +217,7 @@ class Chosen extends AbstractChosen
|
|
218
217
|
results_show: ->
|
219
218
|
if @result_single_selected?
|
220
219
|
this.result_do_highlight @result_single_selected
|
221
|
-
else if @is_multiple and @max_selected_options <=
|
220
|
+
else if @is_multiple and @max_selected_options <= this.choices_count()
|
222
221
|
@form_field.fire("liszt:maxselected", {chosen: this})
|
223
222
|
return false
|
224
223
|
|
@@ -250,13 +249,13 @@ class Chosen extends AbstractChosen
|
|
250
249
|
set_label_behavior: ->
|
251
250
|
@form_field_label = @form_field.up("label") # first check for a parent label
|
252
251
|
if not @form_field_label?
|
253
|
-
@form_field_label = $$("label[for
|
252
|
+
@form_field_label = $$("label[for='#{@form_field.id}']").first() #next check for a for=#{id}
|
254
253
|
|
255
254
|
if @form_field_label?
|
256
255
|
@form_field_label.observe "click", (evt) => if @is_multiple then this.container_mousedown(evt) else this.activate_field()
|
257
256
|
|
258
257
|
show_search_field_default: ->
|
259
|
-
if @is_multiple and
|
258
|
+
if @is_multiple and this.choices_count() < 1 and not @active_field
|
260
259
|
@search_field.value = @default_text
|
261
260
|
@search_field.addClassName "default"
|
262
261
|
else
|
@@ -278,19 +277,16 @@ class Chosen extends AbstractChosen
|
|
278
277
|
this.result_clear_highlight() if evt.target.hasClassName('active-result') or evt.target.up('.active-result')
|
279
278
|
|
280
279
|
choice_build: (item) ->
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
if not item.disabled
|
292
|
-
link = $(choice_id).down('a')
|
293
|
-
link.observe "click", (evt) => this.choice_destroy_link_click(evt)
|
280
|
+
choice = new Element('li', { class: "search-choice" }).update("<span>#{item.html}</span>")
|
281
|
+
|
282
|
+
if item.disabled
|
283
|
+
choice.addClassName 'search-choice-disabled'
|
284
|
+
else
|
285
|
+
close_link = new Element('a', { href: '#', class: 'search-choice-close', rel: item.array_index })
|
286
|
+
close_link.observe "click", (evt) => this.choice_destroy_link_click(evt)
|
287
|
+
choice.insert close_link
|
288
|
+
|
289
|
+
@search_container.insert { before: choice }
|
294
290
|
|
295
291
|
choice_destroy_link_click: (evt) ->
|
296
292
|
evt.preventDefault()
|
@@ -299,10 +295,9 @@ class Chosen extends AbstractChosen
|
|
299
295
|
|
300
296
|
choice_destroy: (link) ->
|
301
297
|
if this.result_deselect link.readAttribute("rel")
|
302
|
-
@choices -= 1
|
303
298
|
this.show_search_field_default()
|
304
299
|
|
305
|
-
this.results_hide() if @is_multiple and
|
300
|
+
this.results_hide() if @is_multiple and this.choices_count() > 0 and @search_field.value.length < 1
|
306
301
|
|
307
302
|
link.up('li').remove()
|
308
303
|
|
@@ -310,6 +305,7 @@ class Chosen extends AbstractChosen
|
|
310
305
|
|
311
306
|
results_reset: ->
|
312
307
|
@form_field.options[0].selected = true
|
308
|
+
@selected_option_count = null
|
313
309
|
@selected_item.down("span").update(@default_text)
|
314
310
|
@selected_item.addClassName("chzn-default") if not @is_multiple
|
315
311
|
this.show_search_field_default()
|
@@ -327,6 +323,10 @@ class Chosen extends AbstractChosen
|
|
327
323
|
high = @result_highlight
|
328
324
|
this.result_clear_highlight()
|
329
325
|
|
326
|
+
if @is_multiple and @max_selected_options <= this.choices_count()
|
327
|
+
@form_field.fire("liszt:maxselected", {chosen: this})
|
328
|
+
return false
|
329
|
+
|
330
330
|
if @is_multiple
|
331
331
|
this.result_deactivate high
|
332
332
|
else
|
@@ -341,6 +341,7 @@ class Chosen extends AbstractChosen
|
|
341
341
|
item.selected = true
|
342
342
|
|
343
343
|
@form_field.options[item.options_index].selected = true
|
344
|
+
@selected_option_count = null
|
344
345
|
|
345
346
|
if @is_multiple
|
346
347
|
this.choice_build item
|
@@ -370,6 +371,8 @@ class Chosen extends AbstractChosen
|
|
370
371
|
result_data.selected = false
|
371
372
|
|
372
373
|
@form_field.options[result_data.options_index].selected = false
|
374
|
+
@selected_option_count = null
|
375
|
+
|
373
376
|
result = $(@container_id + "_o_" + pos)
|
374
377
|
result.removeClassName("result-selected").addClassName("active-result").show()
|
375
378
|
|
@@ -488,7 +491,7 @@ class Chosen extends AbstractChosen
|
|
488
491
|
if prevs.length
|
489
492
|
this.result_do_highlight prevs.first()
|
490
493
|
else
|
491
|
-
this.results_hide() if
|
494
|
+
this.results_hide() if this.choices_count() > 0
|
492
495
|
this.result_clear_highlight()
|
493
496
|
|
494
497
|
keydown_backstroke: ->
|
@@ -32,7 +32,6 @@ class AbstractChosen
|
|
32
32
|
@disable_search = @options.disable_search || false
|
33
33
|
@enable_split_word_search = if @options.enable_split_word_search? then @options.enable_split_word_search else true
|
34
34
|
@search_contains = @options.search_contains || false
|
35
|
-
@choices = 0
|
36
35
|
@single_backstroke_delete = @options.single_backstroke_delete || false
|
37
36
|
@max_selected_options = @options.max_selected_options || Infinity
|
38
37
|
@inherit_select_classes = @options.inherit_select_classes || false
|
@@ -95,6 +94,15 @@ class AbstractChosen
|
|
95
94
|
else
|
96
95
|
this.results_show()
|
97
96
|
|
97
|
+
choices_count: ->
|
98
|
+
return @selected_option_count if @selected_option_count?
|
99
|
+
|
100
|
+
@selected_option_count = 0
|
101
|
+
for option in @form_field.options
|
102
|
+
@selected_option_count += 1 if option.selected
|
103
|
+
|
104
|
+
return @selected_option_count
|
105
|
+
|
98
106
|
choices_click: (evt) ->
|
99
107
|
evt.preventDefault()
|
100
108
|
this.results_show() unless @results_showing
|
@@ -105,7 +113,7 @@ class AbstractChosen
|
|
105
113
|
|
106
114
|
switch stroke
|
107
115
|
when 8
|
108
|
-
if @is_multiple and @backstroke_length < 1 and
|
116
|
+
if @is_multiple and @backstroke_length < 1 and this.choices_count() > 0
|
109
117
|
this.keydown_backstroke()
|
110
118
|
else if not @pending_backstroke
|
111
119
|
this.result_clear_highlight()
|
@@ -131,16 +139,7 @@ class AbstractChosen
|
|
131
139
|
newchar = chars.substring rand, rand+1
|
132
140
|
|
133
141
|
container_width: ->
|
134
|
-
return @options.width
|
135
|
-
|
136
|
-
width = if window.getComputedStyle?
|
137
|
-
parseFloat window.getComputedStyle(@form_field).getPropertyValue('width')
|
138
|
-
else if jQuery? and @form_field_jq?
|
139
|
-
@form_field_jq.outerWidth()
|
140
|
-
else
|
141
|
-
@form_field.getWidth()
|
142
|
-
|
143
|
-
width + "px"
|
142
|
+
return if @options.width? then @options.width else "#{@form_field.offsetWidth}px"
|
144
143
|
|
145
144
|
# class methods and variables ============================================================
|
146
145
|
|
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.9.
|
4
|
+
version: 0.9.15
|
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-
|
11
|
+
date: 2013-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -142,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
142
|
version: '0'
|
143
143
|
requirements: []
|
144
144
|
rubyforge_project:
|
145
|
-
rubygems_version: 2.0.
|
145
|
+
rubygems_version: 2.0.3
|
146
146
|
signing_key:
|
147
147
|
specification_version: 4
|
148
148
|
summary: Integrate Chosen javascript library with Rails asset pipeline
|