prototype-rails 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/Gemfile +7 -0
- data/README +20 -0
- data/Rakefile +10 -0
- data/lib/action_view/helpers/prototype_helper.rb +852 -0
- data/lib/action_view/helpers/scriptaculous_helper.rb +263 -0
- data/lib/action_view/template/handlers/rjs.rb +14 -0
- data/lib/prototype-rails.rb +17 -0
- data/lib/prototype-rails/javascript_helper.rb +65 -0
- data/lib/prototype-rails/on_load_action_controller.rb +2 -0
- data/lib/prototype-rails/on_load_action_view.rb +22 -0
- data/lib/prototype-rails/renderers.rb +12 -0
- data/lib/prototype-rails/rendering.rb +13 -0
- data/lib/prototype-rails/selector_assertions.rb +208 -0
- data/test/abstract_unit.rb +235 -0
- data/test/assert_select_test.rb +452 -0
- data/test/controller/caching_test.rb +46 -0
- data/test/controller/content_type_test.rb +16 -0
- data/test/controller/mime_responds_test.rb +213 -0
- data/test/controller/new_base/content_type_test.rb +19 -0
- data/test/controller/new_base/render_rjs_test.rb +71 -0
- data/test/controller/render_js_test.rb +22 -0
- data/test/fixtures/functional_caching/_partial.erb +3 -0
- data/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs +6 -0
- data/test/fixtures/functional_caching/js_fragment_cached_with_partial.js.rjs +1 -0
- data/test/fixtures/old_content_type/render_default_for_rjs.rjs +1 -0
- data/test/fixtures/respond_to/all_types_with_layout.js.rjs +1 -0
- data/test/fixtures/respond_to/layouts/standard.html.erb +1 -0
- data/test/fixtures/respond_to/using_defaults.js.rjs +1 -0
- data/test/fixtures/respond_to/using_defaults_with_type_list.js.rjs +1 -0
- data/test/fixtures/respond_with/using_resource.js.rjs +1 -0
- data/test/fixtures/test/_one.html.erb +1 -0
- data/test/fixtures/test/_partial.html.erb +1 -0
- data/test/fixtures/test/_partial.js.erb +1 -0
- data/test/fixtures/test/_two.html.erb +1 -0
- data/test/fixtures/test/delete_with_js.rjs +2 -0
- data/test/fixtures/test/enum_rjs_test.rjs +6 -0
- data/test/fixtures/test/greeting.js.rjs +1 -0
- data/test/fixtures/test/render_explicit_html_template.js.rjs +1 -0
- data/test/fixtures/test/render_implicit_html_template.js.rjs +1 -0
- data/test/javascript_helper_test.rb +61 -0
- data/test/lib/controller/fake_models.rb +29 -0
- data/test/render_other_test.rb +257 -0
- data/test/template/prototype_helper_test.rb +476 -0
- data/test/template/render_test.rb +24 -0
- data/test/template/scriptaculous_helper_test.rb +86 -0
- data/vendor/assets/javascripts/controls.js +965 -0
- data/vendor/assets/javascripts/dragdrop.js +974 -0
- data/vendor/assets/javascripts/effects.js +1123 -0
- data/vendor/assets/javascripts/prototype.js +6082 -0
- data/vendor/assets/javascripts/prototype_ujs.js +208 -0
- metadata +127 -0
@@ -0,0 +1,208 @@
|
|
1
|
+
(function() {
|
2
|
+
// Technique from Juriy Zaytsev
|
3
|
+
// http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
|
4
|
+
function isEventSupported(eventName) {
|
5
|
+
var el = document.createElement('div');
|
6
|
+
eventName = 'on' + eventName;
|
7
|
+
var isSupported = (eventName in el);
|
8
|
+
if (!isSupported) {
|
9
|
+
el.setAttribute(eventName, 'return;');
|
10
|
+
isSupported = typeof el[eventName] == 'function';
|
11
|
+
}
|
12
|
+
el = null;
|
13
|
+
return isSupported;
|
14
|
+
}
|
15
|
+
|
16
|
+
function isForm(element) {
|
17
|
+
return Object.isElement(element) && element.nodeName.toUpperCase() == 'FORM';
|
18
|
+
}
|
19
|
+
|
20
|
+
function isInput(element) {
|
21
|
+
if (Object.isElement(element)) {
|
22
|
+
var name = element.nodeName.toUpperCase();
|
23
|
+
return name == 'INPUT' || name == 'SELECT' || name == 'TEXTAREA';
|
24
|
+
}
|
25
|
+
else return false;
|
26
|
+
}
|
27
|
+
|
28
|
+
var submitBubbles = isEventSupported('submit'),
|
29
|
+
changeBubbles = isEventSupported('change');
|
30
|
+
|
31
|
+
if (!submitBubbles || !changeBubbles) {
|
32
|
+
// augment the Event.Handler class to observe custom events when needed
|
33
|
+
Event.Handler.prototype.initialize = Event.Handler.prototype.initialize.wrap(
|
34
|
+
function(init, element, eventName, selector, callback) {
|
35
|
+
init(element, eventName, selector, callback);
|
36
|
+
// is the handler being attached to an element that doesn't support this event?
|
37
|
+
if ( (!submitBubbles && this.eventName == 'submit' && !isForm(this.element)) ||
|
38
|
+
(!changeBubbles && this.eventName == 'change' && !isInput(this.element)) ) {
|
39
|
+
// "submit" => "emulated:submit"
|
40
|
+
this.eventName = 'emulated:' + this.eventName;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
);
|
44
|
+
}
|
45
|
+
|
46
|
+
if (!submitBubbles) {
|
47
|
+
// discover forms on the page by observing focus events which always bubble
|
48
|
+
document.on('focusin', 'form', function(focusEvent, form) {
|
49
|
+
// special handler for the real "submit" event (one-time operation)
|
50
|
+
if (!form.retrieve('emulated:submit')) {
|
51
|
+
form.on('submit', function(submitEvent) {
|
52
|
+
var emulated = form.fire('emulated:submit', submitEvent, true);
|
53
|
+
// if custom event received preventDefault, cancel the real one too
|
54
|
+
if (emulated.returnValue === false) submitEvent.preventDefault();
|
55
|
+
});
|
56
|
+
form.store('emulated:submit', true);
|
57
|
+
}
|
58
|
+
});
|
59
|
+
}
|
60
|
+
|
61
|
+
if (!changeBubbles) {
|
62
|
+
// discover form inputs on the page
|
63
|
+
document.on('focusin', 'input, select, textarea', function(focusEvent, input) {
|
64
|
+
// special handler for real "change" events
|
65
|
+
if (!input.retrieve('emulated:change')) {
|
66
|
+
input.on('change', function(changeEvent) {
|
67
|
+
input.fire('emulated:change', changeEvent, true);
|
68
|
+
});
|
69
|
+
input.store('emulated:change', true);
|
70
|
+
}
|
71
|
+
});
|
72
|
+
}
|
73
|
+
|
74
|
+
function handleRemote(element) {
|
75
|
+
var method, url, params;
|
76
|
+
|
77
|
+
var event = element.fire("ajax:before");
|
78
|
+
if (event.stopped) return false;
|
79
|
+
|
80
|
+
if (element.tagName.toLowerCase() === 'form') {
|
81
|
+
method = element.readAttribute('method') || 'post';
|
82
|
+
url = element.readAttribute('action');
|
83
|
+
// serialize the form with respect to the submit button that was pressed
|
84
|
+
params = element.serialize({ submit: element.retrieve('rails:submit-button') });
|
85
|
+
// clear the pressed submit button information
|
86
|
+
element.store('rails:submit-button', null);
|
87
|
+
} else {
|
88
|
+
method = element.readAttribute('data-method') || 'get';
|
89
|
+
url = element.readAttribute('href');
|
90
|
+
params = {};
|
91
|
+
}
|
92
|
+
|
93
|
+
new Ajax.Request(url, {
|
94
|
+
method: method,
|
95
|
+
parameters: params,
|
96
|
+
evalScripts: true,
|
97
|
+
|
98
|
+
onCreate: function(response) { element.fire("ajax:create", response); },
|
99
|
+
onComplete: function(response) { element.fire("ajax:complete", response); },
|
100
|
+
onSuccess: function(response) { element.fire("ajax:success", response); },
|
101
|
+
onFailure: function(response) { element.fire("ajax:failure", response); }
|
102
|
+
});
|
103
|
+
|
104
|
+
element.fire("ajax:after");
|
105
|
+
}
|
106
|
+
|
107
|
+
function insertHiddenField(form, name, value) {
|
108
|
+
form.insert(new Element('input', { type: 'hidden', name: name, value: value }));
|
109
|
+
}
|
110
|
+
|
111
|
+
function handleMethod(element) {
|
112
|
+
var method = element.readAttribute('data-method'),
|
113
|
+
url = element.readAttribute('href'),
|
114
|
+
csrf_param = $$('meta[name=csrf-param]')[0],
|
115
|
+
csrf_token = $$('meta[name=csrf-token]')[0];
|
116
|
+
|
117
|
+
var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
|
118
|
+
$(element.parentNode).insert(form);
|
119
|
+
|
120
|
+
if (method !== 'post') {
|
121
|
+
insertHiddenField(form, '_method', method);
|
122
|
+
}
|
123
|
+
|
124
|
+
if (csrf_param) {
|
125
|
+
insertHiddenField(form, csrf_param.readAttribute('content'), csrf_token.readAttribute('content'));
|
126
|
+
}
|
127
|
+
|
128
|
+
form.submit();
|
129
|
+
}
|
130
|
+
|
131
|
+
function disableFormElements(form) {
|
132
|
+
form.select('input[type=submit][data-disable-with]').each(function(input) {
|
133
|
+
input.store('rails:original-value', input.getValue());
|
134
|
+
input.setValue(input.readAttribute('data-disable-with')).disable();
|
135
|
+
});
|
136
|
+
}
|
137
|
+
|
138
|
+
function enableFormElements(form) {
|
139
|
+
form.select('input[type=submit][data-disable-with]').each(function(input) {
|
140
|
+
input.setValue(input.retrieve('rails:original-value')).enable();
|
141
|
+
});
|
142
|
+
}
|
143
|
+
|
144
|
+
function allowAction(element) {
|
145
|
+
var message = element.readAttribute('data-confirm');
|
146
|
+
return !message || confirm(message);
|
147
|
+
}
|
148
|
+
|
149
|
+
document.on('click', 'a[data-confirm], a[data-remote], a[data-method]', function(event, link) {
|
150
|
+
if (!allowAction(link)) {
|
151
|
+
event.stop();
|
152
|
+
return false;
|
153
|
+
}
|
154
|
+
|
155
|
+
if (link.readAttribute('data-remote')) {
|
156
|
+
handleRemote(link);
|
157
|
+
event.stop();
|
158
|
+
} else if (link.readAttribute('data-method')) {
|
159
|
+
handleMethod(link);
|
160
|
+
event.stop();
|
161
|
+
}
|
162
|
+
});
|
163
|
+
|
164
|
+
document.on("click", "form input[type=submit], form button[type=submit], form button:not([type])", function(event, button) {
|
165
|
+
// register the pressed submit button
|
166
|
+
event.findElement('form').store('rails:submit-button', button.name || false);
|
167
|
+
});
|
168
|
+
|
169
|
+
document.on("submit", function(event) {
|
170
|
+
var form = event.findElement();
|
171
|
+
|
172
|
+
if (!allowAction(form)) {
|
173
|
+
event.stop();
|
174
|
+
return false;
|
175
|
+
}
|
176
|
+
|
177
|
+
if (form.readAttribute('data-remote')) {
|
178
|
+
handleRemote(form);
|
179
|
+
event.stop();
|
180
|
+
} else {
|
181
|
+
disableFormElements(form);
|
182
|
+
}
|
183
|
+
});
|
184
|
+
|
185
|
+
document.on('ajax:create', 'form', function(event, form) {
|
186
|
+
if (form == event.findElement()) disableFormElements(form);
|
187
|
+
});
|
188
|
+
|
189
|
+
document.on('ajax:complete', 'form', function(event, form) {
|
190
|
+
if (form == event.findElement()) enableFormElements(form);
|
191
|
+
});
|
192
|
+
|
193
|
+
Ajax.Responders.register({
|
194
|
+
onCreate: function(request) {
|
195
|
+
var csrf_meta_tag = $$('meta[name=csrf-token]')[0];
|
196
|
+
|
197
|
+
if (csrf_meta_tag) {
|
198
|
+
var header = 'X-CSRF-Token',
|
199
|
+
token = csrf_meta_tag.readAttribute('content');
|
200
|
+
|
201
|
+
if (!request.options.requestHeaders) {
|
202
|
+
request.options.requestHeaders = {};
|
203
|
+
}
|
204
|
+
request.options.requestHeaders[header] = token;
|
205
|
+
}
|
206
|
+
}
|
207
|
+
});
|
208
|
+
})();
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: prototype-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
version: "0.1"
|
9
|
+
platform: ruby
|
10
|
+
authors:
|
11
|
+
- Xavier Noria
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
|
16
|
+
date: 2011-04-30 00:00:00 +02:00
|
17
|
+
default_executable:
|
18
|
+
dependencies:
|
19
|
+
- !ruby/object:Gem::Dependency
|
20
|
+
name: rails
|
21
|
+
prerelease: false
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - "="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 3
|
29
|
+
- 1
|
30
|
+
- 0
|
31
|
+
- beta
|
32
|
+
version: 3.1.0.beta
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description:
|
36
|
+
email: fxn@hashref.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- README
|
45
|
+
- Rakefile
|
46
|
+
- Gemfile
|
47
|
+
- lib/action_view/helpers/prototype_helper.rb
|
48
|
+
- lib/action_view/helpers/scriptaculous_helper.rb
|
49
|
+
- lib/action_view/template/handlers/rjs.rb
|
50
|
+
- lib/prototype-rails/javascript_helper.rb
|
51
|
+
- lib/prototype-rails/on_load_action_controller.rb
|
52
|
+
- lib/prototype-rails/on_load_action_view.rb
|
53
|
+
- lib/prototype-rails/renderers.rb
|
54
|
+
- lib/prototype-rails/rendering.rb
|
55
|
+
- lib/prototype-rails/selector_assertions.rb
|
56
|
+
- lib/prototype-rails.rb
|
57
|
+
- vendor/assets/javascripts/controls.js
|
58
|
+
- vendor/assets/javascripts/dragdrop.js
|
59
|
+
- vendor/assets/javascripts/effects.js
|
60
|
+
- vendor/assets/javascripts/prototype.js
|
61
|
+
- vendor/assets/javascripts/prototype_ujs.js
|
62
|
+
- test/abstract_unit.rb
|
63
|
+
- test/assert_select_test.rb
|
64
|
+
- test/controller/caching_test.rb
|
65
|
+
- test/controller/content_type_test.rb
|
66
|
+
- test/controller/mime_responds_test.rb
|
67
|
+
- test/controller/new_base/content_type_test.rb
|
68
|
+
- test/controller/new_base/render_rjs_test.rb
|
69
|
+
- test/controller/render_js_test.rb
|
70
|
+
- test/fixtures/functional_caching/_partial.erb
|
71
|
+
- test/fixtures/functional_caching/formatted_fragment_cached.js.rjs
|
72
|
+
- test/fixtures/functional_caching/js_fragment_cached_with_partial.js.rjs
|
73
|
+
- test/fixtures/old_content_type/render_default_for_rjs.rjs
|
74
|
+
- test/fixtures/respond_to/all_types_with_layout.js.rjs
|
75
|
+
- test/fixtures/respond_to/layouts/standard.html.erb
|
76
|
+
- test/fixtures/respond_to/using_defaults.js.rjs
|
77
|
+
- test/fixtures/respond_to/using_defaults_with_type_list.js.rjs
|
78
|
+
- test/fixtures/respond_with/using_resource.js.rjs
|
79
|
+
- test/fixtures/test/_one.html.erb
|
80
|
+
- test/fixtures/test/_partial.html.erb
|
81
|
+
- test/fixtures/test/_partial.js.erb
|
82
|
+
- test/fixtures/test/_two.html.erb
|
83
|
+
- test/fixtures/test/delete_with_js.rjs
|
84
|
+
- test/fixtures/test/enum_rjs_test.rjs
|
85
|
+
- test/fixtures/test/greeting.js.rjs
|
86
|
+
- test/fixtures/test/render_explicit_html_template.js.rjs
|
87
|
+
- test/fixtures/test/render_implicit_html_template.js.rjs
|
88
|
+
- test/javascript_helper_test.rb
|
89
|
+
- test/lib/controller/fake_models.rb
|
90
|
+
- test/render_other_test.rb
|
91
|
+
- test/template/prototype_helper_test.rb
|
92
|
+
- test/template/render_test.rb
|
93
|
+
- test/template/scriptaculous_helper_test.rb
|
94
|
+
has_rdoc: true
|
95
|
+
homepage: http://github.com/rails/prototype-rails
|
96
|
+
licenses: []
|
97
|
+
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
version: "0"
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
version: "0"
|
119
|
+
requirements: []
|
120
|
+
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 1.3.7
|
123
|
+
signing_key:
|
124
|
+
specification_version: 3
|
125
|
+
summary: Prototype, Scriptaculous, and RJS for Ruby on Rails
|
126
|
+
test_files: []
|
127
|
+
|