button_link_to 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/README.md +44 -2
- data/app/assets/javascripts/button_link_to.js +29 -24
- data/lib/button_link_to/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ec700768bf132c1138738e049471ecfe712f06ad
|
|
4
|
+
data.tar.gz: 4fd622ecc4844fe5770fc340fe6b2e42e3b5da87
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c8bd903df8db0cd04f08ce161265f5c1518daf4ecc53b339aea18bc4ef449c7fb0f2595e91b7c4b99c11274d5839e4416c2ed7be8cbab31a48e286d939a17cb0
|
|
7
|
+
data.tar.gz: 093cab5d34c65b4e3a945e98e80a204527ec22161986e74dfdc5a83444b440c9aca0dc6cfa1dae0d0972585eb69692fa07d8384b2812a91d6a1d8e4077c955fb
|
data/README.md
CHANGED
|
@@ -6,15 +6,57 @@ A button version of Rails link_to helper
|
|
|
6
6
|
|
|
7
7
|
Add this line to your application's Gemfile:
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'button_link_to'
|
|
11
|
+
```
|
|
10
12
|
|
|
11
13
|
And then execute:
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
```bash
|
|
16
|
+
$ bundle
|
|
17
|
+
```
|
|
14
18
|
|
|
19
|
+
Add the following lines to app/assets/javascript/application.js:
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
//= require jquery_ujs
|
|
23
|
+
//= require button_link_to
|
|
24
|
+
```
|
|
15
25
|
|
|
16
26
|
## Usage
|
|
17
27
|
|
|
28
|
+
You can use button_link_to helper in your view just like link_to helper in Rails.
|
|
29
|
+
|
|
30
|
+
Send a delete ajax
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
button_link_to "Delete Comment", comment_path(@comment), :remote => true, :method => :delete
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Send a form with delete method
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
button_link_to "Delete Comment", comment_path(@comment), :method => :delete
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
Send a form with delete method and show confirm message
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
button_link_to "Delete Comment", comment_path(@comment), :method => :delete, :confirm => "Are you sure?"
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
HTML button by send block parameter
|
|
52
|
+
|
|
53
|
+
```html
|
|
54
|
+
button_link_to , comment_path(@comment), :remote => true, :class => "btn-link" do
|
|
55
|
+
<i class="icon-remove"></i> Delete Comment
|
|
56
|
+
end
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
|
|
18
60
|
|
|
19
61
|
## Contributing
|
|
20
62
|
|
|
@@ -1,31 +1,36 @@
|
|
|
1
|
+
(function() {
|
|
2
|
+
// jquery ujs hack for remote ajax button
|
|
3
|
+
$(document).on("mouseup", "button[data-remote]", function(e) {
|
|
4
|
+
// middle button click
|
|
5
|
+
if(e.which == 2) {
|
|
6
|
+
$(e.currentTarget).trigger("click.rails")
|
|
7
|
+
}
|
|
8
|
+
});
|
|
1
9
|
|
|
2
|
-
|
|
3
|
-
$(
|
|
4
|
-
|
|
5
|
-
if(e.which == 2) {
|
|
6
|
-
$(e.currentTarget).trigger("click.rails")
|
|
7
|
-
}
|
|
8
|
-
});
|
|
10
|
+
$(document).on("click.rails", "button[data-method]", function(e) {
|
|
11
|
+
if (!$.rails.allowAction($(e.currentTarget))) return $.rails.stopEverything(e);
|
|
12
|
+
});
|
|
9
13
|
|
|
10
|
-
// jquery ujs hack for form restful button
|
|
11
|
-
$(document).on("click.rails", "button[data-method]", function(e) {
|
|
12
|
-
|
|
14
|
+
// jquery ujs hack for form restful button
|
|
15
|
+
$(document).on("click.rails", "button[data-method]", function(e) {
|
|
16
|
+
button = $(e.currentTarget)
|
|
13
17
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
var url = button.data("url"),
|
|
19
|
+
method = button.data('method'),
|
|
20
|
+
target = button.data('target'),
|
|
21
|
+
csrf_token = $('meta[name=csrf-token]').attr('content'),
|
|
22
|
+
csrf_param = $('meta[name=csrf-param]').attr('content'),
|
|
23
|
+
form = $('<form method="post" action="' + url + '"></form>'),
|
|
24
|
+
metadata_input = '<input name="_method" value="' + method + '" type="hidden" />';
|
|
21
25
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
if (csrf_param !== undefined && csrf_token !== undefined) {
|
|
27
|
+
metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />';
|
|
28
|
+
}
|
|
25
29
|
|
|
26
|
-
|
|
30
|
+
if (target) { form.attr('target', target); }
|
|
27
31
|
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
form.hide().append(metadata_input).appendTo('body');
|
|
33
|
+
form.submit();
|
|
30
34
|
|
|
31
|
-
});
|
|
35
|
+
});
|
|
36
|
+
})();
|