abracadabra 1.0.4 → 1.0.5
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 +8 -4
- data/abracadabra.gemspec +3 -3
- data/app/assets/javascripts/abracadabra.js +36 -19
- data/app/assets/stylesheets/abracadabra.css +2 -2
- data/lib/abracadabra/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cb45804338fe71758c94d2b1d99dc80ab717d8a
|
4
|
+
data.tar.gz: 530aeb3bae6e383a2b38e80eebc69b244506882a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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`.
|
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
|
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
|

|
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
|
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 )
|
data/abracadabra.gemspec
CHANGED
@@ -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", ">=
|
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
|
-
|
15
|
+
closeAbracadabra(this);
|
4
16
|
})
|
5
17
|
|
6
18
|
$("body").on("click", ".abracadabra-cancel", function() {
|
7
|
-
|
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
|
14
|
-
|
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
|
-
|
43
|
+
formMethod = link.data("method");
|
27
44
|
remote = ((link.data("remote") == true) ? " data-remote=\"true\"" : "");
|
28
45
|
|
29
46
|
if(remote == "") {
|
30
|
-
|
47
|
+
authToken = "<input name=\"authenticity_token\" type=\"hidden\" value=\"" + $("meta[name=\"csrf-token\"]").attr("content") + "\">";
|
31
48
|
type = "";
|
32
49
|
} else {
|
33
|
-
|
50
|
+
authToken = "";
|
34
51
|
type = " data-type=\"" + link.data("type") + "\"";
|
35
52
|
}
|
36
53
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
54
|
+
instanceClass = link.data("class");
|
55
|
+
inputValue = link.text().replace(/"|\\"/g, """);
|
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
|
-
|
44
|
-
|
45
|
-
input = "<input type=\"text\" class=\"form-control\" id=\"" +
|
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=\"✓\"><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\">" +
|
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 >
|
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 >
|
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
|
}
|
data/lib/abracadabra/version.rb
CHANGED
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
|
+
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-
|
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:
|
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:
|
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
|