selectivity-rails 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +129 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/selectivity.pl_PL.js.coffee +21 -0
- data/app/assets/stylesheets/selectivity_bootstrap.sass +35 -0
- data/lib/selectivity/rails/version.rb +5 -0
- data/lib/selectivity/rails.rb +8 -0
- data/lib/selectivity/rspec.rb +52 -0
- data/selectivity-rails.gemspec +24 -0
- data/vendor/assets/javascripts/selectivity.js +4619 -0
- data/vendor/assets/stylesheets/selectivity/backdrop.sass +12 -0
- data/vendor/assets/stylesheets/selectivity/base.sass +23 -0
- data/vendor/assets/stylesheets/selectivity/dropdown.sass +59 -0
- data/vendor/assets/stylesheets/selectivity/multiple.sass +64 -0
- data/vendor/assets/stylesheets/selectivity/single.sass +50 -0
- data/vendor/assets/stylesheets/selectivity/submenu.sass +7 -0
- data/vendor/assets/stylesheets/selectivity/variables.sass +16 -0
- data/vendor/assets/stylesheets/selectivity.sass +7 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d55b130f5ccc4b4b46143ad0eaf3e4a91f925a91
|
4
|
+
data.tar.gz: 97671a18859e10e389ed69b381b78e9545f6cd71
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b7ede2a49f84d147f0777b0a69c3a43b93d76f868a60ce94ee7d4e04f515cfc2cb4db73e0c0fde60c5937a493536d440d7d2721fc4f7f502b7c8f34fc4c82fc2
|
7
|
+
data.tar.gz: c804cba7768ba36207328678d78d098f3ccb664cbbefc8fd43486c6d8726254fe413ca454d1b3bf1884d2badf6757a66981ae14441c756bbae6e5f887ed30017
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Konrad Jurkowski
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/selectivity-rails.svg)](http://badge.fury.io/rb/selectivity-rails)
|
2
|
+
[![Code Climate](https://codeclimate.com/github/msx2/selectivity-rails/badges/gpa.svg)](https://codeclimate.com/github/msx2/selectivity-rails)
|
3
|
+
|
4
|
+
# Selectivity.js for Rails' Asset Pipeline
|
5
|
+
|
6
|
+
[Selectivity.js](https://github.com/arendjr/selectivity) is a modular and light-weight selection library for jQuery and Zepto.js.
|
7
|
+
|
8
|
+
## Installation and usage
|
9
|
+
|
10
|
+
Add `selectivity-rails` to Gemfile of your Rails application and run `bundle install`:
|
11
|
+
|
12
|
+
```
|
13
|
+
gem 'selectivity-rails'
|
14
|
+
```
|
15
|
+
|
16
|
+
### JavaScript
|
17
|
+
Add the following to your JavaScript manifest, by default `app/assets/javascripts/application.js`:
|
18
|
+
|
19
|
+
```javascript
|
20
|
+
//= require selectivity
|
21
|
+
```
|
22
|
+
|
23
|
+
#### Internationalization (i18n)
|
24
|
+
Selectivity.js uses English by default, however `selectivity-rails` supports multiple languages. Add the following to your JavaScript manifest, e.g. `app/assets/javascripts/application.js`:
|
25
|
+
|
26
|
+
```javascript
|
27
|
+
//= require selectivity.xx
|
28
|
+
```
|
29
|
+
|
30
|
+
where `xx` is the code of supported language. Currently supported are:
|
31
|
+
|
32
|
+
Code | Language
|
33
|
+
--- | ---
|
34
|
+
`pl_PL` | Polish
|
35
|
+
|
36
|
+
I18n file should be included **after** default `selectivity` script.
|
37
|
+
|
38
|
+
### Stylesheets
|
39
|
+
Add the following to your stylesheet manifest, by default `app/assets/stylesheets/application.sass`:
|
40
|
+
|
41
|
+
```sass
|
42
|
+
@import 'selectivity'
|
43
|
+
```
|
44
|
+
|
45
|
+
If you use `application.css` default format, you might not be able to access mixins or variables. Use `.scss` or `.sass` syntax instead.
|
46
|
+
|
47
|
+
For the basic styling supporting [`simple_form`](https://github.com/plataformatec/simple_form) and [Bootstrap](http://getbootstrap.com), import also `selectivity_bootstrap` stylesheet:
|
48
|
+
|
49
|
+
```sass
|
50
|
+
@import 'selectivity'
|
51
|
+
@import 'selectivity_bootstrap'
|
52
|
+
```
|
53
|
+
|
54
|
+
#### Customization
|
55
|
+
Selectivity.js is written in Sass and allows basic customization. For the list of all supported variables refer to [selectivity/variables.sass](https://github.com/msx2/selectivity-rails/blob/master/vendor/assets/stylesheets/selectivity/variables.sass)
|
56
|
+
|
57
|
+
To use customization, import your `variables` file before `selectivity`:
|
58
|
+
|
59
|
+
```sass
|
60
|
+
@import 'variables'
|
61
|
+
@import 'selectivity'
|
62
|
+
```
|
63
|
+
|
64
|
+
#### Icons: Font Awesome
|
65
|
+
By default, Selectivity.js uses [Font Awesome](http://fortawesome.github.io/Font-Awesome) icons.
|
66
|
+
|
67
|
+
If you don't use Font Awesome, you can install [`font-awesome-rails`](https://github.com/bokmann/font-awesome-rails) gem, or manually override styling for following CSS classes:
|
68
|
+
|
69
|
+
```sass
|
70
|
+
.fa.fa-remove
|
71
|
+
.fa.fa-chevron-right
|
72
|
+
.fa.fa-sort-desc
|
73
|
+
```
|
74
|
+
|
75
|
+
## RSpec helpers
|
76
|
+
`selectivity-rails` provides RSpec feature helper methods that allow user to select or unselect elements from both single and multiple select elements. Add the following to your `spec/rails_helper.rb` (or `spec/spec_helper.rb`):
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
require 'selectivity/rspec'
|
80
|
+
```
|
81
|
+
|
82
|
+
This automatically configures RSpec by adding:
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
RSpec.configure do |config|
|
86
|
+
config.include Selectivity::Rspec::FeatureHelpers, type: :feature, js: true
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
Configuration includes two additional methods for all `type: :feature, js: true` specs:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
selectivity_select(value, options = {})
|
94
|
+
selectivity_unselect(value, options = {})
|
95
|
+
```
|
96
|
+
|
97
|
+
Both methods require `from: '...'` inside `options` hash.
|
98
|
+
|
99
|
+
### Example usage
|
100
|
+
To handle single select:
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
selectivity_select('Netherlands', from: '#country')
|
104
|
+
selectivity_unselect('Netherlands', from: '#country')
|
105
|
+
selectivity_select('Poland', from: '#country')
|
106
|
+
```
|
107
|
+
|
108
|
+
To handle multiple select:
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
selectivity_select('Netherlands', from: '#countries')
|
112
|
+
selectivity_select('Poland', from: '#countries')
|
113
|
+
selectivity_select('Russia', from: '#countries')
|
114
|
+
selectivity_unselect('Russia', from: '#countries')
|
115
|
+
```
|
116
|
+
|
117
|
+
## Demos and examples
|
118
|
+
For detailed information on Selectivity.js possibilities and behavior, visit:
|
119
|
+
|
120
|
+
* [Selectivity.js repository](https://github.com/arendjr/selectivity)
|
121
|
+
* [Selectibity.js gh-page](https://arendjr.github.io/selectivity)
|
122
|
+
|
123
|
+
## Contributing
|
124
|
+
|
125
|
+
1. Fork it
|
126
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
127
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
128
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
129
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
$(document).on 'ready page:load', ->
|
2
|
+
$.fn.selectivity.Locale =
|
3
|
+
ajaxError: (term) -> "Nie udało się pobrać wyników dla <b>#{escape(term)}</b>"
|
4
|
+
loading: 'Ładowanie...'
|
5
|
+
loadMore: 'Więcej...'
|
6
|
+
needMoreCharacters: (numCharacters) -> "Wpisz jeszcze #{word_pluralize(numCharacters, 'znak', 'znaki', 'znaków')}"
|
7
|
+
noResults: 'Brak wyników'
|
8
|
+
noResultsForTerm: (term) -> "Brak wyników dla <b>#{escape(term)}</b>"
|
9
|
+
|
10
|
+
|
11
|
+
word_pluralize = (number, wordSingle, wordFew, wordMany) ->
|
12
|
+
number = Number(number)
|
13
|
+
|
14
|
+
word = if number == 0 then wordMany
|
15
|
+
else if number == 1 then wordSingle
|
16
|
+
else if (number % 10) >= 2 && (number % 10) <= 4 && (number <= 10 || number >= 20)
|
17
|
+
wordFew
|
18
|
+
else
|
19
|
+
wordMany
|
20
|
+
|
21
|
+
"#{number} #{word}"
|
@@ -0,0 +1,35 @@
|
|
1
|
+
$border-radius-base: 4px !default
|
2
|
+
|
3
|
+
$input-bg: #fff !default
|
4
|
+
$input-color: #555 !default
|
5
|
+
$input-border: #ccc !default
|
6
|
+
|
7
|
+
|
8
|
+
.form-control.selectivity-input
|
9
|
+
width: 100%
|
10
|
+
height: auto
|
11
|
+
display: block
|
12
|
+
padding: inherit
|
13
|
+
border-color: $input-border
|
14
|
+
border-radius: $border-radius-base
|
15
|
+
color: $input-color
|
16
|
+
background: $input-bg
|
17
|
+
|
18
|
+
.selectivity-multiple-input-container,
|
19
|
+
.selectivity-single-select
|
20
|
+
color: $input-color
|
21
|
+
background: $input-bg
|
22
|
+
|
23
|
+
.selectivity-multiple-input-container
|
24
|
+
padding: 0
|
25
|
+
|
26
|
+
.selectivity-single-select
|
27
|
+
padding: 2px
|
28
|
+
|
29
|
+
.selectivity-single-result-container,
|
30
|
+
.selectivity-caret
|
31
|
+
top: 0.5em
|
32
|
+
|
33
|
+
|
34
|
+
.selectivity-dropdown
|
35
|
+
margin-top: 2px
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Selectivity
|
2
|
+
module Rspec
|
3
|
+
module FeatureHelpers
|
4
|
+
|
5
|
+
def selectivity_select(value, options = {})
|
6
|
+
fail('Selectivity input not set!') unless options.has_key?(:from)
|
7
|
+
|
8
|
+
from = options.delete(:from)
|
9
|
+
|
10
|
+
find(:div, from, options).click
|
11
|
+
|
12
|
+
within 'div.selectivity-dropdown' do
|
13
|
+
first(:xpath, "//div[@class='selectivity-result-item'][contains(text(), '#{value}')]").click
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def selectivity_unselect(value, options = {})
|
18
|
+
fail('Selectivity input not set!') unless options.has_key?(:from)
|
19
|
+
|
20
|
+
from = options.delete(:from)
|
21
|
+
selectivity_input = find(:div, from, options)
|
22
|
+
|
23
|
+
if selectivity_multiselect?(selectivity_input)
|
24
|
+
unselect_multiple(selectivity_input, value)
|
25
|
+
else
|
26
|
+
unselect_single(selectivity_input)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def selectivity_multiselect?(input)
|
33
|
+
input.first('.selectivity-multiple-input-container').present?
|
34
|
+
end
|
35
|
+
|
36
|
+
def unselect_single(input)
|
37
|
+
input.first('.selectivity-single-selected-item-remove').click
|
38
|
+
end
|
39
|
+
|
40
|
+
def unselect_multiple(input, value)
|
41
|
+
input.first('.selectivity-multiple-selected-item', text: value)
|
42
|
+
.first('.selectivity-multiple-selected-item-remove')
|
43
|
+
.click
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
RSpec.configure do |config|
|
51
|
+
config.include Selectivity::Rspec::FeatureHelpers, type: :feature, js: true
|
52
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'selectivity/rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'selectivity-rails'
|
8
|
+
spec.version = Selectivity::Rails::VERSION
|
9
|
+
spec.authors = ['Konrad Jurkowski']
|
10
|
+
spec.email = ['konrad@jurkowski.me']
|
11
|
+
spec.description = %q{Selectivity.js is a modular and light-weight selection library for jQuery and Zepto.js. This gem integrates Selectivity.js with Ruby on Rails.}
|
12
|
+
spec.summary = %q{Integrate Selectivity.js with Ruby on Rails}
|
13
|
+
spec.homepage = 'https://github.com/msx2/selectivity-rails'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'rails', '>= 3.0'
|
24
|
+
end
|