render_async 1.1.0 → 1.1.1

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: 34364781d19ea77161a9be8861be690efc034fd1
4
- data.tar.gz: 2cc3906d7c0c680f663694dc9d9224daf0091fc4
3
+ metadata.gz: 0e8f5232e6ce897923d42d8d7e13e12f2106596a
4
+ data.tar.gz: ffddc0b5d3b6844d443b2b38b3314ad42fbf2b21
5
5
  SHA512:
6
- metadata.gz: 663f85b5338e9348745f4b515aa630b0e035fa7e598a6adfa7b7d8848e8fa25f20eec8eb1d65120f5885b3bc09314fa074cd617b4f002f028178b059757a1720
7
- data.tar.gz: e5e3b70a41ae41946651c20204b7414bde2073cc70803fd8b1a1e46ab3a3766d0148d4267bc64f8d9d289bb289a69be4448b72b34abbb24a865efaad7be54ab1
6
+ metadata.gz: 7a3b034960837da35ba4afd002c2f7c9ea05d55cbc33a20f9b6644e965c17295a48d47156eb418d7346f0204b50e298cd60525d258c174001a382884c05b4dfe
7
+ data.tar.gz: 6a74359e25c505cdb82135fa671b966a54d41fc543e989f23e5086242de52bc6dc6ade032c647ea5abae6f1713bddbb25fae583b83241e4e7f1bd36ac826b60b
data/README.md CHANGED
@@ -102,21 +102,7 @@ Rendered code in the view:
102
102
 
103
103
  <script nonce="lWaaV6eYicpt+oyOfcShYINsz0b70iR+Q1mohZqNaag=">
104
104
  //<![CDATA[
105
- (function() {
106
- var request = new XMLHttpRequest();
107
- var asyncRequest = true;
108
- var SUCCESS = 200;
109
- var ERROR = 400;
110
- request.open("GET", "/users", asyncRequest);
111
-
112
- request.onload = function() {
113
- if (request.status >= SUCCESS && request.status < ERROR) {
114
- document.getElementById("render_async_18b41794481507226109").outerHTML = request.responseText;
115
- }
116
- };
117
-
118
- request.send();
119
- })();
105
+ ...
120
106
  //]]>
121
107
  </script>
122
108
  ```
@@ -142,21 +128,7 @@ Rendered code in the view:
142
128
 
143
129
  <script>
144
130
  //<![CDATA[
145
- (function() {
146
- var request = new XMLHttpRequest();
147
- var asyncRequest = true;
148
- var SUCCESS = 200;
149
- var ERROR = 400;
150
- request.open("GET", "/users", asyncRequest);
151
-
152
- request.onload = function() {
153
- if (request.status >= SUCCESS && request.status < ERROR) {
154
- document.getElementById("render_async_14d7ac165d1505993721").outerHTML = request.responseText;
155
- }
156
- };
157
-
158
- request.send();
159
- })();
131
+ ...
160
132
  //]]>
161
133
  </script>
162
134
  ```
@@ -184,23 +156,9 @@ Rendered code in view:
184
156
 
185
157
  <script>
186
158
  //<![CDATA[
187
- (function() {
188
- var request = new XMLHttpRequest();
189
- var asyncRequest = true;
190
- var SUCCESS = 200;
191
- var ERROR = 400;
192
- request.open("GET", "/users", asyncRequest);
193
-
194
- request.onload = function() {
195
- if (request.status >= SUCCESS && request.status < ERROR) {
196
- document.getElementById("render_async_04229e7abe1507987376").outerHTML = request.responseText;
197
-
198
- document.dispatchEvent(new Event("users-loaded"));
199
- }
200
- };
201
-
202
- request.send();
203
- })();
159
+ ...
160
+ document.dispatchEvent(new Event("users-loaded"));
161
+ ...
204
162
  //]]>
205
163
  </script>
206
164
  ```
@@ -4,25 +4,37 @@
4
4
 
5
5
  <% content_for :render_async do %>
6
6
  <%= javascript_tag html_options do %>
7
- (function() {
8
- var request = new XMLHttpRequest();
9
- var asyncRequest = true;
10
- var SUCCESS = 200;
11
- var ERROR = 400;
12
-
13
- request.open("GET", "<%= path %>", asyncRequest);
14
-
15
- request.onload = function() {
16
- if (request.status >= SUCCESS && request.status < ERROR) {
17
- document.getElementById("<%= container_id %>").outerHTML = request.responseText;
7
+ if (jQuery) {
8
+ (function($){
9
+ $.ajax({ url: "<%= path %>" }).always(function(response) {
10
+ $("#<%= container_id %>").replaceWith(response);
18
11
 
19
12
  <% if event_name.present? %>
20
13
  document.dispatchEvent(new Event("<%= event_name %>"));
21
14
  <% end %>
22
- }
23
- };
15
+ });
16
+ }(jQuery));
17
+ } else {
18
+ (function() {
19
+ var request = new XMLHttpRequest();
20
+ var asyncRequest = true;
21
+ var SUCCESS = 200;
22
+ var ERROR = 400;
23
+
24
+ request.open("GET", "<%= path %>", asyncRequest);
25
+
26
+ request.onload = function() {
27
+ if (request.status >= SUCCESS && request.status < ERROR) {
28
+ var container = document.getElementById("<%= container_id %>");
29
+
30
+ <% if event_name.present? %>
31
+ document.dispatchEvent(new Event("<%= event_name %>"));
32
+ <% end %>
33
+ }
34
+ };
24
35
 
25
- request.send();
26
- })();
36
+ request.send();
37
+ })();
38
+ }
27
39
  <% end %>
28
40
  <% end %>
@@ -1,3 +1,3 @@
1
1
  module RenderAsync
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: render_async
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Grubbe