hammock 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/VERSION +1 -1
- data/hammock.gemspec +2 -1
- data/lib/hammock/ajaxinate.rb +9 -55
- data/public/javascripts/ajax.js +53 -0
- metadata +2 -1
data/History.txt
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
== 0.5.0 2009-10-27
|
2
|
+
Redesigned ajaxinate implementation - instead of rendering JS separately for every link, use one generic method and a link map to store details for each link.
|
3
|
+
|
4
|
+
|
1
5
|
== 0.4.2 2009-10-27
|
2
6
|
Check rendered_or_redirected? on XHR requests as well as normal ones.
|
3
7
|
Fix #ajaxinate to handle multiple entities.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/hammock.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{hammock}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ben Hoskings"]
|
@@ -68,6 +68,7 @@ Gem::Specification.new do |s|
|
|
68
68
|
"lib/hammock/utils.rb",
|
69
69
|
"misc/scaffold.txt",
|
70
70
|
"misc/template.rb",
|
71
|
+
"public/javascripts/ajax.js",
|
71
72
|
"tasks/hammock_tasks.rake"
|
72
73
|
]
|
73
74
|
s.homepage = %q{http://github.com/benhoskings/hammock}
|
data/lib/hammock/ajaxinate.rb
CHANGED
@@ -22,7 +22,7 @@ module Hammock
|
|
22
22
|
|
23
23
|
content_tag :a,
|
24
24
|
opts[:text] || route.verb.to_s.capitalize,
|
25
|
-
:class => [opts[:class], link_class_for(route.verb, entities)].squash.join(' '),
|
25
|
+
:class => ['hammock', opts[:class], link_class_for(route.verb, entities), "hammock_link_#{link_class_for(route.verb, entities)}"].squash.join(' '),
|
26
26
|
:href => route.path,
|
27
27
|
:onclick => 'return false;',
|
28
28
|
:style => opts[:style]
|
@@ -37,64 +37,18 @@ module Hammock
|
|
37
37
|
attribute = link_params[:attribute]
|
38
38
|
link_class = link_class_for route.verb, entities, attribute
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
"jQuery('form').serializeHash()"
|
47
|
-
else
|
48
|
-
"{ '#{entity.base_model}[#{attribute}]': $('.#{link_class}').val() }"
|
49
|
-
end
|
50
|
-
|
51
|
-
response_action = case link_params[:format].to_s
|
52
|
-
when 'js'
|
53
|
-
"eval(response);"
|
54
|
-
else
|
55
|
-
"jQuery('.#{opts[:target] || link_class + '_target'}').before(response).remove();"
|
56
|
-
end
|
57
|
-
|
58
|
-
# TODO check the response code in the callback, and replace :after with :success and :failure.
|
59
|
-
js = %Q{
|
60
|
-
jQuery('.#{link_class}').#{opts[:on] || 'click'}(function() {
|
61
|
-
var obj = null;
|
62
|
-
|
63
|
-
if (#{opts[:spinner] ? 'true' : 'false'}) {
|
64
|
-
obj = jQuery(this).parent().find('.statuses');
|
65
|
-
obj.find('.spinner').animate({opacity: 'show'}, 100);
|
66
|
-
}
|
67
|
-
|
68
|
-
/*if (#{attribute.blank? ? 'false' : 'true'} && (jQuery('.#{link_class}_target .original_value').html() == jQuery('.#{link_class}_target .modify input').val())) {
|
69
|
-
eval("#{clean_snippet opts[:skipped]}");
|
70
|
-
} else*/ if (false == eval("#{clean_snippet opts[:before]}")) {
|
71
|
-
// before callback failed
|
72
|
-
} else { // fire the request
|
73
|
-
jQuery.#{route.fake_http_method}(
|
74
|
-
'#{route.path}',
|
75
|
-
jQuery.extend(
|
76
|
-
#{record_attributes.to_flattened_json},
|
77
|
-
#{form_elements_hash},
|
78
|
-
#{link_params.to_flattened_json},
|
79
|
-
#{forgery_key_json(route.http_method)}
|
80
|
-
),
|
81
|
-
function(response, textStatus) {
|
82
|
-
#{response_action}
|
83
|
-
if (obj) {
|
84
|
-
obj.children('.spinner').hide();
|
85
|
-
#{"if ('success' == textStatus) obj.children('.success').show().fadeOut(4000);" if opts[:spinner] != :pending}
|
86
|
-
}
|
87
|
-
eval("#{clean_snippet opts[:after]}");
|
88
|
-
}
|
89
|
-
);
|
90
|
-
}
|
91
|
-
});
|
40
|
+
link_data = {
|
41
|
+
:klass => link_class,
|
42
|
+
:path => route.path,
|
43
|
+
:http_method => route.http_method,
|
44
|
+
:fake_http_method => route.fake_http_method,
|
45
|
+
:format => (opts[:format].blank? ? 'html' : opts[:format].to_s)
|
92
46
|
}
|
93
47
|
|
94
|
-
append_javascript
|
48
|
+
append_javascript %Q{hammock_link_map['#{link_class}'] = #{link_data.to_json};}
|
95
49
|
route
|
96
50
|
end
|
97
|
-
|
51
|
+
|
98
52
|
def status_callback
|
99
53
|
%Q{
|
100
54
|
if ('success' == textStatus) {
|
@@ -0,0 +1,53 @@
|
|
1
|
+
var KEYS = { BACKSPACE:8, TAB:9, RETURN:13, ENTER:3, ESC:27, SPACE:32, LEFT:37, UP:38, RIGHT:39, DOWN:40, DELETE:46 };
|
2
|
+
|
3
|
+
var hammock_link_map = {};
|
4
|
+
|
5
|
+
var hamlink_log = function(link_key, message) {
|
6
|
+
if (console.log) console.log(link_key + ": " + message);
|
7
|
+
};
|
8
|
+
|
9
|
+
var hammock_ajax = function() {
|
10
|
+
$('a.hammock').live('click', function() {
|
11
|
+
link_key = $(this).attr('class').match(/hammock_link_(\w+)/)[1];
|
12
|
+
if (!hammock_link_map[link_key]) {
|
13
|
+
hamlink_log(link_key, 'no entry in link map');
|
14
|
+
} else {
|
15
|
+
fire_hammock_ajax(hammock_link_map[link_key]);
|
16
|
+
}
|
17
|
+
});
|
18
|
+
};
|
19
|
+
|
20
|
+
var fire_hammock_ajax = function(data) {
|
21
|
+
var obj = null;
|
22
|
+
|
23
|
+
if (data.spinner) {
|
24
|
+
obj = jQuery(this).parent().find('.statuses');
|
25
|
+
obj.find('.spinner').animate({opacity: 'show'}, 100);
|
26
|
+
}
|
27
|
+
|
28
|
+
if (data.before && false == data.before()) {
|
29
|
+
hamlink_log(data.klass, "before callback failed.");
|
30
|
+
} else {
|
31
|
+
jQuery[data.fake_http_method](
|
32
|
+
data.path,
|
33
|
+
{
|
34
|
+
'_method': data.http_method,
|
35
|
+
'format': data.format
|
36
|
+
},
|
37
|
+
function(response, textStatus) {
|
38
|
+
if (data.format == 'js') {
|
39
|
+
eval(response);
|
40
|
+
} else {
|
41
|
+
jQuery('.' + (data.target || data.klass + '_target')).before(response).remove();
|
42
|
+
}
|
43
|
+
if (data.after && false == data.after()) {
|
44
|
+
hamlink_log(data.klass, "after callback failed.");
|
45
|
+
}
|
46
|
+
}
|
47
|
+
);
|
48
|
+
}
|
49
|
+
};
|
50
|
+
|
51
|
+
$(function() {
|
52
|
+
hammock_ajax();
|
53
|
+
});
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hammock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Hoskings
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- lib/hammock/utils.rb
|
94
94
|
- misc/scaffold.txt
|
95
95
|
- misc/template.rb
|
96
|
+
- public/javascripts/ajax.js
|
96
97
|
- tasks/hammock_tasks.rake
|
97
98
|
has_rdoc: true
|
98
99
|
homepage: http://github.com/benhoskings/hammock
|