da-js 0.0.1
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.
- data/.gitignore +4 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/README.md +33 -0
- data/Rakefile +8 -0
- data/da-js.gemspec +31 -0
- data/features/change_tracker.feature +119 -0
- data/features/step_definitions/change_tracker_steps.rb +128 -0
- data/features/support/env.rb +7 -0
- data/features/support/testapp/config.ru +12 -0
- data/features/support/testapp/testapp.rb +21 -0
- data/features/support/testapp/vendor/jquery-1.7.1.js +9266 -0
- data/features/support/testapp/views/form_change_tracker.erb +152 -0
- data/lib/assets/javascripts/da-js/form_change_tracker.js +64 -0
- data/lib/assets/javascripts/da-js.js +1 -0
- data/lib/da-js/version.rb +5 -0
- data/lib/da-js.rb +9 -0
- metadata +224 -0
@@ -0,0 +1,152 @@
|
|
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"></script>
|
7
|
+
<style type="text/css">
|
8
|
+
form {
|
9
|
+
background: #eee;
|
10
|
+
padding: 1em;
|
11
|
+
margin: 0 0 2em 0;
|
12
|
+
}
|
13
|
+
h2 {
|
14
|
+
margin: 0;
|
15
|
+
font-size: 1.25em;
|
16
|
+
}
|
17
|
+
.changed { outline: 1px solid #C93; }
|
18
|
+
</style>
|
19
|
+
</head>
|
20
|
+
<body>
|
21
|
+
<h1>Test: Form Change Tracker</h1>
|
22
|
+
<form id="simple_form" action="">
|
23
|
+
<h2>Simple Form</h2>
|
24
|
+
<p>
|
25
|
+
A simple form as it may appear in non-Rails applications.
|
26
|
+
</p>
|
27
|
+
<label for="simple_form_textfield">textfield:</label>
|
28
|
+
<input id="simple_form_textfield" name="textfield">
|
29
|
+
|
30
|
+
<label for="simple_form_textarea">textarea:</label>
|
31
|
+
<textarea id="simple_form_textarea" name="textarea"></textarea>
|
32
|
+
|
33
|
+
<label for="simple_form_checkbox">checkbox:</label>
|
34
|
+
<input id="simple_form_checkbox" name="checkbox" type="checkbox" value="1">
|
35
|
+
|
36
|
+
<input id='simple_form_radiobutton_1' name='radiobutton' type='radio' value='1'>
|
37
|
+
<label for='simple_form_radiobutton_1'>radiobutton 1</label>
|
38
|
+
<input id='simple_form_radiobutton_2' name='radiobutton' type='radio' value='2'>
|
39
|
+
<label for='simple_form_radiobutton_2'>radiobutton 2</label>
|
40
|
+
<input id='simple_form_radiobutton_3' name='radiobutton' type='radio' value='3'>
|
41
|
+
<label for='simple_form_radiobutton_3'>radiobutton 3</label>
|
42
|
+
|
43
|
+
<label for="simple_form_select">select:</label>
|
44
|
+
<select id="simple_form_select" name="select">
|
45
|
+
<option></option>
|
46
|
+
<option value="1">option 1</option>
|
47
|
+
<option value="2">option 2</option>
|
48
|
+
</select>
|
49
|
+
|
50
|
+
</form>
|
51
|
+
|
52
|
+
<form id="simple_form_prefilled" action="">
|
53
|
+
<h2>Simple Form (prefilled)</h2>
|
54
|
+
<label for="simple_form_prefilled_textfield">textfield:</label>
|
55
|
+
<input id="simple_form_prefilled_textfield" name="textfield" value="text">
|
56
|
+
|
57
|
+
<label for="simple_form_prefilled_textarea">textarea:</label>
|
58
|
+
<textarea id="simple_form_prefilled_textarea" name="textarea">text</textarea>
|
59
|
+
<label for="simple_form_prefilled_checkbox">checkbox:</label>
|
60
|
+
<input id="simple_form_prefilled_checkbox" name="checkbox" type="checkbox" value="1" checked>
|
61
|
+
|
62
|
+
<input id='simple_form_prefilled_radiobutton_1' name='radiobutton' type='radio' value='1' checked>
|
63
|
+
<label for='simple_form_prefilled_radiobutton_1'>radiobutton 1</label>
|
64
|
+
<input id='simple_form_prefilled_radiobutton_2' name='radiobutton' type='radio' value='2'>
|
65
|
+
<label for='simple_form_prefilled_radiobutton_2'>radiobutton 2</label>
|
66
|
+
<input id='simple_form_prefilled_radiobutton_3' name='radiobutton' type='radio' value='3'>
|
67
|
+
<label for='simple_form_prefilled_radiobutton_3'>radiobutton 3</label>
|
68
|
+
|
69
|
+
<label for="simple_form_prefilled_select">select:</label>
|
70
|
+
<select id="simple_form_prefilled_select" name="select">
|
71
|
+
<option></option>
|
72
|
+
<option value="1" selected>option 1</option>
|
73
|
+
<option value="2">option 2</option>
|
74
|
+
</select>
|
75
|
+
</form>
|
76
|
+
|
77
|
+
<form id="scaffold_form" action="">
|
78
|
+
<h2>Scaffold Form</h2>
|
79
|
+
<p>
|
80
|
+
A form generated by Rails' scaffolding. Labels and Inputs are wrapped in <div class="field">…</div>. Checkbox has an additional hidden field with the same name and value="0".
|
81
|
+
</p>
|
82
|
+
<div class="field">
|
83
|
+
<label for="scaffold_form_textfield">textfield:</label>
|
84
|
+
<input id="scaffold_form_textfield" name="scaffold_form[textfield]">
|
85
|
+
</div>
|
86
|
+
<div class="field">
|
87
|
+
<label for="scaffold_form_textarea">textarea:</label>
|
88
|
+
<textarea id="scaffold_form_textarea" name="scaffold_form[textarea]"></textarea>
|
89
|
+
</div>
|
90
|
+
<div class="field">
|
91
|
+
<label for="scaffold_form_checkbox">checkbox:</label>
|
92
|
+
<input name="scaffold_form[checkbox]" type="hidden" value="0">
|
93
|
+
<input id="scaffold_form_checkbox" name="scaffold_form[checkbox]" type="checkbox" value="1">
|
94
|
+
</div>
|
95
|
+
<div class="field">
|
96
|
+
<input id='scaffold_form_radiobutton_1' name='scaffold_form[radiobutton]' type='radio' value='1'>
|
97
|
+
<label for='scaffold_form_radiobutton_1'>radiobutton 1</label>
|
98
|
+
<input id='scaffold_form_radiobutton_2' name='scaffold_form[radiobutton]' type='radio' value='2'>
|
99
|
+
<label for='scaffold_form_radiobutton_2'>radiobutton 2</label>
|
100
|
+
<input id='scaffold_form_radiobutton_3' name='scaffold_form[radiobutton]' type='radio' value='3'>
|
101
|
+
<label for='scaffold_form_radiobutton_3'>radiobutton 3</label>
|
102
|
+
</div>
|
103
|
+
<div class="field">
|
104
|
+
<label for="scaffold_form_select">select:</label>
|
105
|
+
<select id="scaffold_form_select" name="scaffold_form[select]">
|
106
|
+
<option></option>
|
107
|
+
<option value="1">option 1</option>
|
108
|
+
<option value="2">option 2</option>
|
109
|
+
</select>
|
110
|
+
</div>
|
111
|
+
</form>
|
112
|
+
|
113
|
+
<form id="scaffold_form_prefilled" action="">
|
114
|
+
<h2>Scaffold Form Prefilled</h2>
|
115
|
+
<div class="field">
|
116
|
+
<label for="scaffold_form_prefilled_textfield">textfield:</label>
|
117
|
+
<input id="scaffold_form_prefilled_textfield" name="scaffold_form_prefilled[textfield]" value="text">
|
118
|
+
</div>
|
119
|
+
<div class="field">
|
120
|
+
<label for="scaffold_form_prefilled_textarea">textarea:</label>
|
121
|
+
<textarea id="scaffold_form_prefilled_textarea" name="scaffold_form_prefilled[textarea]">text</textarea>
|
122
|
+
</div>
|
123
|
+
<div class="field">
|
124
|
+
<label for="scaffold_form_prefilled_checkbox">checkbox:</label>
|
125
|
+
<input name="scaffold_form_prefilled[checkbox]" type="hidden" value="0">
|
126
|
+
<input id="scaffold_form_prefilled_checkbox" name="scaffold_form_prefilled[checkbox]" type="checkbox" value="1" checked>
|
127
|
+
</div>
|
128
|
+
<div class="field">
|
129
|
+
<input id='scaffold_form_prefilled_radiobutton_1' name='scaffold_form_prefilled[radiobutton]' type='radio' value='1' checked>
|
130
|
+
<label for='scaffold_form_prefilled_radiobutton_1'>radiobutton 1</label>
|
131
|
+
<input id='scaffold_form_prefilled_radiobutton_2' name='scaffold_form_prefilled[radiobutton]' type='radio' value='2'>
|
132
|
+
<label for='scaffold_form_prefilled_radiobutton_2'>radiobutton 2</label>
|
133
|
+
<input id='scaffold_form_prefilled_radiobutton_3' name='scaffold_form_prefilled[radiobutton]' type='radio' value='3'>
|
134
|
+
<label for='scaffold_form_prefilled_radiobutton_3'>radiobutton 3</label>
|
135
|
+
</div>
|
136
|
+
<div class="field">
|
137
|
+
<label for="scaffold_form_prefilled_select">select:</label>
|
138
|
+
<select id="scaffold_form_prefilled_select" name="scaffold_form_prefilled[select]">
|
139
|
+
<option></option>
|
140
|
+
<option value="1" selected>option 1</option>
|
141
|
+
<option value="2">option 2</option>
|
142
|
+
</select>
|
143
|
+
</div>
|
144
|
+
</form>
|
145
|
+
|
146
|
+
<script>
|
147
|
+
$("form").formChangeTracker();
|
148
|
+
</script>
|
149
|
+
|
150
|
+
|
151
|
+
</body>
|
152
|
+
</html>
|
@@ -0,0 +1,64 @@
|
|
1
|
+
(function( $ ) {
|
2
|
+
// Track changes to form fields accordingly set/reset CSS class "changed".
|
3
|
+
//
|
4
|
+
// Usage:
|
5
|
+
// $("#myform").formChangeTracker();
|
6
|
+
//
|
7
|
+
// If the form element is wrapped in an element with the class "field", the class "changed" is set/reset on this wrapper element. Otherwise, "changed" is set/reset on the form element itself and its label (if present).
|
8
|
+
|
9
|
+
$.fn.formChangeTracker = function() {
|
10
|
+
|
11
|
+
var elementSelector = "input[type!=hidden],textarea,select";
|
12
|
+
|
13
|
+
this.each(function() {
|
14
|
+
|
15
|
+
var form = $(this);
|
16
|
+
saveInitialValues(elementSelector);
|
17
|
+
form.on("change keyup click", elementSelector, updateStatus);
|
18
|
+
|
19
|
+
function saveInitialValues(selector) {
|
20
|
+
form.find(selector).each(function() {
|
21
|
+
$(this).data("initialValue", valueFor(this));
|
22
|
+
})
|
23
|
+
}
|
24
|
+
|
25
|
+
function valueFor(element) {
|
26
|
+
if (element.type == "checkbox" || element.type == "radio") return element.checked;
|
27
|
+
return $(element).val();
|
28
|
+
}
|
29
|
+
|
30
|
+
function updateStatus(event, ignoreOtherRadiobuttons) {
|
31
|
+
var targets = targetsForElement(this);
|
32
|
+
|
33
|
+
if (elementHasChanged(this)) {
|
34
|
+
targets.addClass('changed');
|
35
|
+
} else {
|
36
|
+
targets.removeClass('changed');
|
37
|
+
}
|
38
|
+
|
39
|
+
// For radiobuttons, if there is no container, also update all other radiobuttons of the same group
|
40
|
+
if (this.type == "radio" && !ignoreOtherRadiobuttons && targets.index(this) != -1) {
|
41
|
+
form.find("input[type=radio][name='" + this.name + "']").each(function() {
|
42
|
+
updateStatus.call(this, null, true);
|
43
|
+
});
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
function elementHasChanged(element) {
|
48
|
+
return valueFor(element) !== $(element).data("initialValue");
|
49
|
+
}
|
50
|
+
|
51
|
+
// Return the element(s) on that the "changed" class should be set/removed.
|
52
|
+
function targetsForElement(element) {
|
53
|
+
// use wrapping element with class .field if present ...
|
54
|
+
var targets = $(element).closest("form .field");
|
55
|
+
|
56
|
+
// ... or fallback to the form element itself (and its label)
|
57
|
+
if (targets.length == 0) targets = $(element).add("label[for=" + element.id + "]");
|
58
|
+
|
59
|
+
return targets;
|
60
|
+
}
|
61
|
+
|
62
|
+
});
|
63
|
+
};
|
64
|
+
})( jQuery );
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require_tree ./da-js
|
data/lib/da-js.rb
ADDED
metadata
ADDED
@@ -0,0 +1,224 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: da-js
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Stefan Daschek
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-02-07 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: railties
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 3
|
31
|
+
- 1
|
32
|
+
- 0
|
33
|
+
version: 3.1.0
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: sprockets
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 2
|
47
|
+
- 0
|
48
|
+
version: "2.0"
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: cucumber
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 27
|
60
|
+
segments:
|
61
|
+
- 1
|
62
|
+
- 1
|
63
|
+
- 4
|
64
|
+
version: 1.1.4
|
65
|
+
type: :development
|
66
|
+
version_requirements: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: rspec-expectations
|
69
|
+
prerelease: false
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 19
|
76
|
+
segments:
|
77
|
+
- 2
|
78
|
+
- 7
|
79
|
+
- 0
|
80
|
+
version: 2.7.0
|
81
|
+
type: :development
|
82
|
+
version_requirements: *id004
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sinatra
|
85
|
+
prerelease: false
|
86
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
hash: 3
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
version: "0"
|
95
|
+
type: :development
|
96
|
+
version_requirements: *id005
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sinatra-contrib
|
99
|
+
prerelease: false
|
100
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
hash: 3
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
version: "0"
|
109
|
+
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
|
+
version_requirements: *id007
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
name: capybara-webkit
|
129
|
+
prerelease: false
|
130
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
hash: 63
|
136
|
+
segments:
|
137
|
+
- 0
|
138
|
+
- 8
|
139
|
+
- 0
|
140
|
+
version: 0.8.0
|
141
|
+
type: :development
|
142
|
+
version_requirements: *id008
|
143
|
+
- !ruby/object:Gem::Dependency
|
144
|
+
name: launchy
|
145
|
+
prerelease: false
|
146
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
147
|
+
none: false
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
hash: 3
|
152
|
+
segments:
|
153
|
+
- 0
|
154
|
+
version: "0"
|
155
|
+
type: :development
|
156
|
+
version_requirements: *id009
|
157
|
+
description: Some jQuery extensions we tend to use in almost all our projects.
|
158
|
+
email:
|
159
|
+
- stefan@die-antwort.eu
|
160
|
+
executables: []
|
161
|
+
|
162
|
+
extensions: []
|
163
|
+
|
164
|
+
extra_rdoc_files: []
|
165
|
+
|
166
|
+
files:
|
167
|
+
- .gitignore
|
168
|
+
- CHANGELOG.md
|
169
|
+
- Gemfile
|
170
|
+
- README.md
|
171
|
+
- Rakefile
|
172
|
+
- da-js.gemspec
|
173
|
+
- features/change_tracker.feature
|
174
|
+
- features/step_definitions/change_tracker_steps.rb
|
175
|
+
- features/support/env.rb
|
176
|
+
- features/support/testapp/config.ru
|
177
|
+
- features/support/testapp/testapp.rb
|
178
|
+
- features/support/testapp/vendor/jquery-1.7.1.js
|
179
|
+
- features/support/testapp/views/form_change_tracker.erb
|
180
|
+
- lib/assets/javascripts/da-js.js
|
181
|
+
- lib/assets/javascripts/da-js/form_change_tracker.js
|
182
|
+
- lib/da-js.rb
|
183
|
+
- lib/da-js/version.rb
|
184
|
+
homepage: https://github.com/die-antwort/da-js
|
185
|
+
licenses: []
|
186
|
+
|
187
|
+
post_install_message:
|
188
|
+
rdoc_options: []
|
189
|
+
|
190
|
+
require_paths:
|
191
|
+
- lib
|
192
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
193
|
+
none: false
|
194
|
+
requirements:
|
195
|
+
- - ">="
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
hash: 3
|
198
|
+
segments:
|
199
|
+
- 0
|
200
|
+
version: "0"
|
201
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
202
|
+
none: false
|
203
|
+
requirements:
|
204
|
+
- - ">="
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
hash: 3
|
207
|
+
segments:
|
208
|
+
- 0
|
209
|
+
version: "0"
|
210
|
+
requirements: []
|
211
|
+
|
212
|
+
rubyforge_project: da-js
|
213
|
+
rubygems_version: 1.8.11
|
214
|
+
signing_key:
|
215
|
+
specification_version: 3
|
216
|
+
summary: Mixed jQuery extensions
|
217
|
+
test_files:
|
218
|
+
- features/change_tracker.feature
|
219
|
+
- features/step_definitions/change_tracker_steps.rb
|
220
|
+
- features/support/env.rb
|
221
|
+
- features/support/testapp/config.ru
|
222
|
+
- features/support/testapp/testapp.rb
|
223
|
+
- features/support/testapp/vendor/jquery-1.7.1.js
|
224
|
+
- features/support/testapp/views/form_change_tracker.erb
|