abracadabra 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d4e4740ccd71a82f5d189f3db3e1ebd524a4d1d
4
- data.tar.gz: 5892da4ddc2675a8b6b9b9a7d56ba69669299341
3
+ metadata.gz: 7cb45804338fe71758c94d2b1d99dc80ab717d8a
4
+ data.tar.gz: 530aeb3bae6e383a2b38e80eebc69b244506882a
5
5
  SHA512:
6
- metadata.gz: 310f8d4e36515555ba7776da77d22558d7855ac23b54a74bd228f979b80ebb2b6a41151927665dbea59def894fd0d2cd639b8f9643e73ccdd39709d090175617
7
- data.tar.gz: 39501d3e2e6ea72bdfe5e5e93ebfa20351744d00451e1b10b289fe6e37552d72d94c0012d7057dc3f4651b8a1f3fcd2c8802e56cee72de88dc9f306c71144f71
6
+ metadata.gz: 73fecc08bc118c530dc84389865f346ece46b5ef6ab3faa8dcfda9f80fb2a1c04111d75ef763e44b956b09dc16389330fa4ee9a297874df5f58ddb6bfad9db7f
7
+ data.tar.gz: 14995d84dff4f4369643cecbd528e46218fad781381090c06ea1bb2054cfa3a720f3621941b515edc0b37d35916d2c143115971d57c28cf7808e9278a9ab9491
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Abracadabra
2
2
 
3
- A lightweight gem for swapping out text with a fully-compliant Rails form in one click.
3
+ A lightweight gem for swapping out text with a fully-compliant Rails 4 form in one click.
4
4
 
5
5
  Much of the concepts and html mark-up were taken from the awesome [x-editable](http://vitalets.github.io/x-editable/) plugin and the Rails version of this, [x-editable-rails](https://github.com/werein/x-editable-rails). However, this was written from the ground up and uses fully Rails-compliant forms without hacking into x-editable's core files, or overriding them.
6
6
 
@@ -36,13 +36,13 @@ In your `application.js`, AFTER Jquery (required), include the javascript file:
36
36
 
37
37
  ## Helpers
38
38
 
39
- The bread and butter of abracadabra is its helper, `click_to_edit`. Its pretty much as readable as it gets:
39
+ The bread and butter of abracadabra is its helper, `click_to_edit`. It's pretty much as readable as it gets:
40
40
 
41
41
  ```ruby
42
42
  <%= click_to_edit @user, path: user_path(@user), attribute: :name %>
43
43
  ```
44
44
 
45
- When a user clicks the link generated by this helper, a form with a text field input will replace the link. It's fully Rails compliant, and looks identical to a `form_for` with `remote: true`. Here's what it looks like:
45
+ When a user clicks the link generated by this helper, a form with a text field input will replace the link. It's fully Rails compliant, and the form markup that is generated is identical to a `form_for` with `remote: true`. Here's what it looks like:
46
46
 
47
47
  ![Abracadabra Demo](http://recordit.co/CbgPTahYix.gif "Abracadabra Demo")
48
48
 
@@ -73,7 +73,7 @@ method: "patch"
73
73
  # Default: "patch"
74
74
 
75
75
  remote: true
76
- # Same as link_to's remote: true, form submits via AJAX.
76
+ # Same as link_to's `remote: true`, form submits via AJAX.
77
77
  # Default: true
78
78
 
79
79
  # IMPORTANT: `type` will be ignored if `remote = false` is used. HTML is the default
@@ -89,6 +89,10 @@ type: :js
89
89
 
90
90
  2. I would love the different Bootstrap classes to be overridable with an initializer (config/abracadabra.rb) so that any framework could be used. Same with the Font-Awesome button classes.
91
91
 
92
+ 3. I would love for a `buttons: false` option to be offered that would allow only `Tab`, `Enter` and `Escape` to submit or cancel the form submission.
93
+
94
+ 4. I would love for a `tabbable: true` option to be offered that would tab to the next text input with the `abracadabra` class.
95
+
92
96
  Any other ideas, feel free to contribute!
93
97
 
94
98
  1. Fork it ( http://github.com/TrevorHinesley/abracadabra/fork )
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Abracadabra::Rails::VERSION
9
9
  spec.authors = ["Trevor Hinesley"]
10
10
  spec.email = ["trevor.hinesley@gmail.com"]
11
- spec.summary = %q{A lightweight gem for swapping out text with a fully-compliant Rails form in one click using JQuery.}
12
- spec.description = %q{Abracadabra: A lightweight gem for swapping out text with a fully-compliant Rails form in one click using JQuery and rails.js.}
11
+ spec.summary = %q{A lightweight gem for swapping out text with a fully-compliant Rails 4 form in one click using JQuery.}
12
+ spec.description = %q{Abracadabra: A lightweight gem for swapping out text with a fully-compliant Rails 4 form in one click using JQuery and rails.js.}
13
13
  spec.homepage = "https://github.com/TrevorHinesley/abracadabra"
14
14
  spec.license = "MIT"
15
15
 
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "rails", ">= 4.0.0"
21
+ spec.add_dependency "rails", ">= 3.2.11"
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.5"
24
24
  spec.add_development_dependency "rake"
@@ -1,21 +1,38 @@
1
1
  $(function() {
2
+ function closeAbracadabra(element) {
3
+ $element = $(element);
4
+ if($element.hasClass("abracadabra-container")) {
5
+ container = $element;
6
+ } else {
7
+ container = $element.parents(".abracadabra-container");
8
+ }
9
+ value = container.find(".abracadabra-input").val();
10
+ container.siblings(".abracadabra").text(value).show();
11
+ container.remove();
12
+ }
13
+
2
14
  $("body").on("ajax:success", ".abracadabra-form", function(e) {
3
- $(e.target).find(".abracadabra-cancel").click();
15
+ closeAbracadabra(this);
4
16
  })
5
17
 
6
18
  $("body").on("click", ".abracadabra-cancel", function() {
7
- container = $(this).closest(".abracadabra-container");
8
- value = $(this).parents(".abracadabra-buttons").siblings().find("input").val();
9
- container.siblings(".abracadabra").text(value).show();
10
- $(this).closest(".abracadabra-container").remove();
19
+ closeAbracadabra(this);
11
20
  });
12
21
 
13
- $("body").on("keydown", ".abracadabra-input input", function(e) {
14
- if (e.which == 9)
22
+ $("body").on("keydown", ".abracadabra-input", function(e) {
23
+ // Press Tab to submit (same function as Enter key)
24
+ if (e.keyCode == 9)
15
25
  {
16
26
  e.preventDefault();
17
27
  $(this.form).submit();
18
28
  }
29
+
30
+ // Press Escape to cancel
31
+ if (e.keyCode == 27)
32
+ {
33
+ e.preventDefault();
34
+ closeAbracadabra(this);
35
+ }
19
36
  });
20
37
 
21
38
  $(".abracadabra").on("click", function() {
@@ -23,29 +40,29 @@ $(function() {
23
40
  link.hide();
24
41
  path = link.data("path");
25
42
  attribute = link.data("attribute");
26
- form_method = link.data("method");
43
+ formMethod = link.data("method");
27
44
  remote = ((link.data("remote") == true) ? " data-remote=\"true\"" : "");
28
45
 
29
46
  if(remote == "") {
30
- auth_token = "<input name=\"authenticity_token\" type=\"hidden\" value=\"" + $("meta[name=\"csrf-token\"]").attr("content") + "\">";
47
+ authToken = "<input name=\"authenticity_token\" type=\"hidden\" value=\"" + $("meta[name=\"csrf-token\"]").attr("content") + "\">";
31
48
  type = "";
32
49
  } else {
33
- auth_token = "";
50
+ authToken = "";
34
51
  type = " data-type=\"" + link.data("type") + "\"";
35
52
  }
36
53
 
37
- instance_class = link.data("class");
38
- input_value = link.text().replace(/"|\\"/g, "&quot;");
39
- input_id = instance_class + "_" + attribute;
40
- input_name = instance_class + "[" + attribute + "]";
54
+ instanceClass = link.data("class");
55
+ inputValue = link.text().replace(/"|\\"/g, "&quot;");
56
+ inputId = instanceClass + "_" + attribute;
57
+ inputName = instanceClass + "[" + attribute + "]";
41
58
 
42
59
  buttons = "<button type=\"submit\" class=\"btn btn-primary abracadabra-submit\"><i class=\"fa fa-check\"></i></button><button type=\"button\" class=\"btn abracadabra-cancel\"><i class=\"fa fa-times\"></i></button>";
43
- open_form_tag = "<form accept-charset=\"UTF-8\" action=\"" + path + "\"" + remote + type + " class=\"form-inline abracadabra-form\" method=\"post\">";
44
- hidden_method_tags = "<div style=\"display:none;\"><input name=\"utf8\" type=\"hidden\" value=\"&#10003;\"><input name=\"_method\" type=\"hidden\" value=\"" + form_method + "\">" + auth_token + "</div>";
45
- input = "<input type=\"text\" class=\"form-control\" id=\"" + input_id + "\" name=\"" + input_name + "\" value=\"" + input_value + "\">";
60
+ openFormTag = "<form accept-charset=\"UTF-8\" action=\"" + path + "\"" + remote + type + " class=\"form-inline abracadabra-form\" method=\"post\">";
61
+ hiddenMethodTags = "<div style=\"display:none;\"><input name=\"utf8\" type=\"hidden\" value=\"&#10003;\"><input name=\"_method\" type=\"hidden\" value=\"" + formMethod + "\">" + authToken + "</div>";
62
+ input = "<input type=\"text\" class=\"form-control abracadabra-input\" id=\"" + inputId + "\" name=\"" + inputName + "\" value=\"" + inputValue + "\">";
46
63
 
47
- html = "<span class=\"abracadabra-container abracadabra-inline\">" + open_form_tag + hidden_method_tags;
48
- html += "<div class=\"control-group\"><div><div class=\"abracadabra-input\">" + input + "</div>";
64
+ html = "<span class=\"abracadabra-container abracadabra-inline\">" + openFormTag + hiddenMethodTags;
65
+ html += "<div class=\"control-group\"><div class=\"abracadabra-input-and-button-wrapper\"><div class=\"abracadabra-input-container\">" + input + "</div>";
49
66
  html += "<div class=\"abracadabra-buttons\">" + buttons + "</div></div></form></span>";
50
67
 
51
68
  link.after(html);
@@ -10,12 +10,12 @@
10
10
 
11
11
  .abracadabra-container { display: block; }
12
12
 
13
- .abracadabra-container > form > .control-group > div > .abracadabra-input {
13
+ .abracadabra-container > .abracadabra-form > .control-group > .abracadabra-input-and-button-wrapper > .abracadabra-input-container {
14
14
  width: 60%;
15
15
  display: inline-block;
16
16
  }
17
17
 
18
- .abracadabra-container > form > .control-group > div > .abracadabra-buttons {
18
+ .abracadabra-container > .abracadabra-form > .control-group > .abracadabra-input-and-button-wrapper > .abracadabra-buttons {
19
19
  width: 40%;
20
20
  display: inline-block;
21
21
  }
@@ -1,5 +1,5 @@
1
1
  module Abracadabra
2
2
  module Rails
3
- VERSION = "1.0.4"
3
+ VERSION = "1.0.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abracadabra
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trevor Hinesley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-31 00:00:00.000000000 Z
11
+ date: 2014-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.0.0
19
+ version: 3.2.11
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 4.0.0
26
+ version: 3.2.11
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: 'Abracadabra: A lightweight gem for swapping out text with a fully-compliant
56
- Rails form in one click using JQuery and rails.js.'
56
+ Rails 4 form in one click using JQuery and rails.js.'
57
57
  email:
58
58
  - trevor.hinesley@gmail.com
59
59
  executables: []
@@ -149,7 +149,7 @@ rubyforge_project:
149
149
  rubygems_version: 2.2.2
150
150
  signing_key:
151
151
  specification_version: 4
152
- summary: A lightweight gem for swapping out text with a fully-compliant Rails form
152
+ summary: A lightweight gem for swapping out text with a fully-compliant Rails 4 form
153
153
  in one click using JQuery.
154
154
  test_files:
155
155
  - test/dummy/.gitignore