epi_js 1.0.1 → 1.0.2
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/README.md +17 -0
- data/lib/epi_js/version.rb +1 -1
- data/vendor/assets/javascripts/visibility_map.coffee +19 -11
- 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: 85946da973e194c5338ab9151db06cf6577a041d
|
4
|
+
data.tar.gz: 4c4164c02a4ffee89dc58fff07911a0e6d809218
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 747e9f051cdbde2fd52cc79d4c62662639c4a95ed4c282596a8522b470eb2d387fb470e98af3307902977130e0cf77d2bf8705c0fcfa33630c2dafb295e1625d
|
7
|
+
data.tar.gz: 27f9283424d00ef506df7fddab591b0f29bd93adca1fb80d02512451c1fd9b69f8fbaccc6cb870e48c0847ec79814e8fd01d675af5060224a444ce1a3e90abef
|
data/README.md
CHANGED
@@ -108,6 +108,23 @@ Or for SimpleForm, use:
|
|
108
108
|
|
109
109
|
When the value of the input element is `foo`, the element `#foo` will be visible and `#bar` will be hidden, and vice versa. The value of the JSON key value pair can be any jQuery selectors.
|
110
110
|
|
111
|
+
#### Other options
|
112
|
+
1. You can limit the scope of elements to hide / show by providing a JQuery selector as the `data-visibility-map-scope` attribute. Then only elements within the closest element of input matching the given selector will be affected, e.g.
|
113
|
+
|
114
|
+
.nested-fields
|
115
|
+
= f.input :some_select, input_html: {data: {visibility_map_scope: '.nested-fields', visibility_map: {foo: '.foo', bar: '.bar'}}}
|
116
|
+
.foo
|
117
|
+
.bar
|
118
|
+
|
119
|
+
.nested-fields
|
120
|
+
= f.input :some_select, input_html: {data: {visibility_map_scope: '.nested-fields', visibility_map: {foo: '.foo', bar: '.bar'}}}
|
121
|
+
.foo
|
122
|
+
.bar
|
123
|
+
|
124
|
+
When the value of the first select is set to `foo`, only the `.foo` in the first `.nested-fields` will be displayed
|
125
|
+
|
126
|
+
2. By setting the `data-visibility-map-action` attribute to `hide`, elements will be shown by default and only hidden when the given value is selected.
|
127
|
+
|
111
128
|
### Table filter
|
112
129
|
This allows you to filter out rows in a table based on an input field.
|
113
130
|
|
data/lib/epi_js/version.rb
CHANGED
@@ -3,20 +3,28 @@
|
|
3
3
|
class GenericVisibilityChecker
|
4
4
|
constructor: (element) ->
|
5
5
|
@element = element
|
6
|
-
@
|
7
|
-
@
|
6
|
+
@scope = @element.closest(@element.data('visibility-map-scope') ? document)
|
7
|
+
@action = @element.data('visibility-map-action') ? 'show'
|
8
|
+
@map = @element.data('visibility-map')
|
9
|
+
@allFields = $($.unique $.map @map, (val) => $(val, @scope).get())
|
8
10
|
|
9
11
|
check: ->
|
10
|
-
|
11
|
-
toHide = @allFields.not(toShow)
|
12
|
+
fieldsForValue = $ $.unique $.map @getValue(), (value) => $(@map[value], @scope).get()
|
12
13
|
|
13
|
-
|
14
|
-
toShow
|
15
|
-
|
16
|
-
|
17
|
-
toHide
|
18
|
-
|
19
|
-
|
14
|
+
if @action is 'show'
|
15
|
+
toShow = fieldsForValue
|
16
|
+
toHide = @allFields.not(fieldsForValue)
|
17
|
+
else
|
18
|
+
toHide = fieldsForValue
|
19
|
+
toShow = @allFields.not(fieldsForValue)
|
20
|
+
|
21
|
+
toShow.show()
|
22
|
+
toShow.trigger('visibility.show')
|
23
|
+
$(':input:not([data-visibility-map-no-auto-enable])', toShow).prop('disabled', false)
|
24
|
+
|
25
|
+
toHide.hide()
|
26
|
+
toHide.trigger('visibility.hide')
|
27
|
+
$(':input', toHide).prop('disabled', true)
|
20
28
|
|
21
29
|
getValue: ->
|
22
30
|
$.makeArray(@element.val())
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epi_js
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shuo Chen
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-04-
|
12
|
+
date: 2016-04-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
140
|
version: '0'
|
141
141
|
requirements: []
|
142
142
|
rubyforge_project:
|
143
|
-
rubygems_version: 2.
|
143
|
+
rubygems_version: 2.5.1
|
144
144
|
signing_key:
|
145
145
|
specification_version: 4
|
146
146
|
summary: jQuery scripts used in various projects
|