render_async 2.1.5 → 2.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -1
- data/README.md +4 -4
- data/app/views/render_async/_request_jquery.js.erb +23 -9
- data/app/views/render_async/_request_vanilla.js.erb +15 -5
- data/lib/render_async/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4395fdb879d841524916faed69721328699ce7e0a306eb90e1fc8884481b456
|
4
|
+
data.tar.gz: f46076b2751679131e34cfa171f57f669eeea03ff7a54dfa0f72ef7e62a5ae30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a489a71c7f80f9de03cb1d5c907b0e254e1dd40417432ff58c8a165f49b4e75a74d4338f20969be147bc5f1919d55f94f29189531f7822cb1803a6fc12ba0300
|
7
|
+
data.tar.gz: c045fe610ddbddde1083c1455c106e6024cb743a32d69f1c9e2720c5cba6bad1b9941af955383ee9c340d7f9d7538f7abbfd9eea58491f84428ee030b62f8ba9
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,33 @@
|
|
1
|
-
### 2.1.
|
1
|
+
### 2.1.6 (2020/5/9)
|
2
|
+
|
3
|
+
* [#114](https://github.com/renderedtext/render_async/pull/114): Call render_async logic if document state is ready or interactive - [@nikolalsvk](https://github.com/nikolalsvk).
|
4
|
+
* [#113](https://github.com/renderedtext/render_async/pull/113): Remove interval after Turbolinks visit event - [@nikolalsvk](https://github.com/nikolalsvk).
|
5
|
+
* [#112](https://github.com/renderedtext/render_async/pull/112): Add X-Requested-With header in Vanilla JS - [@nikolalsvk](https://github.com/nikolalsvk).
|
6
|
+
* [#110](https://github.com/renderedtext/render_async/pull/110): Remove preventDefault, and load toggle in stream - [@vanboom](https://github.com/vanboom).
|
7
|
+
|
8
|
+
### 2.1.5 (2020/3/22)
|
9
|
+
|
10
|
+
* [#105](https://github.com/renderedtext/render_async/pull/105): Load toggle listeners after page loads - [@nikolalsvk](https://github.com/nikolalsvk).
|
11
|
+
* [#104](https://github.com/renderedtext/render_async/pull/104): Attach container to dispatched events - [@nikolalsvk](https://github.com/nikolalsvk).
|
12
|
+
* [#103](https://github.com/renderedtext/render_async/pull/103): Add generic "load" and "error" events - [@lipsumar](https://github.com/lipsumar).
|
13
|
+
* [#98](https://github.com/renderedtext/render_async/pull/98): Bump nonce pattern in the README to follow Rails CSP standard - [@colinxfleming](https://github.com/colinxfleming).
|
14
|
+
|
15
|
+
### 2.1.4 (2019/11/11)
|
16
|
+
|
17
|
+
* [#96](https://github.com/renderedtext/render_async/pull/96): Add once option to remove event once it's triggered #94 - [@fffx](https://github.com/fffx).
|
18
|
+
|
19
|
+
### 2.1.3 (2019/9/24)
|
20
|
+
|
21
|
+
* [#95](https://github.com/renderedtext/render_async/pull/95): Use double quotes for displaying error message - [@nikolalsvk](https://github.com/nikolalsvk).
|
22
|
+
* [#93](https://github.com/renderedtext/render_async/pull/93): Fix: "Uncaught ReferenceError: \_interval" #92 - [@fffx](https://github.com/fffx).
|
23
|
+
|
24
|
+
### 2.1.2 (2019/8/17)
|
25
|
+
|
2
26
|
* [#89](https://github.com/renderedtext/render_async/pull/89): Bump version to 2.1.2 - [@nikolalsvk](https://github.com/nikolalsvk).
|
3
27
|
* [#82](https://github.com/renderedtext/render_async/pull/88): When toggle true, do not fire `_renderAsyncFunc` on `turbolinks:load` - [@ThanhKhoaIT](https://github.com/ThanhKhoaIT).
|
4
28
|
|
5
29
|
### 2.1.1 (2019/8/17)
|
30
|
+
|
6
31
|
* [#85](https://github.com/renderedtext/render_async/pull/85): Rename main JS function and support toggle feature with other features - [@nikolalsvk](https://github.com/nikolalsvk).
|
7
32
|
* [#82](https://github.com/renderedtext/render_async/pull/82): Add toggle selector and event to render - [@ThanhKhoaIT](https://github.com/ThanhKhoaIT).
|
8
33
|
* DEPRECATION WARNING - html_options is now a hash that you pass to render_async instead of an argument. If you passed for example a nonce: '21312aas...', you will need to pass
|
data/README.md
CHANGED
@@ -268,11 +268,11 @@ document.addEventListener('render_async_error', function(event) {
|
|
268
268
|
});
|
269
269
|
|
270
270
|
// with jQuery
|
271
|
-
$(document).on('render_async_load', function(event
|
272
|
-
console.log('Async partial loaded in this container:', container);
|
271
|
+
$(document).on('render_async_load', function(event) {
|
272
|
+
console.log('Async partial loaded in this container:', event.container);
|
273
273
|
});
|
274
|
-
$(document).on('render_async_error', function(event
|
275
|
-
console.log('Async partial could not load in this container:', container);
|
274
|
+
$(document).on('render_async_error', function(event) {
|
275
|
+
console.log('Async partial could not load in this container:', event.container);
|
276
276
|
});
|
277
277
|
```
|
278
278
|
|
@@ -18,11 +18,16 @@ if (window.jQuery) {
|
|
18
18
|
}
|
19
19
|
|
20
20
|
function _runAfterDocumentLoaded(callback) {
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
if (document.readyState === 'complete' || document.readyState === 'interactive') {
|
22
|
+
// Handle a case where nested partials get loaded after the document loads
|
23
|
+
callback();
|
24
|
+
} else {
|
25
|
+
<% if turbolinks %>
|
26
|
+
$(document).one('turbolinks:load', callback);
|
27
|
+
<% else %>
|
28
|
+
$(document).ready(callback);
|
29
|
+
<% end %>
|
30
|
+
}
|
26
31
|
}
|
27
32
|
|
28
33
|
function _makeRequest(currentRetryCount) {
|
@@ -91,18 +96,27 @@ if (window.jQuery) {
|
|
91
96
|
|
92
97
|
var _renderAsyncFunction = _makeRequest;
|
93
98
|
|
94
|
-
<% if interval %>
|
95
99
|
var _interval;
|
100
|
+
<% if interval %>
|
96
101
|
var _renderAsyncFunction = function() {
|
97
102
|
_makeRequest();
|
98
103
|
_interval = setInterval(_makeRequest, <%= interval %>);
|
99
104
|
}
|
105
|
+
|
106
|
+
<% if turbolinks %>
|
107
|
+
$(document).one('turbolinks:visit', function() {
|
108
|
+
if (typeof(_interval) === 'number') {
|
109
|
+
console.log('clearing the interval in jQuery part')
|
110
|
+
clearInterval(_interval)
|
111
|
+
_interval = undefined;
|
112
|
+
}
|
113
|
+
});
|
114
|
+
<% end %>
|
100
115
|
<% end %>
|
101
116
|
|
102
117
|
<% if toggle %>
|
103
118
|
function _setUpToggle() {
|
104
119
|
$(document).<%= toggle[:once] ? 'one' : 'on' %>('<%= toggle[:event] || 'click' %>', '<%= toggle[:selector] %>', function(event) {
|
105
|
-
event.preventDefault();
|
106
120
|
if (typeof(_interval) === 'number') {
|
107
121
|
clearInterval(_interval);
|
108
122
|
_interval = undefined;
|
@@ -112,11 +126,11 @@ if (window.jQuery) {
|
|
112
126
|
});
|
113
127
|
}
|
114
128
|
|
115
|
-
_runAfterDocumentLoaded(_setUpToggle)
|
129
|
+
_runAfterDocumentLoaded(_setUpToggle);
|
116
130
|
<% elsif !toggle %>
|
117
131
|
_runAfterDocumentLoaded(_renderAsyncFunction)
|
118
132
|
<% end %>
|
119
133
|
}(jQuery));
|
120
134
|
} else {
|
121
|
-
console.warn("Looks like you've enabled jQuery for render_async, but jQuery is not defined");
|
135
|
+
console.warn("Looks like you've enabled jQuery for render_async, but jQuery is not defined on the window object");
|
122
136
|
};
|
@@ -44,6 +44,8 @@
|
|
44
44
|
request.setRequestHeader(key, headers[key]);
|
45
45
|
});
|
46
46
|
|
47
|
+
request.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
48
|
+
|
47
49
|
request.onreadystatechange = function() {
|
48
50
|
if (request.readyState === 4) {
|
49
51
|
if (request.status >= SUCCESS && request.status < ERROR) {
|
@@ -72,7 +74,6 @@
|
|
72
74
|
var container = document.getElementById('<%= container_id %>');
|
73
75
|
container.outerHTML = '<%= error_message.try(:html_safe) %>';
|
74
76
|
|
75
|
-
console.log(container)
|
76
77
|
var errorEvent = createEvent('render_async_error', container);
|
77
78
|
document.dispatchEvent(errorEvent);
|
78
79
|
|
@@ -105,19 +106,28 @@
|
|
105
106
|
|
106
107
|
var _renderAsyncFunction = _makeRequest;
|
107
108
|
|
108
|
-
<% if interval %>
|
109
109
|
var _interval;
|
110
|
+
<% if interval %>
|
110
111
|
var _renderAsyncFunction = function() {
|
111
112
|
_makeRequest();
|
112
113
|
_interval = setInterval(_makeRequest, <%= interval %>);
|
113
114
|
}
|
115
|
+
|
116
|
+
<% if turbolinks %>
|
117
|
+
document.addEventListener("turbolinks:visit", function(e) {
|
118
|
+
if (typeof(_interval) === 'number') {
|
119
|
+
console.log('clearing the interval')
|
120
|
+
clearInterval(_interval);
|
121
|
+
_interval = undefined;
|
122
|
+
}
|
123
|
+
});
|
124
|
+
<% end %>
|
114
125
|
<% end %>
|
115
126
|
|
116
127
|
<% if toggle %>
|
117
128
|
function _setUpToggle() {
|
118
|
-
var selectors = document.querySelectorAll('<%= toggle[:selector] %>')
|
129
|
+
var selectors = document.querySelectorAll('<%= toggle[:selector] %>');
|
119
130
|
var handler = function(event) {
|
120
|
-
event.preventDefault();
|
121
131
|
if (typeof(_interval) === 'number') {
|
122
132
|
clearInterval(_interval);
|
123
133
|
_interval = undefined;
|
@@ -129,7 +139,7 @@
|
|
129
139
|
<% end %>
|
130
140
|
};
|
131
141
|
|
132
|
-
for (i = 0; i < selectors.length; ++i) {
|
142
|
+
for (var i = 0; i < selectors.length; ++i) {
|
133
143
|
selectors[i].addEventListener('<%= toggle[:event] || 'click' %>', handler)
|
134
144
|
}
|
135
145
|
}
|
data/lib/render_async/version.rb
CHANGED
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: 2.1.
|
4
|
+
version: 2.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kasper Grubbe
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-05-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -101,8 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
103
|
requirements: []
|
104
|
-
|
105
|
-
rubygems_version: 2.7.6
|
104
|
+
rubygems_version: 3.1.2
|
106
105
|
signing_key:
|
107
106
|
specification_version: 4
|
108
107
|
summary: Render parts of the page asynchronously with AJAX
|