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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b0ab80e421367cd685e605c95646314a3f28432
4
- data.tar.gz: 25248e9d98500f8126b8eda393635245e06ee643
3
+ metadata.gz: ec700768bf132c1138738e049471ecfe712f06ad
4
+ data.tar.gz: 4fd622ecc4844fe5770fc340fe6b2e42e3b5da87
5
5
  SHA512:
6
- metadata.gz: 9912b76898e8eb8332c6ebd439fc96e5cfdb244ef806f0566baeea34a2adaefbdc2037dbb3397e0ed5cad6daa8fb689c1f7c6078059486417024be4c6def905f
7
- data.tar.gz: d987859782ce6e7af1a7ebbb26a41a1cf28fda1affafbf68c4ff6036b13a38ef07fcbde97e37e6fc01187f71a43af7f2f1624ccf88c4458f109490adb5ce1aac
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
- gem 'button_link_to'
9
+ ```ruby
10
+ gem 'button_link_to'
11
+ ```
10
12
 
11
13
  And then execute:
12
14
 
13
- $ bundle
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
- // 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
- });
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
- button = $(e.currentTarget)
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
- var url = button.data("url"),
15
- method = button.data('method'),
16
- target = button.data('target'),
17
- csrf_token = $('meta[name=csrf-token]').attr('content'),
18
- csrf_param = $('meta[name=csrf-param]').attr('content'),
19
- form = $('<form method="post" action="' + url + '"></form>'),
20
- metadata_input = '<input name="_method" value="' + method + '" type="hidden" />';
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
- if (csrf_param !== undefined && csrf_token !== undefined) {
23
- metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />';
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
- if (target) { form.attr('target', target); }
30
+ if (target) { form.attr('target', target); }
27
31
 
28
- form.hide().append(metadata_input).appendTo('body');
29
- form.submit();
32
+ form.hide().append(metadata_input).appendTo('body');
33
+ form.submit();
30
34
 
31
- });
35
+ });
36
+ })();
@@ -1,3 +1,3 @@
1
1
  module ButtonLinkTo
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: button_link_to
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - tonilin