turboboost 0.0.5.1 → 0.0.6
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 +8 -8
- data/README.md +1 -1
- data/app/assets/javascripts/turboboost.js.coffee +29 -25
- data/lib/turboboost.rb +12 -0
- data/lib/turboboost/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
N2VlY2M0OWI0ZjQ1MDJlYmUwYjViMDI0NmIwNTNjMzhlMGRiNjI3Nw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTRmNWNkOTJjN2EwYTFmZDI0ZWI1YWUyMTg0MWJiOGQ4N2E3NjhlMw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDkwMGU2YmNiMmY0MmI1ZTlhMzkxN2M0N2ExNzY5M2JjY2Y0ZDA0ZTY3ZTEx
|
10
|
+
MDY5YzQwNWJlZjM5YTE1MTdhOGJlNTljMGNlMTQ3ZjkyMDllZjE3YWQzNTgz
|
11
|
+
ZWRlZmQzMGFiOWNiYTVhMWZhYTg5YjVkM2Q4OGZiODNmYTVlZGQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
M2U1MWUzZDQ5NDRjMTI0YTRjMmRhYWEwM2RhM2UzMmY0MDE0MDhhMTNhNmJj
|
14
|
+
ODhkMzhlMGY3NTAyNGE0ZWU0YzE1ZTYwNmQzNGNkNTJhMTk2YTJjMDUwNzU4
|
15
|
+
NDNiNzViMzBiOWI3OGQ1ZDQ2ZDRiNGM2OGIxYTkwZTM5OWY0MjQ=
|
data/README.md
CHANGED
@@ -34,7 +34,7 @@ Turboboost extends the power of Turbolinks into the forms of your Rails app and
|
|
34
34
|
### Installation
|
35
35
|
|
36
36
|
``` ruby
|
37
|
-
gem "turboboost"
|
37
|
+
gem "turboboost"
|
38
38
|
```
|
39
39
|
|
40
40
|
Put that in your `Gemfile` and `bundle install`. In your `application.js` require it after `jquery_ujs` and `turbolinks`:
|
@@ -2,7 +2,7 @@
|
|
2
2
|
insertErrors: false
|
3
3
|
defaultError: "Sorry, there was an error."
|
4
4
|
|
5
|
-
|
5
|
+
turboboostable = "[data-turboboost]"
|
6
6
|
errID = "#error_explanation"
|
7
7
|
errTemplate = (errors) ->
|
8
8
|
"<ul><li>#{$.makeArray(errors).join('</li><li>')}</li></ul>"
|
@@ -13,7 +13,7 @@ enableForm = ($form) ->
|
|
13
13
|
disableForm = ($form) ->
|
14
14
|
$form.find("[type='submit']").attr('disabled', 'disabled')
|
15
15
|
|
16
|
-
|
16
|
+
turboboostFormError = (e, errors) ->
|
17
17
|
return if !Turboboost.insertErrors
|
18
18
|
errors = [Turboboost.defaultError] if !errors.length
|
19
19
|
$form = $(e.target)
|
@@ -22,6 +22,28 @@ insertErrors = (e, errors) ->
|
|
22
22
|
$form.prepend $el = $("<div id='#{errID.substr(1)}'></div>")
|
23
23
|
$el.html errTemplate(errors)
|
24
24
|
|
25
|
+
turboboostComplete = (e, resp) ->
|
26
|
+
$el = $(@)
|
27
|
+
isForm = @nodeName is "FORM"
|
28
|
+
|
29
|
+
if resp.status in [200..299]
|
30
|
+
$el.trigger "turboboost:success", tryJSONParse resp.getResponseHeader('X-Flash')
|
31
|
+
if (location = resp.getResponseHeader('Location')) and !$el.attr('data-no-turboboost-redirect')
|
32
|
+
Turbolinks.visit(location)
|
33
|
+
else
|
34
|
+
enableForm $el if isForm
|
35
|
+
maybeInsertSuccessResponseBody(resp)
|
36
|
+
|
37
|
+
if resp.status in [400..599]
|
38
|
+
enableForm $el if isForm
|
39
|
+
$el.trigger "turboboost:error", tryJSONParse resp.responseText
|
40
|
+
|
41
|
+
turboboostFormBeforeSend = (e, xhr, settings) ->
|
42
|
+
disableForm $(@)
|
43
|
+
if settings.type == "GET"
|
44
|
+
Turbolinks.visit [@action, $(@).serialize()].join("?")
|
45
|
+
return false
|
46
|
+
|
25
47
|
tryJSONParse = (str) ->
|
26
48
|
try
|
27
49
|
JSON.parse str
|
@@ -39,26 +61,8 @@ maybeInsertSuccessResponseBody = (resp) ->
|
|
39
61
|
$(scope).prepend(resp.responseText)
|
40
62
|
|
41
63
|
$(document)
|
42
|
-
.on
|
43
|
-
xhr.setRequestHeader('X-Turboboost', '1')
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
return false
|
48
|
-
|
49
|
-
.on "ajax:complete", turboboost, (e, resp) ->
|
50
|
-
$form = $(e.target)
|
51
|
-
|
52
|
-
if resp.status in [200..299]
|
53
|
-
$form.trigger "turboboost:success", tryJSONParse resp.getResponseHeader('X-Flash')
|
54
|
-
if (location = resp.getResponseHeader('Location')) and !$form.attr('data-no-turboboost-redirect')
|
55
|
-
Turbolinks.visit(location)
|
56
|
-
else
|
57
|
-
enableForm $form
|
58
|
-
maybeInsertSuccessResponseBody(resp)
|
59
|
-
|
60
|
-
if resp.status in [400..599]
|
61
|
-
enableForm $form
|
62
|
-
$form.trigger "turboboost:error", tryJSONParse resp.responseText
|
63
|
-
|
64
|
-
.on "turboboost:error", insertErrors
|
64
|
+
.on("ajax:beforeSend", turboboostable, (e, xhr, settings) ->
|
65
|
+
xhr.setRequestHeader('X-Turboboost', '1'))
|
66
|
+
.on("ajax:beforeSend", "form#{turboboostable}", turboboostFormBeforeSend)
|
67
|
+
.on("ajax:complete", turboboostable, turboboostComplete)
|
68
|
+
.on("turboboost:error", "form#{turboboostable}", turboboostFormError)
|
data/lib/turboboost.rb
CHANGED
@@ -132,6 +132,18 @@ module Turboboost
|
|
132
132
|
|
133
133
|
form_tag_without_data_turboboost(record_or_name_or_array, *(args << options), &proc)
|
134
134
|
end
|
135
|
+
|
136
|
+
def convert_options_to_data_attributes(options, html_options)
|
137
|
+
if html_options
|
138
|
+
html_options = html_options.stringify_keys
|
139
|
+
if turboboost = html_options.delete("turboboost")
|
140
|
+
html_options["data-remote"] = "true"
|
141
|
+
html_options["data-turboboost"] = "true"
|
142
|
+
end
|
143
|
+
end
|
144
|
+
super options, html_options
|
145
|
+
end
|
146
|
+
|
135
147
|
end
|
136
148
|
|
137
149
|
class Engine < Rails::Engine
|
data/lib/turboboost/version.rb
CHANGED