epi_js 0.0.18 → 0.0.19

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: 32b683bebf316f9df7642f24b8785cd1a03bcb74
4
- data.tar.gz: d6ff19c68d8d462284902c28498581c2a1c44c80
3
+ metadata.gz: c9cb4601137674203e8fb811db4c557d346b5a83
4
+ data.tar.gz: d9b3e66fdce959db6657b60634ba4a2af381b6aa
5
5
  SHA512:
6
- metadata.gz: 0614d2f1cc10a0b0fe2ed1ae8f217243210fa927e16d1aa4e2dedc2031228c08768ac941d84bf8e0f1663062478ae60c7999ad3851a09b3656ccf8e55e4cab2b
7
- data.tar.gz: ca0920db179c91be440d38af753a2542a332540bf81dac909ff6dcd7a470389a047456ebee3769fa3fdc8d7ebfee2d8823c38063359555a98f98514d893fb545
6
+ metadata.gz: bf5bf618e901d016ffb74f29420e1164f53d5af956aaf76a603dc14852a5063e5952127075f6af4614aaee41ff6bded6cabac6dbde5a171a0b1b946ba1342ddc
7
+ data.tar.gz: 35763559ef74f24841f42e249ee7f515f81b038d1a6af5b673cf17aedc3b63cd56ca4341bd07a58725acccf1a3e894ae98739447d2cd7363e807f251170c117e
@@ -1,3 +1,3 @@
1
1
  module EpiJs
2
- VERSION = "0.0.18"
2
+ VERSION = "0.0.19"
3
3
  end
@@ -1,19 +1,42 @@
1
1
  (($) ->
2
+ 'use strict'
3
+ class GenericVisibilityChecker
4
+ constructor: (element) ->
5
+ @element = element
6
+ @map = @element.data('visibility-map')
7
+ @allFields = $($.unique $.map @map, (val) -> $(val).get())
8
+
9
+ check: ->
10
+ toShow = $ $.unique $.map @getValue(), (value) => $(@map[value]).get()
11
+ toHide = @allFields.not(toShow)
12
+
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)
20
+
21
+ getValue: ->
22
+ $.makeArray(@element.val())
23
+
24
+ class CheckboxVisibilityChecker extends GenericVisibilityChecker
25
+ getValue: ->
26
+ $.map $("input[type='checkbox'][name='#{@element.attr('name')}']:checked"), (inputElement) ->
27
+ $(inputElement).val()
28
+
2
29
  $.fn.setVisibility = ->
3
30
  @each ->
4
- unless $(@).data('fieldList')?
5
- $(@).data 'fieldList', $.unique $.map $(@).data('visibility-map'), (val) -> $(val).get()
6
-
7
- $toShow = $($(@).data('visibility-map')[$(@).val()])
8
- $toShow.find('input, select, textarea').prop 'disabled', false
9
- $toShow.show().trigger('visibility.show')
10
-
11
- $($(@).data('fieldList')).not($toShow).hide().trigger('visibility.hide').find('input, select, textarea').prop 'disabled', true
12
-
13
- ) jQuery
14
-
15
- $ ->
16
- $(document.body).on 'change', '[data-visibility-map]', ->
17
- $(@).setVisibility()
18
-
19
- $('input[data-visibility-map]:checked, select[data-visibility-map]').setVisibility()
31
+ data = $(this).data('visibility-checker')
32
+ unless data?
33
+ checkerClass = if $(this).is("input[type='checkbox']") then CheckboxVisibilityChecker else GenericVisibilityChecker
34
+ $(this).data('visibility-checker', data = new checkerClass $(this))
35
+ data.check()
36
+
37
+ $ ->
38
+ $('input[data-visibility-map]:checked, select[data-visibility-map]').setVisibility()
39
+
40
+ $(document.body).on 'change', '[data-visibility-map]', (e) ->
41
+ $(e.target).setVisibility()
42
+ ) jQuery
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epi_js
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shuo Chen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-14 00:00:00.000000000 Z
11
+ date: 2015-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  version: '0'
135
135
  requirements: []
136
136
  rubyforge_project:
137
- rubygems_version: 2.4.6
137
+ rubygems_version: 2.4.5.1
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: jQuery scripts used in various projects