chosen-rails 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +44 -24
- data/lib/chosen-rails/source_file.rb +1 -1
- data/lib/chosen-rails/version.rb +2 -2
- data/vendor/assets/javascripts/chosen.jquery.coffee +5 -3
- data/vendor/assets/javascripts/chosen.proto.coffee +4 -2
- data/vendor/assets/javascripts/lib/abstract-chosen.coffee +14 -1
- data/vendor/assets/javascripts/lib/select-parser.coffee +4 -1
- data/vendor/assets/stylesheets/{chosen.css.scss → chosen.scss} +17 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a00aed3e49a214127fe61ce7d78b31f490898af0
|
4
|
+
data.tar.gz: 5849a7c7fd0b0bf95e5a282555771f30cd175fee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 436778b889eb6341473da8452f60b33951d8415cbaf697322c63b799befc2ce37bbbce6910245e52624047cb7f2876ecea21c5ee4d57af64f9e2c8e9c0782222
|
7
|
+
data.tar.gz: d2c4efc81e654f3957fc647ad58771e9629910b2a5e7ace3fd92504d456c063df3bd5dff44a833662c3b26d6c314454a72673019eb164fac72d1ca59dcb8ec95
|
data/README.md
CHANGED
@@ -10,7 +10,9 @@ The `chosen-rails` gem integrates the `Chosen` with the Rails asset pipeline.
|
|
10
10
|
|
11
11
|
Include `chosen-rails` in Gemefile
|
12
12
|
|
13
|
-
|
13
|
+
```rb
|
14
|
+
gem 'chosen-rails'
|
15
|
+
```
|
14
16
|
|
15
17
|
Then run `bundle install`
|
16
18
|
|
@@ -18,51 +20,65 @@ Then run `bundle install`
|
|
18
20
|
|
19
21
|
Add to your `app/assets/javascripts/application.js` if use with jQuery
|
20
22
|
|
21
|
-
|
23
|
+
```coffee
|
24
|
+
//= require chosen-jquery
|
25
|
+
```
|
22
26
|
|
23
27
|
Or with Prototype
|
24
28
|
|
25
|
-
|
29
|
+
```coffee
|
30
|
+
//= require chosen-prototype
|
31
|
+
```
|
26
32
|
|
27
33
|
### Include chosen stylesheet assets
|
28
34
|
|
29
35
|
Add to your `app/assets/stylesheets/application.css`
|
30
36
|
|
31
|
-
|
37
|
+
```scss
|
38
|
+
*= require chosen
|
39
|
+
```
|
32
40
|
|
33
41
|
### Enable chosen javascript by specific css class
|
34
42
|
|
35
43
|
Add to one coffee script file, like `scaffold.js.coffee`
|
36
44
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
45
|
+
```coffee
|
46
|
+
$ ->
|
47
|
+
# enable chosen js
|
48
|
+
$('.chosen-select').chosen
|
49
|
+
allow_single_deselect: true
|
50
|
+
no_results_text: 'No results matched'
|
51
|
+
width: '200px'
|
52
|
+
```
|
43
53
|
|
44
54
|
Notice: `width` option is required since `Chosen 0.9.15`.
|
45
55
|
|
46
56
|
And this file must be included in `application.js`
|
47
57
|
|
48
|
-
|
49
|
-
|
58
|
+
```coffee
|
59
|
+
//= require chosen-jquery
|
60
|
+
//= require scaffold
|
61
|
+
```
|
50
62
|
|
51
63
|
Also add the class to your form field
|
52
64
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
65
|
+
```erb
|
66
|
+
<%= f.select :author,
|
67
|
+
User.all.map { |u| [u.name, u.id] },
|
68
|
+
{ include_blank: true },
|
69
|
+
{ class: 'chosen-select' }
|
70
|
+
%>
|
71
|
+
```
|
58
72
|
|
59
73
|
If you use simple form as form builder
|
60
74
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
75
|
+
```erb
|
76
|
+
<%= f.association :author,
|
77
|
+
collection: User.all,
|
78
|
+
include_blank: true,
|
79
|
+
input_html: { class: 'chosen-select' }
|
80
|
+
%>
|
81
|
+
```
|
66
82
|
|
67
83
|
### Deployment
|
68
84
|
|
@@ -74,11 +90,15 @@ Maintain `chosen-rails` gem with `Rake` commands.
|
|
74
90
|
|
75
91
|
Update origin chosen source files.
|
76
92
|
|
77
|
-
|
93
|
+
```bash
|
94
|
+
rake update-chosen
|
95
|
+
```
|
78
96
|
|
79
97
|
Publish gem.
|
80
98
|
|
81
|
-
|
99
|
+
```bash
|
100
|
+
rake release
|
101
|
+
```
|
82
102
|
|
83
103
|
## License
|
84
104
|
|
@@ -9,7 +9,7 @@ class SourceFile < Thor
|
|
9
9
|
self.destination_root = 'vendor/assets'
|
10
10
|
get "#{remote}/raw/#{branch}/public/chosen-sprite.png", 'images/chosen-sprite.png'
|
11
11
|
get "#{remote}/raw/#{branch}/public/chosen-sprite@2x.png", 'images/chosen-sprite@2x.png'
|
12
|
-
get "#{remote}/raw/#{branch}/sass/chosen.scss", 'stylesheets/chosen.
|
12
|
+
get "#{remote}/raw/#{branch}/sass/chosen.scss", 'stylesheets/chosen.scss'
|
13
13
|
get "#{remote}/raw/#{branch}/coffee/lib/abstract-chosen.coffee", 'javascripts/lib/abstract-chosen.coffee'
|
14
14
|
get "#{remote}/raw/#{branch}/coffee/lib/select-parser.coffee", 'javascripts/lib/select-parser.coffee'
|
15
15
|
get "#{remote}/raw/#{branch}/coffee/chosen.jquery.coffee", 'javascripts/chosen.jquery.coffee'
|
data/lib/chosen-rails/version.rb
CHANGED
@@ -63,6 +63,8 @@ class Chosen extends AbstractChosen
|
|
63
63
|
this.results_build()
|
64
64
|
this.set_tab_index()
|
65
65
|
this.set_label_behavior()
|
66
|
+
|
67
|
+
on_ready: ->
|
66
68
|
@form_field_jq.trigger("chosen:ready", {chosen: this})
|
67
69
|
|
68
70
|
register_observers: ->
|
@@ -289,7 +291,7 @@ class Chosen extends AbstractChosen
|
|
289
291
|
this.result_clear_highlight() if $(evt.target).hasClass "active-result" or $(evt.target).parents('.active-result').first()
|
290
292
|
|
291
293
|
choice_build: (item) ->
|
292
|
-
choice = $('<li />', { class: "search-choice" }).html("<span>#{item
|
294
|
+
choice = $('<li />', { class: "search-choice" }).html("<span>#{this.choice_label(item)}</span>")
|
293
295
|
|
294
296
|
if item.disabled
|
295
297
|
choice.addClass 'search-choice-disabled'
|
@@ -352,7 +354,7 @@ class Chosen extends AbstractChosen
|
|
352
354
|
if @is_multiple
|
353
355
|
this.choice_build item
|
354
356
|
else
|
355
|
-
this.single_set_selected_text(item
|
357
|
+
this.single_set_selected_text(this.choice_label(item))
|
356
358
|
|
357
359
|
this.results_hide() unless (evt.metaKey or evt.ctrlKey) and @is_multiple
|
358
360
|
|
@@ -369,7 +371,7 @@ class Chosen extends AbstractChosen
|
|
369
371
|
this.single_deselect_control_build()
|
370
372
|
@selected_item.removeClass("chosen-default")
|
371
373
|
|
372
|
-
@selected_item.find("span").
|
374
|
+
@selected_item.find("span").html(text)
|
373
375
|
|
374
376
|
result_deselect: (pos) ->
|
375
377
|
result_data = @results_data[pos]
|
@@ -46,6 +46,8 @@ class @Chosen extends AbstractChosen
|
|
46
46
|
this.results_build()
|
47
47
|
this.set_tab_index()
|
48
48
|
this.set_label_behavior()
|
49
|
+
|
50
|
+
on_ready: ->
|
49
51
|
@form_field.fire("chosen:ready", {chosen: this})
|
50
52
|
|
51
53
|
register_observers: ->
|
@@ -282,7 +284,7 @@ class @Chosen extends AbstractChosen
|
|
282
284
|
this.result_clear_highlight() if evt.target.hasClassName('active-result') or evt.target.up('.active-result')
|
283
285
|
|
284
286
|
choice_build: (item) ->
|
285
|
-
choice = new Element('li', { class: "search-choice" }).update("<span>#{item
|
287
|
+
choice = new Element('li', { class: "search-choice" }).update("<span>#{this.choice_label(item)}</span>")
|
286
288
|
|
287
289
|
if item.disabled
|
288
290
|
choice.addClassName 'search-choice-disabled'
|
@@ -347,7 +349,7 @@ class @Chosen extends AbstractChosen
|
|
347
349
|
if @is_multiple
|
348
350
|
this.choice_build item
|
349
351
|
else
|
350
|
-
this.single_set_selected_text(item
|
352
|
+
this.single_set_selected_text(this.choice_label(item))
|
351
353
|
|
352
354
|
this.results_hide() unless (evt.metaKey or evt.ctrlKey) and @is_multiple
|
353
355
|
|
@@ -10,6 +10,8 @@ class AbstractChosen
|
|
10
10
|
|
11
11
|
this.set_up_html()
|
12
12
|
this.register_observers()
|
13
|
+
# instantiation done, fire ready
|
14
|
+
this.on_ready()
|
13
15
|
|
14
16
|
set_default_values: ->
|
15
17
|
@click_test_action = (evt) => this.test_active_click(evt)
|
@@ -29,6 +31,7 @@ class AbstractChosen
|
|
29
31
|
@inherit_select_classes = @options.inherit_select_classes || false
|
30
32
|
@display_selected_options = if @options.display_selected_options? then @options.display_selected_options else true
|
31
33
|
@display_disabled_options = if @options.display_disabled_options? then @options.display_disabled_options else true
|
34
|
+
@include_group_label_in_selected = @options.include_group_label_in_selected || false
|
32
35
|
|
33
36
|
set_default_text: ->
|
34
37
|
if @form_field.getAttribute("data-placeholder")
|
@@ -40,6 +43,12 @@ class AbstractChosen
|
|
40
43
|
|
41
44
|
@results_none_found = @form_field.getAttribute("data-no_results_text") || @options.no_results_text || AbstractChosen.default_no_result_text
|
42
45
|
|
46
|
+
choice_label: (item) ->
|
47
|
+
if @include_group_label_in_selected and item.group_label?
|
48
|
+
"<b class='group-name'>#{item.group_label}</b>#{item.html}"
|
49
|
+
else
|
50
|
+
item.html
|
51
|
+
|
43
52
|
mouse_enter: -> @mouse_on_container = true
|
44
53
|
mouse_leave: -> @mouse_on_container = false
|
45
54
|
|
@@ -95,8 +104,12 @@ class AbstractChosen
|
|
95
104
|
return '' unless group.search_match || group.group_match
|
96
105
|
return '' unless group.active_options > 0
|
97
106
|
|
107
|
+
classes = []
|
108
|
+
classes.push "group-result"
|
109
|
+
classes.push group.classes if group.classes
|
110
|
+
|
98
111
|
group_el = document.createElement("li")
|
99
|
-
group_el.className = "
|
112
|
+
group_el.className = classes.join(" ")
|
100
113
|
group_el.innerHTML = group.search_text
|
101
114
|
|
102
115
|
this.outerHTML(group_el)
|
@@ -17,7 +17,8 @@ class SelectParser
|
|
17
17
|
group: true
|
18
18
|
label: this.escapeExpression(group.label)
|
19
19
|
children: 0
|
20
|
-
disabled: group.disabled
|
20
|
+
disabled: group.disabled,
|
21
|
+
classes: group.className
|
21
22
|
this.add_option( option, group_position, group.disabled ) for option in group.childNodes
|
22
23
|
|
23
24
|
add_option: (option, group_position, group_disabled) ->
|
@@ -34,6 +35,7 @@ class SelectParser
|
|
34
35
|
selected: option.selected
|
35
36
|
disabled: if group_disabled is true then group_disabled else option.disabled
|
36
37
|
group_array_index: group_position
|
38
|
+
group_label: if group_position? then @parsed[group_position].label else null
|
37
39
|
classes: option.className
|
38
40
|
style: option.style.cssText
|
39
41
|
else
|
@@ -63,4 +65,5 @@ SelectParser.select_to_array = (select) ->
|
|
63
65
|
parser.add_node( child ) for child in select.childNodes
|
64
66
|
parser.parsed
|
65
67
|
|
68
|
+
|
66
69
|
window.SelectParser = SelectParser
|
@@ -34,6 +34,22 @@ $chosen-sprite-retina: image-url('chosen-sprite@2x.png') !default;
|
|
34
34
|
a{
|
35
35
|
cursor: pointer;
|
36
36
|
}
|
37
|
+
|
38
|
+
.search-choice, .chosen-single{
|
39
|
+
.group-name{
|
40
|
+
margin-right: 4px;
|
41
|
+
overflow: hidden;
|
42
|
+
white-space: nowrap;
|
43
|
+
text-overflow: ellipsis;
|
44
|
+
font-weight: normal;
|
45
|
+
color: #999999;
|
46
|
+
&:after {
|
47
|
+
content: ":";
|
48
|
+
padding-left: 2px;
|
49
|
+
vertical-align: top;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
37
53
|
}
|
38
54
|
/* @end */
|
39
55
|
|
@@ -401,7 +417,7 @@ $chosen-sprite-retina: image-url('chosen-sprite@2x.png') !default;
|
|
401
417
|
/* @end */
|
402
418
|
|
403
419
|
/* @group Retina compatibility */
|
404
|
-
@media only screen and (-webkit-min-device-pixel-ratio:
|
420
|
+
@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min-resolution: 144dpi), only screen and (min-resolution: 1.5dppx) {
|
405
421
|
.chosen-rtl .chosen-search input[type="text"],
|
406
422
|
.chosen-container-single .chosen-single abbr,
|
407
423
|
.chosen-container-single .chosen-single div b,
|
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: 1.
|
4
|
+
version: 1.3.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:
|
11
|
+
date: 2015-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -137,7 +137,7 @@ files:
|
|
137
137
|
- vendor/assets/javascripts/chosen.proto.coffee
|
138
138
|
- vendor/assets/javascripts/lib/abstract-chosen.coffee
|
139
139
|
- vendor/assets/javascripts/lib/select-parser.coffee
|
140
|
-
- vendor/assets/stylesheets/chosen.
|
140
|
+
- vendor/assets/stylesheets/chosen.scss
|
141
141
|
homepage: https://github.com/tsechingho/chosen-rails
|
142
142
|
licenses: []
|
143
143
|
metadata: {}
|