turbolinks 2.2.2 → 2.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -2
- data/lib/assets/javascripts/turbolinks.js.coffee +24 -0
- data/lib/turbolinks.rb +1 -1
- data/lib/turbolinks/version.rb +1 -1
- data/lib/turbolinks/xhr_headers.rb +18 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da81704fe0957d34fec719c2fc56b4e455441f1b
|
4
|
+
data.tar.gz: 97475c1cc1e7f695aff45af973ec494f8eec515e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44e9dc7c75af51edef6c7549f46d8d3778c1a45a2d3944bfc7ead3a0242699eb606c9738d46e68de737c1ea72a02041c8e14532215aa8d3ab83fad4d4df8f306
|
7
|
+
data.tar.gz: f936d6871752ea5aafbf7c55f1e630c682361defb46c5dc5aa98b1f867ceb8bca539967b3669487537ecdf810e3c1bbd59aea6698c4d51df0ad8c6cb8f17c8be
|
data/README.md
CHANGED
@@ -59,8 +59,12 @@ When a page is removed from the cache due to the cache reaching its size limit,
|
|
59
59
|
|
60
60
|
To implement a client-side spinner, you could listen for `page:fetch` to start it and `page:receive` to stop it.
|
61
61
|
|
62
|
-
|
63
|
-
|
62
|
+
```javascript
|
63
|
+
// using jQuery for simplicity
|
64
|
+
|
65
|
+
$(document).on("page:fetch", startSpinner);
|
66
|
+
$(document).on("page:receive", stopSpinner);
|
67
|
+
```
|
64
68
|
|
65
69
|
DOM transformations that are idempotent are best. If you have transformations that are not, hook them to happen only on `page:load` instead of `page:change` (as that would run them again on the cached pages).
|
66
70
|
|
@@ -195,6 +199,7 @@ Language Ports
|
|
195
199
|
*These projects are not affiliated with or endorsed by the Rails Turbolinks team.*
|
196
200
|
|
197
201
|
* [Flask Turbolinks](https://github.com/lepture/flask-turbolinks) (Python Flask)
|
202
|
+
* [Django Turbolinks](https://github.com/dgladkov/django-turbolinks) (Python Django)
|
198
203
|
* [ASP.NET MVC Turbolinks](https://github.com/kazimanzurrashid/aspnetmvcturbolinks)
|
199
204
|
* [PHP Turbolinks Component](https://github.com/helthe/Turbolinks) (Symfony Component)
|
200
205
|
* [PHP Turbolinks Package](https://github.com/frenzyapp/turbolinks) (Laravel Package)
|
@@ -45,6 +45,7 @@ fetchReplacement = (url, onLoadFunction = =>) ->
|
|
45
45
|
|
46
46
|
if doc = processResponse()
|
47
47
|
changePage extractTitleAndBody(doc)...
|
48
|
+
manuallyTriggerHashChangeForFirefox()
|
48
49
|
reflectRedirectedUrl()
|
49
50
|
onLoadFunction()
|
50
51
|
triggerEvent 'page:load'
|
@@ -95,6 +96,7 @@ changePage = (title, body, csrfToken, runScripts) ->
|
|
95
96
|
document.title = title
|
96
97
|
document.documentElement.replaceChild body, document.body
|
97
98
|
CSRFToken.update csrfToken if csrfToken?
|
99
|
+
setAutofocusElement()
|
98
100
|
executeScriptTags() if runScripts
|
99
101
|
currentState = window.history.state
|
100
102
|
triggerEvent 'page:change'
|
@@ -115,6 +117,12 @@ removeNoscriptTags = (node) ->
|
|
115
117
|
node.innerHTML = node.innerHTML.replace /<noscript[\S\s]*?<\/noscript>/ig, ''
|
116
118
|
node
|
117
119
|
|
120
|
+
# Firefox bug: Doesn't autofocus fields that are inserted via JavaScript
|
121
|
+
setAutofocusElement = ->
|
122
|
+
autofocusElement = (list = document.querySelectorAll 'input[autofocus], textarea[autofocus]')[list.length - 1]
|
123
|
+
if autofocusElement and document.activeElement isnt autofocusElement
|
124
|
+
autofocusElement.focus()
|
125
|
+
|
118
126
|
reflectNewUrl = (url) ->
|
119
127
|
if (url = new ComponentUrl url).absolute isnt referer
|
120
128
|
window.history.pushState { turbolinks: true, url: url.absolute }, '', url.absolute
|
@@ -134,6 +142,18 @@ rememberCurrentUrl = ->
|
|
134
142
|
rememberCurrentState = ->
|
135
143
|
currentState = window.history.state
|
136
144
|
|
145
|
+
# Unlike other browsers, Firefox doesn't trigger hashchange after changing the
|
146
|
+
# location (via pushState) to an anchor on a different page. For example:
|
147
|
+
#
|
148
|
+
# /pages/one => /pages/two#with-hash
|
149
|
+
#
|
150
|
+
# By forcing Firefox to trigger hashchange, the rest of the code can rely on more
|
151
|
+
# consistent behavior across browsers.
|
152
|
+
manuallyTriggerHashChangeForFirefox = ->
|
153
|
+
if navigator.userAgent.match(/Firefox/) and !(url = (new ComponentUrl)).hasNoHash()
|
154
|
+
window.history.replaceState currentState, '', url.withoutHash()
|
155
|
+
document.location.hash = url.hash
|
156
|
+
|
137
157
|
recallScrollPosition = (page) ->
|
138
158
|
window.scrollTo page.positionX, page.positionY
|
139
159
|
|
@@ -371,6 +391,10 @@ initializeTurbolinks = ->
|
|
371
391
|
|
372
392
|
document.addEventListener 'click', Click.installHandlerLast, true
|
373
393
|
|
394
|
+
window.addEventListener 'hashchange', (event) ->
|
395
|
+
rememberCurrentUrl()
|
396
|
+
rememberCurrentState()
|
397
|
+
, false
|
374
398
|
bypassOnLoadPopstate ->
|
375
399
|
window.addEventListener 'popstate', installHistoryChangeHandler, false
|
376
400
|
|
data/lib/turbolinks.rb
CHANGED
data/lib/turbolinks/version.rb
CHANGED
@@ -11,21 +11,19 @@ module Turbolinks
|
|
11
11
|
module XHRHeaders
|
12
12
|
extend ActiveSupport::Concern
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
end
|
14
|
+
def _compute_redirect_to_location(*args)
|
15
|
+
options, request = _normalize_redirect_params(args)
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
else
|
24
|
-
_compute_redirect_to_location_without_xhr_referer(options)
|
25
|
-
end
|
17
|
+
store_for_turbolinks begin
|
18
|
+
if options == :back && request.headers["X-XHR-Referer"]
|
19
|
+
super(*[(request if args.length == 2), request.headers["X-XHR-Referer"]].compact)
|
20
|
+
else
|
21
|
+
super(*args)
|
26
22
|
end
|
27
23
|
end
|
24
|
+
end
|
28
25
|
|
26
|
+
private
|
29
27
|
def store_for_turbolinks(url)
|
30
28
|
session[:_turbolinks_redirect_to] = url if request.headers["X-XHR-Referer"]
|
31
29
|
url
|
@@ -36,5 +34,13 @@ module Turbolinks
|
|
36
34
|
response.headers['X-XHR-Redirected-To'] = session.delete :_turbolinks_redirect_to
|
37
35
|
end
|
38
36
|
end
|
37
|
+
|
38
|
+
# Ensure backwards compatibility
|
39
|
+
# Rails < 4.2: _compute_redirect_to_location(options)
|
40
|
+
# Rails >= 4.2: _compute_redirect_to_location(request, options)
|
41
|
+
def _normalize_redirect_params(args)
|
42
|
+
options, req = args.reverse
|
43
|
+
[options, req || request]
|
44
|
+
end
|
39
45
|
end
|
40
|
-
end
|
46
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: turbolinks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coffee-rails
|