turbolinks 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 +4 -4
- data/README.md +6 -2
- data/lib/assets/javascripts/turbolinks.js.coffee +17 -3
- 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: 7189329adf13178c8d0734735e1affc9f7cabbcd
|
4
|
+
data.tar.gz: ee154008520bd38704aa60fe9519fa71a74fb43b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be97d3f28a06864e225e9d384d0aa714c175163410fd9079a4d3770e0d17d581b35bfa043b674480d4cf0ec17e76614615032d1fed2c4a652ce04e8ffdbe0248
|
7
|
+
data.tar.gz: 6553c4009a6b45a5163456f31c6bab1dd33a3f49e7fa0513f346f4c781f8bee57660e5b4a8d7fbae7202a4b284b2e0a211a330bed69c73008d479aab7a66d5fb
|
data/README.md
CHANGED
@@ -27,7 +27,7 @@ Turbolinks is designed to be as light-weight as possible (so you won't think twi
|
|
27
27
|
Events
|
28
28
|
------
|
29
29
|
|
30
|
-
Since pages will change without a full reload with Turbolinks, you can't by default rely on `DOMContentLoaded` to trigger your JavaScript code or jQuery.ready(). Instead, Turbolinks
|
30
|
+
Since pages will change without a full reload with Turbolinks, you can't by default rely on `DOMContentLoaded` to trigger your JavaScript code or jQuery.ready(). Instead, Turbolinks fires events on `document` to provide hooks into the lifecycle of the page:
|
31
31
|
|
32
32
|
* `page:fetch` starting to fetch the target page (only called if loading fresh, not from cache).
|
33
33
|
* `page:load` fetched page is being retrieved fresh from the server.
|
@@ -35,8 +35,12 @@ Since pages will change without a full reload with Turbolinks, you can't by defa
|
|
35
35
|
* `page:change` page has changed to the newly fetched version.
|
36
36
|
* `page:receive` page has been fetched from the server, but not yet parsed.
|
37
37
|
|
38
|
-
So if you wanted to have a client-side spinner, you could listen for `page:fetch` to start it and `page:
|
38
|
+
So if you wanted to have a client-side spinner, you could listen for `page:fetch` to start it and `page:receive` to stop it.
|
39
39
|
|
40
|
+
document.addEventListener("page:fetch", startSpinner);
|
41
|
+
document.addEventListener("page:receive", stopSpinner);
|
42
|
+
|
43
|
+
If you have DOM transformation that are not idempotent (the best way), you can hook them to happen only on `page:load` instead of `page:change` (as that would run them again on the cached pages).
|
40
44
|
|
41
45
|
Initialization
|
42
46
|
--------------
|
@@ -8,7 +8,7 @@ requestMethod = document.cookie.match(/request_method=(\w+)/)?[1].toUpperCase()
|
|
8
8
|
xhr = null
|
9
9
|
|
10
10
|
visit = (url) ->
|
11
|
-
if browserSupportsPushState
|
11
|
+
if browserSupportsPushState && browserIsntBuggy
|
12
12
|
cacheCurrentPage()
|
13
13
|
reflectNewUrl url
|
14
14
|
fetchReplacement url
|
@@ -75,10 +75,12 @@ cacheCurrentPage = ->
|
|
75
75
|
constrainPageCacheTo = (limit) ->
|
76
76
|
for own key, value of pageCache
|
77
77
|
pageCache[key] = null if key <= currentState.position - limit
|
78
|
+
return
|
78
79
|
|
79
|
-
changePage = (title, body, runScripts) ->
|
80
|
+
changePage = (title, body, csrfToken, runScripts) ->
|
80
81
|
document.title = title
|
81
82
|
document.documentElement.replaceChild body, document.body
|
83
|
+
CSRFToken.update csrfToken if csrfToken?
|
82
84
|
removeNoscriptTags()
|
83
85
|
executeScriptTags() if runScripts
|
84
86
|
currentState = window.history.state
|
@@ -93,10 +95,12 @@ executeScriptTags = ->
|
|
93
95
|
{ parentNode, nextSibling } = script
|
94
96
|
parentNode.removeChild script
|
95
97
|
parentNode.insertBefore copy, nextSibling
|
98
|
+
return
|
96
99
|
|
97
100
|
removeNoscriptTags = ->
|
98
101
|
noscriptTags = Array::slice.call document.body.getElementsByTagName 'noscript'
|
99
102
|
noscript.parentNode.removeChild noscript for noscript in noscriptTags
|
103
|
+
return
|
100
104
|
|
101
105
|
reflectNewUrl = (url) ->
|
102
106
|
if url isnt document.location.href
|
@@ -157,8 +161,18 @@ intersection = (a, b) ->
|
|
157
161
|
|
158
162
|
extractTitleAndBody = (doc) ->
|
159
163
|
title = doc.querySelector 'title'
|
160
|
-
[ title?.textContent, doc.body, 'runScripts' ]
|
164
|
+
[ title?.textContent, doc.body, CSRFToken.get(doc).token, 'runScripts' ]
|
161
165
|
|
166
|
+
CSRFToken =
|
167
|
+
get: (doc = document) ->
|
168
|
+
node: tag = doc.querySelector 'meta[name="csrf-token"]'
|
169
|
+
token: tag?.getAttribute? 'content'
|
170
|
+
|
171
|
+
update: (latest) ->
|
172
|
+
current = @get()
|
173
|
+
if current.token? and latest? and current.token isnt latest
|
174
|
+
current.node.setAttribute 'content', latest
|
175
|
+
|
162
176
|
browserCompatibleDocumentParser = ->
|
163
177
|
createDocumentUsingParser = (html) ->
|
164
178
|
(new DOMParser).parseFromString html, 'text/html'
|
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: 1.1.
|
4
|
+
version: 1.1.1
|
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: 2013-03
|
11
|
+
date: 2013-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coffee-rails
|