simple_form-dropdown_select 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -0
- data/LICENSE.md +20 -0
- data/README.md +34 -0
- data/app/assets/javascripts/simple_form/dropdown_select.js.coffee +38 -0
- data/app/assets/stylesheets/simple_form/dropdown_select.styl +25 -0
- data/app/inputs/dropdown_select_input.rb +27 -0
- data/lib/simple_form/dropdown_select.rb +6 -0
- data/lib/simple_form/dropdown_select/engine.rb +7 -0
- data/lib/simple_form/dropdown_select/version.rb +5 -0
- data/simple_form-dropdown_select.gemspec +28 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 02ed5c18bd74d61670d3a97c0a4ec1471de714a4
|
4
|
+
data.tar.gz: 6a01cd87f9a1a94884c62dd07f7b8624dcf8f22f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fcc8b217c7c8ddfaa01b941b316a461910b93ba4bb72f5050db20c1aeec42897ebc9ad24f6a8efbf4340c19741b9339e626d97229afc5e21307f80d1ccc73567
|
7
|
+
data.tar.gz: 662c244c6f738bce408e7139fed0114084d9df79e60ddc3e78660f5609fe832696adc281165ef305c5959f7039fc5eb9b64bc5cd44aec88babb33c5a38725ac7
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.1
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 Department of Better Technology
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
Simple Form - Dropdown Select Input
|
2
|
+
=======
|
3
|
+
|
4
|
+
## Dependencies
|
5
|
+
- Coffeescript
|
6
|
+
- Stylus
|
7
|
+
- jQuery
|
8
|
+
- Simple Form
|
9
|
+
- Bootstrap-dropdown v3
|
10
|
+
|
11
|
+
## Use it
|
12
|
+
|
13
|
+
### In your forms
|
14
|
+
```ruby
|
15
|
+
simple_form_for :foo do |f|
|
16
|
+
f.input :employees,
|
17
|
+
as: :dropdown_select,
|
18
|
+
collection: [['Adam', :adam, 'The developer of this gem.'],
|
19
|
+
['Blue', :blue, 'Blue is a nice color, in case you were wondering.']]
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
### application.js
|
24
|
+
```
|
25
|
+
//= require simple_form-dropdown_select_input
|
26
|
+
```
|
27
|
+
|
28
|
+
### application.css
|
29
|
+
```
|
30
|
+
*= require simple_form-dropdown_select_input
|
31
|
+
```
|
32
|
+
|
33
|
+
## Notes
|
34
|
+
Currently does not allow `include_blank`.
|
@@ -0,0 +1,38 @@
|
|
1
|
+
(($, window) ->
|
2
|
+
|
3
|
+
class DropdownSelectInput
|
4
|
+
defaults: {}
|
5
|
+
|
6
|
+
constructor: ($el, options) ->
|
7
|
+
@options = $.extend({}, @defaults, options)
|
8
|
+
@$el = $el
|
9
|
+
@$input = $el.find('input')
|
10
|
+
@$toggle = $el.find('.dropdown_toggle_button')
|
11
|
+
|
12
|
+
@$el.on 'click', 'a[data-value]', (e) =>
|
13
|
+
$a = $(e.currentTarget)
|
14
|
+
|
15
|
+
@$input.val($a.data('value'))
|
16
|
+
.trigger('input')
|
17
|
+
.trigger('change')
|
18
|
+
|
19
|
+
$a.closest('li')
|
20
|
+
.addClass('active')
|
21
|
+
.siblings()
|
22
|
+
.removeClass('active')
|
23
|
+
|
24
|
+
@$toggle.text($a.find('.dropdown_select_input_title').text())
|
25
|
+
|
26
|
+
$.fn.extend dropdownSelectInput: (option, args...) ->
|
27
|
+
@each ->
|
28
|
+
data = $(@).data('dropdown-select-input')
|
29
|
+
|
30
|
+
if !data
|
31
|
+
$(@).data 'dropdown-select-input', (data = new DropdownSelectInput($(@), option))
|
32
|
+
if typeof option == 'string'
|
33
|
+
data[option].apply(data, args)
|
34
|
+
|
35
|
+
) window.jQuery, window
|
36
|
+
|
37
|
+
$ ->
|
38
|
+
$(".dropdown_select_input").dropdownSelectInput()
|
@@ -0,0 +1,25 @@
|
|
1
|
+
.dropdown_select_input
|
2
|
+
.dropdown_toggle_button
|
3
|
+
width 240px
|
4
|
+
|
5
|
+
.dropdown_menu
|
6
|
+
width 300px
|
7
|
+
|
8
|
+
li
|
9
|
+
a
|
10
|
+
white-space normal
|
11
|
+
padding 6px 10px 6px 20px
|
12
|
+
|
13
|
+
a:hover, &.active a
|
14
|
+
.dropdown_select_input_description
|
15
|
+
color #e5e5e5
|
16
|
+
|
17
|
+
.dropdown_select_input_title
|
18
|
+
font-weight 600
|
19
|
+
display block
|
20
|
+
|
21
|
+
.dropdown_select_input_description
|
22
|
+
display block
|
23
|
+
color #aaa
|
24
|
+
font-size 0.9rem
|
25
|
+
line-height 1.3
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class DropdownSelectInput < SimpleForm::Inputs::CollectionInput
|
2
|
+
|
3
|
+
include ActionView::Helpers::TagHelper
|
4
|
+
include ActionView::Context
|
5
|
+
|
6
|
+
def selected_option
|
7
|
+
collection.find { |x| x[1] == object.send(attribute_name) }
|
8
|
+
end
|
9
|
+
|
10
|
+
def input
|
11
|
+
content_tag(:span, class: 'dropdown dropdown_select_input') do
|
12
|
+
@builder.hidden_field(attribute_name, input_html_options) +
|
13
|
+
content_tag(:a, class: 'dropdown_toggle_button', 'data-toggle' => 'dropdown') { selected_option[0] } +
|
14
|
+
content_tag(:ul, class: 'dropdown_menu') {
|
15
|
+
collection.map do |x|
|
16
|
+
content_tag(:li, class: selected_option == x ? 'active' : nil) {
|
17
|
+
content_tag(:a, 'data-value' => x[1]) {
|
18
|
+
content_tag(:span, class: 'dropdown_select_input_title') { x[0] } +
|
19
|
+
content_tag(:span, class: 'dropdown_select_input_description') { x[2] }
|
20
|
+
}
|
21
|
+
}
|
22
|
+
end.join('').html_safe
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
# Maintain your gem's version:
|
4
|
+
require "simple_form/dropdown_select/version"
|
5
|
+
|
6
|
+
# Describe your gem and declare its dependencies:
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "simple_form-dropdown_select"
|
9
|
+
s.version = SimpleForm::DropdownSelect::VERSION
|
10
|
+
|
11
|
+
s.required_ruby_version = Gem::Requirement.new('>= 2.0.0')
|
12
|
+
s.authors = ['Adam Becker']
|
13
|
+
s.summary = 'A more powerful dropdown input for Simple Form.'
|
14
|
+
s.description = 'Using the power of not-actually-a-select element, each option in this ' +
|
15
|
+
'dropdown can have helper text associated with it.'
|
16
|
+
s.email = 'adam@dobt.co'
|
17
|
+
s.license = 'MIT'
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {features,spec}/*`.split("\n")
|
21
|
+
|
22
|
+
s.homepage = 'http://github.com/dobtco/simple_form-dropdown_select_input'
|
23
|
+
|
24
|
+
s.add_dependency 'coffee-script'
|
25
|
+
s.add_dependency 'rspec-rails'
|
26
|
+
s.add_dependency 'simple_form'
|
27
|
+
s.add_dependency 'stylus'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_form-dropdown_select
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Becker
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: coffee-script
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: simple_form
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: stylus
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Using the power of not-actually-a-select element, each option in this
|
70
|
+
dropdown can have helper text associated with it.
|
71
|
+
email: adam@dobt.co
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".ruby-version"
|
78
|
+
- Gemfile
|
79
|
+
- Gemfile.lock
|
80
|
+
- LICENSE.md
|
81
|
+
- README.md
|
82
|
+
- app/assets/javascripts/simple_form/dropdown_select.js.coffee
|
83
|
+
- app/assets/stylesheets/simple_form/dropdown_select.styl
|
84
|
+
- app/inputs/dropdown_select_input.rb
|
85
|
+
- lib/simple_form/dropdown_select.rb
|
86
|
+
- lib/simple_form/dropdown_select/engine.rb
|
87
|
+
- lib/simple_form/dropdown_select/version.rb
|
88
|
+
- simple_form-dropdown_select.gemspec
|
89
|
+
homepage: http://github.com/dobtco/simple_form-dropdown_select_input
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 2.0.0
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.2.2
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: A more powerful dropdown input for Simple Form.
|
113
|
+
test_files: []
|