cruyff 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/Readme.md +29 -0
- data/SpecRunner.html +43 -0
- data/cruyff.gemspec +21 -0
- data/lib/cruyff/version.rb +3 -0
- data/lib/generators/cruyff_generator.rb +14 -0
- data/lib/generators/templates/jquery.cruyff.js +174 -0
- data/spec/CruyffSpec.js +159 -0
- data/spec/SpecHelper.js +0 -0
- data/spec/fixtures/view.html +1 -0
- data/spec/js_lib/jasmine-1.0.1/jasmine-html.js +188 -0
- data/spec/js_lib/jasmine-1.0.1/jasmine.css +166 -0
- data/spec/js_lib/jasmine-1.0.1/jasmine.js +2421 -0
- data/spec/js_lib/jasmine-fixture.js +24 -0
- data/spec/js_lib/jasmine-jquery-1.1.3.js +205 -0
- data/spec/js_lib/jquery-1.4.4.js +7179 -0
- data/spec/js_lib/jquery.ba-bbq-1.2.1.js +1137 -0
- data/spec/js_lib/jquery.form-2.52.js +791 -0
- data/spec/js_lib/rails-11.01.12.js +137 -0
- metadata +99 -0
@@ -0,0 +1,137 @@
|
|
1
|
+
/**
|
2
|
+
* Unobtrusive scripting adapter for jQuery
|
3
|
+
*
|
4
|
+
* Requires jQuery 1.4.3 or later.
|
5
|
+
* https://github.com/rails/jquery-ujs
|
6
|
+
*/
|
7
|
+
|
8
|
+
(function($) {
|
9
|
+
// Triggers an event on an element and returns the event result
|
10
|
+
function fire(obj, name, data) {
|
11
|
+
var event = new $.Event(name);
|
12
|
+
obj.trigger(event, data);
|
13
|
+
return event.result !== false;
|
14
|
+
}
|
15
|
+
|
16
|
+
// Submits "remote" forms and links with ajax
|
17
|
+
function handleRemote(element) {
|
18
|
+
var method, url, data,
|
19
|
+
dataType = element.attr('data-type') || ($.ajaxSettings && $.ajaxSettings.dataType);
|
20
|
+
|
21
|
+
if (element.is('form')) {
|
22
|
+
method = element.attr('method');
|
23
|
+
url = element.attr('action');
|
24
|
+
data = element.serializeArray();
|
25
|
+
// memoized value from clicked submit button
|
26
|
+
var button = element.data('ujs:submit-button');
|
27
|
+
if (button) {
|
28
|
+
data.push(button);
|
29
|
+
element.data('ujs:submit-button', null);
|
30
|
+
}
|
31
|
+
} else {
|
32
|
+
method = element.attr('data-method');
|
33
|
+
url = element.attr('href');
|
34
|
+
data = null;
|
35
|
+
}
|
36
|
+
|
37
|
+
$.ajax({
|
38
|
+
url: url, type: method || 'GET', data: data, dataType: dataType,
|
39
|
+
// stopping the "ajax:beforeSend" event will cancel the ajax request
|
40
|
+
beforeSend: function(xhr, settings) {
|
41
|
+
if (settings.dataType === undefined) {
|
42
|
+
xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script);
|
43
|
+
}
|
44
|
+
return fire(element, 'ajax:beforeSend', [xhr, settings]);
|
45
|
+
},
|
46
|
+
success: function(data, status, xhr) {
|
47
|
+
element.trigger('ajax:success', [data, status, xhr]);
|
48
|
+
},
|
49
|
+
complete: function(xhr, status) {
|
50
|
+
element.trigger('ajax:complete', [xhr, status]);
|
51
|
+
},
|
52
|
+
error: function(xhr, status, error) {
|
53
|
+
element.trigger('ajax:error', [xhr, status, error]);
|
54
|
+
}
|
55
|
+
});
|
56
|
+
}
|
57
|
+
|
58
|
+
// Handles "data-method" on links such as:
|
59
|
+
// <a href="/users/5" data-method="delete" rel="nofollow" data-confirm="Are you sure?">Delete</a>
|
60
|
+
function handleMethod(link) {
|
61
|
+
var href = link.attr('href'),
|
62
|
+
method = link.attr('data-method'),
|
63
|
+
csrf_token = $('meta[name=csrf-token]').attr('content'),
|
64
|
+
csrf_param = $('meta[name=csrf-param]').attr('content'),
|
65
|
+
form = $('<form method="post" action="' + href + '"></form>'),
|
66
|
+
metadata_input = '<input name="_method" value="' + method + '" type="hidden" />';
|
67
|
+
|
68
|
+
if (csrf_param !== undefined && csrf_token !== undefined) {
|
69
|
+
metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />';
|
70
|
+
}
|
71
|
+
|
72
|
+
form.hide().append(metadata_input).appendTo('body');
|
73
|
+
form.submit();
|
74
|
+
}
|
75
|
+
|
76
|
+
function disableFormElements(form) {
|
77
|
+
form.find('input[data-disable-with]').each(function() {
|
78
|
+
var input = $(this);
|
79
|
+
input.data('ujs:enable-with', input.val())
|
80
|
+
.val(input.attr('data-disable-with'))
|
81
|
+
.attr('disabled', 'disabled');
|
82
|
+
});
|
83
|
+
}
|
84
|
+
|
85
|
+
function enableFormElements(form) {
|
86
|
+
form.find('input[data-disable-with]').each(function() {
|
87
|
+
var input = $(this);
|
88
|
+
input.val(input.data('ujs:enable-with')).removeAttr('disabled');
|
89
|
+
});
|
90
|
+
}
|
91
|
+
|
92
|
+
function allowAction(element) {
|
93
|
+
var message = element.attr('data-confirm');
|
94
|
+
return !message || (fire(element, 'confirm') && confirm(message));
|
95
|
+
}
|
96
|
+
|
97
|
+
$('a[data-confirm], a[data-method], a[data-remote]').live('click.rails', function(e) {
|
98
|
+
var link = $(this);
|
99
|
+
if (!allowAction(link)) return false;
|
100
|
+
|
101
|
+
if (link.attr('data-remote')) {
|
102
|
+
handleRemote(link);
|
103
|
+
return false;
|
104
|
+
} else if (link.attr('data-method')) {
|
105
|
+
handleMethod(link);
|
106
|
+
return false;
|
107
|
+
}
|
108
|
+
});
|
109
|
+
|
110
|
+
$('form').live('submit.rails', function(e) {
|
111
|
+
var form = $(this);
|
112
|
+
if (!allowAction(form)) return false;
|
113
|
+
|
114
|
+
if (form.attr('data-remote')) {
|
115
|
+
handleRemote(form);
|
116
|
+
return false;
|
117
|
+
} else {
|
118
|
+
disableFormElements(form);
|
119
|
+
}
|
120
|
+
});
|
121
|
+
|
122
|
+
$('form input[type=submit], form button[type=submit], form button:not([type])').live('click.rails', function() {
|
123
|
+
var button = $(this);
|
124
|
+
if (!allowAction(button)) return false;
|
125
|
+
// register the pressed submit button
|
126
|
+
var name = button.attr('name'), data = name ? {name:name, value:button.val()} : null;
|
127
|
+
button.closest('form').data('ujs:submit-button', data);
|
128
|
+
});
|
129
|
+
|
130
|
+
$('form').live('ajax:beforeSend.rails', function(event) {
|
131
|
+
if (this == event.target) disableFormElements($(this));
|
132
|
+
});
|
133
|
+
|
134
|
+
$('form').live('ajax:complete.rails', function(event) {
|
135
|
+
if (this == event.target) enableFormElements($(this));
|
136
|
+
});
|
137
|
+
})( jQuery );
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cruyff
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Charger Tec
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-20 00:00:00 -02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: jquery-rails
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 2
|
31
|
+
- 6
|
32
|
+
version: 0.2.6
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Cruyff is a Ajax CRUD solution for Rails applications.
|
36
|
+
email:
|
37
|
+
- DM @andrefarina
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- Gemfile
|
47
|
+
- Rakefile
|
48
|
+
- Readme.md
|
49
|
+
- SpecRunner.html
|
50
|
+
- cruyff.gemspec
|
51
|
+
- lib/cruyff/version.rb
|
52
|
+
- lib/generators/cruyff_generator.rb
|
53
|
+
- lib/generators/templates/jquery.cruyff.js
|
54
|
+
- spec/CruyffSpec.js
|
55
|
+
- spec/SpecHelper.js
|
56
|
+
- spec/fixtures/view.html
|
57
|
+
- spec/js_lib/jasmine-1.0.1/jasmine-html.js
|
58
|
+
- spec/js_lib/jasmine-1.0.1/jasmine.css
|
59
|
+
- spec/js_lib/jasmine-1.0.1/jasmine.js
|
60
|
+
- spec/js_lib/jasmine-fixture.js
|
61
|
+
- spec/js_lib/jasmine-jquery-1.1.3.js
|
62
|
+
- spec/js_lib/jquery-1.4.4.js
|
63
|
+
- spec/js_lib/jquery.ba-bbq-1.2.1.js
|
64
|
+
- spec/js_lib/jquery.form-2.52.js
|
65
|
+
- spec/js_lib/rails-11.01.12.js
|
66
|
+
has_rdoc: true
|
67
|
+
homepage: https://github.com/andref5/cruyff
|
68
|
+
licenses: []
|
69
|
+
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
requirements: []
|
92
|
+
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 1.3.7
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: Ajax CRUD solution for Rails applications.
|
98
|
+
test_files: []
|
99
|
+
|