epi_js 1.0.1 → 1.0.2

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: c0ea0f23ad95d3bbe7fe2a10dad4b3a3c465f2f6
4
- data.tar.gz: 480cd8bd092bbba61b7e60bdd047eb45821fa27c
3
+ metadata.gz: 85946da973e194c5338ab9151db06cf6577a041d
4
+ data.tar.gz: 4c4164c02a4ffee89dc58fff07911a0e6d809218
5
5
  SHA512:
6
- metadata.gz: 177c29ef9d5e9fb26f2a70722a5eecf05b65ffa96fb1eafbd3cf3160321f4e24ceb869316d21b19ff8d3482584f2af79a195ff6f8d667e5131e2bff142dda7f0
7
- data.tar.gz: 84d07e1bf1caafc49c9d3ca690c5b516f661f725999ddacbc1157e19be30a140f0c7bca2d069f3d892acd5bdcac610968c3034339a0765eec76b543705410718
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
 
@@ -1,3 +1,3 @@
1
1
  module EpiJs
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -3,20 +3,28 @@
3
3
  class GenericVisibilityChecker
4
4
  constructor: (element) ->
5
5
  @element = element
6
- @map = @element.data('visibility-map')
7
- @allFields = $($.unique $.map @map, (val) -> $(val).get())
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
- toShow = $ $.unique $.map @getValue(), (value) => $(@map[value]).get()
11
- toHide = @allFields.not(toShow)
12
+ fieldsForValue = $ $.unique $.map @getValue(), (value) => $(@map[value], @scope).get()
12
13
 
13
- toShow.show()
14
- toShow.trigger('visibility.show')
15
- $(':input:not([data-visibility-map-no-auto-enable])', toShow).prop('disabled', false)
16
-
17
- toHide.hide()
18
- toHide.trigger('visibility.hide')
19
- $(':input', toHide).prop('disabled', true)
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.1
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-06 00:00:00.000000000 Z
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.4.5.1
143
+ rubygems_version: 2.5.1
144
144
  signing_key:
145
145
  specification_version: 4
146
146
  summary: jQuery scripts used in various projects