da-js 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## Version 0.1.0
2
+ * Add conditionalVisibility().
3
+ * Now requires CoffeeScript.
4
+
1
5
  ## Version 0.0.2
2
6
  * Now supports forms generated by Formtastic.
3
7
  * Return 'this' from formChangeTracker() to make it chainable.
data/da-js.gemspec CHANGED
@@ -20,12 +20,12 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_dependency "railties", ">= 3.1.0"
22
22
  s.add_dependency "sprockets", "~> 2.0"
23
+ s.add_dependency "coffee-script", "~> 2.2"
23
24
 
24
25
  s.add_development_dependency "cucumber", ">= 1.1.4"
25
26
  s.add_development_dependency "rspec-expectations", ">= 2.7.0"
26
27
  s.add_development_dependency "sinatra"
27
28
  s.add_development_dependency "sinatra-contrib"
28
- s.add_development_dependency "capybara", ">= 1.1.2"
29
- s.add_development_dependency "capybara-webkit", ">= 0.8.0"
29
+ s.add_development_dependency "capybara-webkit", ">= 0.11.0"
30
30
  s.add_development_dependency "launchy"
31
31
  end
@@ -0,0 +1,29 @@
1
+ @javascript
2
+ Feature: Conditional visibility for elements
3
+
4
+ Background:
5
+ Given I visit the test page for "conditional visibility"
6
+
7
+ Scenario: Basic functionality
8
+ Then the "Other Country" input should be hidden
9
+ But the "Message" input should be visible
10
+
11
+ When I select "Other …" from the "Country" select
12
+ Then the "Other Country" input should be visible
13
+
14
+ When I uncheck the "I want to leave a message" checkbox
15
+ Then the "Message" input should be hidden
16
+
17
+ When I select "Austria" from the "Country" select
18
+ Then the "Other Country" input should be hidden
19
+
20
+ When I check the "I want to leave a message" checkbox
21
+ Then the "Message" input should be visible
22
+
23
+ Scenario: Changing a field value via javascript and triggering the event manually
24
+ When I set the "I want to leave a message" checkbox to unchecked using JavaScript
25
+ Then the "Message" input should be visible
26
+
27
+ When I trigger the "updateVisibilities" event on the form
28
+ Then the "Message" input should be hidden
29
+
@@ -0,0 +1,30 @@
1
+ Then /^the "([^"]*)" input should be hidden$/ do |input|
2
+ find_field(input).should_not be_visible
3
+ end
4
+
5
+ Then /^the "([^"]*)" input should be visible$/ do |input|
6
+ find_field(input).should be_visible
7
+ end
8
+
9
+ When /^I select "([^"]*)" from the "([^"]*)" select$/ do |option, input|
10
+ select option, :from => input
11
+ end
12
+
13
+ When /^I uncheck the "([^"]*)" checkbox$/ do |input|
14
+ uncheck input
15
+ end
16
+
17
+ When /^I check the "([^"]*)" checkbox$/ do |input|
18
+ check input
19
+ end
20
+
21
+ When /^I set the "([^"]*)" checkbox to unchecked using JavaScript$/ do |input|
22
+ id = find_field(input)["id"]
23
+ page.execute_script "$('##{id}')[0].checked = false"
24
+ end
25
+
26
+ When /^I trigger the "([^"]*)" event on the form$/ do |event|
27
+ page.execute_script "$('form').trigger('#{event}')"
28
+ end
29
+
30
+
@@ -0,0 +1,5 @@
1
+ require "active_support/inflector"
2
+
3
+ When /^I visit the test page for "([^"]*)"$/ do |feature|
4
+ visit "/#{feature.parameterize '_'}"
5
+ end
@@ -1,5 +1,6 @@
1
1
  require "sinatra"
2
2
  require "sinatra/reloader" if development?
3
+ require "coffee_script"
3
4
 
4
5
  set :app_file, __FILE__
5
6
 
@@ -0,0 +1,41 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Test</title>
5
+ <%= "<script src='../vendor/jquery-#{@jquery_version}.js'></script>" %>
6
+ <script src="/assets/javascripts/da-js.js"></script>
7
+ <script>$.fx.off = true;</script>
8
+ </head>
9
+ <body>
10
+ <h1>Test: Conditional Visibility</h1>
11
+ <form id="simple_form" action="">
12
+ <div class="field">
13
+ <label for="country">Country</label>
14
+ <select id="country">
15
+ <option></option>
16
+ <option>Austria</option>
17
+ <option>Other …</option>
18
+ </select>
19
+ </div>
20
+ <div class="field" data-visible-if="$('#country option:last').is(':selected')">
21
+ <label for="country_other">Other Country</label>
22
+ <input id="country_other">
23
+ </div>
24
+ <div class="field">
25
+ <label for="message_checkbox">I want to leave a message</label>
26
+ <input type="checkbox" id="message_checkbox" checked>
27
+ </div>
28
+ <div class="field" data-visible-if="$('#message_checkbox')[0].checked">
29
+ <label for="message">Message</label>
30
+ <textarea id="message"></textarea>
31
+ </div>
32
+
33
+ </form>
34
+
35
+ <script>
36
+ $("form").conditionalVisibility();
37
+ </script>
38
+
39
+
40
+ </body>
41
+ </html>
@@ -0,0 +1,40 @@
1
+ # Hide/show elements dynamically according to their data-visible-if attribute.
2
+ #
3
+ # All elements with a data-visible-if attribute are checked on each change/focusout/click event:
4
+ # For each element, the content of its data-visible-if attribute is eval'd. If the eval'd code returns true, the element is shown – otherwise it is hidden.
5
+ # (The data-visible-if attributes must contain valid JavaScript code.)
6
+ #
7
+ # Calling conditionalVisibility() also sets up the correct initial state (shown/hidden) of each element (again according to the result of the eval'd code in its dava-visible-if attribute).
8
+ #
9
+ # Use $("body").conditionalVisibility() to enable the functionality for the whole document, or use a more specific selector to enable it only for some elements.
10
+ #
11
+ # If you want to force an update of the visibilites, use $(…).trigger("updateVisibilites").
12
+ #
13
+ # Example:
14
+ #
15
+ # <form id="myform">
16
+ # <input id="checkbox" type="checkbox" >
17
+ # <input id="text" data-visible-if="$('#checkbox')[0].checked">
18
+ # </form>
19
+ # <script>
20
+ # $("#myform").conditionalVisibility()
21
+ # </script>
22
+
23
+ $.fn.conditionalVisibility = ->
24
+
25
+ updateVisibilities = (event, options) ->
26
+ $(this).find("[data-visible-if]").each ->
27
+ if eval($(this).data("visible-if"))
28
+ if options?.skipAnimations
29
+ $(this).show()
30
+ else
31
+ $(this).slideDown(100)
32
+ else
33
+ if options?.skipAnimations
34
+ $(this).hide()
35
+ else
36
+ $(this).slideUp(100)
37
+
38
+ this.on("change focusout click updateVisibilities", updateVisibilities).trigger("updateVisibilities", {skipAnimations: true})
39
+
40
+
data/lib/da-js/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Da
2
2
  module Js
3
- VERSION = "0.0.2"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 2
10
- version: 0.0.2
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Stefan Daschek
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-02-07 00:00:00 Z
18
+ date: 2012-03-29 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: railties
@@ -49,9 +49,24 @@ dependencies:
49
49
  type: :runtime
50
50
  version_requirements: *id002
51
51
  - !ruby/object:Gem::Dependency
52
- name: cucumber
52
+ name: coffee-script
53
53
  prerelease: false
54
54
  requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 7
60
+ segments:
61
+ - 2
62
+ - 2
63
+ version: "2.2"
64
+ type: :runtime
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ name: cucumber
68
+ prerelease: false
69
+ requirement: &id004 !ruby/object:Gem::Requirement
55
70
  none: false
56
71
  requirements:
57
72
  - - ">="
@@ -63,11 +78,11 @@ dependencies:
63
78
  - 4
64
79
  version: 1.1.4
65
80
  type: :development
66
- version_requirements: *id003
81
+ version_requirements: *id004
67
82
  - !ruby/object:Gem::Dependency
68
83
  name: rspec-expectations
69
84
  prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
85
+ requirement: &id005 !ruby/object:Gem::Requirement
71
86
  none: false
72
87
  requirements:
73
88
  - - ">="
@@ -79,11 +94,11 @@ dependencies:
79
94
  - 0
80
95
  version: 2.7.0
81
96
  type: :development
82
- version_requirements: *id004
97
+ version_requirements: *id005
83
98
  - !ruby/object:Gem::Dependency
84
99
  name: sinatra
85
100
  prerelease: false
86
- requirement: &id005 !ruby/object:Gem::Requirement
101
+ requirement: &id006 !ruby/object:Gem::Requirement
87
102
  none: false
88
103
  requirements:
89
104
  - - ">="
@@ -93,11 +108,11 @@ dependencies:
93
108
  - 0
94
109
  version: "0"
95
110
  type: :development
96
- version_requirements: *id005
111
+ version_requirements: *id006
97
112
  - !ruby/object:Gem::Dependency
98
113
  name: sinatra-contrib
99
114
  prerelease: false
100
- requirement: &id006 !ruby/object:Gem::Requirement
115
+ requirement: &id007 !ruby/object:Gem::Requirement
101
116
  none: false
102
117
  requirements:
103
118
  - - ">="
@@ -107,22 +122,6 @@ dependencies:
107
122
  - 0
108
123
  version: "0"
109
124
  type: :development
110
- version_requirements: *id006
111
- - !ruby/object:Gem::Dependency
112
- name: capybara
113
- prerelease: false
114
- requirement: &id007 !ruby/object:Gem::Requirement
115
- none: false
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- hash: 23
120
- segments:
121
- - 1
122
- - 1
123
- - 2
124
- version: 1.1.2
125
- type: :development
126
125
  version_requirements: *id007
127
126
  - !ruby/object:Gem::Dependency
128
127
  name: capybara-webkit
@@ -132,12 +131,12 @@ dependencies:
132
131
  requirements:
133
132
  - - ">="
134
133
  - !ruby/object:Gem::Version
135
- hash: 63
134
+ hash: 51
136
135
  segments:
137
136
  - 0
138
- - 8
137
+ - 11
139
138
  - 0
140
- version: 0.8.0
139
+ version: 0.11.0
141
140
  type: :development
142
141
  version_requirements: *id008
143
142
  - !ruby/object:Gem::Dependency
@@ -171,13 +170,18 @@ files:
171
170
  - Rakefile
172
171
  - da-js.gemspec
173
172
  - features/change_tracker.feature
173
+ - features/conditional_visibility.feature
174
174
  - features/step_definitions/change_tracker_steps.rb
175
+ - features/step_definitions/conditional_visibility_steps.rb
176
+ - features/step_definitions/shared_steps.rb
175
177
  - features/support/env.rb
176
178
  - features/support/testapp/config.ru
177
179
  - features/support/testapp/testapp.rb
178
180
  - features/support/testapp/vendor/jquery-1.7.1.js
181
+ - features/support/testapp/views/conditional_visibility.erb
179
182
  - features/support/testapp/views/form_change_tracker.erb
180
183
  - lib/assets/javascripts/da-js.js
184
+ - lib/assets/javascripts/da-js/conditional_visibility.js.coffee
181
185
  - lib/assets/javascripts/da-js/form_change_tracker.js
182
186
  - lib/da-js.rb
183
187
  - lib/da-js/version.rb
@@ -216,9 +220,13 @@ specification_version: 3
216
220
  summary: Mixed jQuery extensions
217
221
  test_files:
218
222
  - features/change_tracker.feature
223
+ - features/conditional_visibility.feature
219
224
  - features/step_definitions/change_tracker_steps.rb
225
+ - features/step_definitions/conditional_visibility_steps.rb
226
+ - features/step_definitions/shared_steps.rb
220
227
  - features/support/env.rb
221
228
  - features/support/testapp/config.ru
222
229
  - features/support/testapp/testapp.rb
223
230
  - features/support/testapp/vendor/jquery-1.7.1.js
231
+ - features/support/testapp/views/conditional_visibility.erb
224
232
  - features/support/testapp/views/form_change_tracker.erb