turbolinks 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -1
- data/lib/assets/javascripts/turbolinks.js.coffee +26 -14
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44d63b0594e6fb0a716f3e4bf5b20fc846d6fcfa
|
4
|
+
data.tar.gz: ef06a46f52118a4f02ff22d5b021c836ad8383e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7590f57d144d29dc0ded39043a95d11d01d32de69172bb82d0899558e587820d1d3ec5571ea17f7ad2bd913ad9f4fc4d348ee74c0fe0e1e3bf22d2933d4fdaf9
|
7
|
+
data.tar.gz: 8a583b3da14790bafbdd16e86bc59dc8c150c5609f280ba2e14c971f60bce9102d5fc8332b0bc98f9595a95d9fe6e3314de3ee3ea8f3890ad9afb8f5cb948a29
|
data/README.md
CHANGED
@@ -55,6 +55,8 @@ Turbolinks.pagesCached();
|
|
55
55
|
Turbolinks.pagesCached(20);
|
56
56
|
```
|
57
57
|
|
58
|
+
When a page is removed from the cache due to the cache reaching its size limit, the `page:expire` event is triggered. Listeners bound to this event can access the cached page object using `event.originalEvent.data`. Keys of note for this page cache object include `url`, `body`, and `title`.
|
59
|
+
|
58
60
|
To implement a client-side spinner, you could listen for `page:fetch` to start it and `page:receive` to stop it.
|
59
61
|
|
60
62
|
document.addEventListener("page:fetch", startSpinner);
|
@@ -89,7 +91,13 @@ By default, all internal HTML links will be funneled through Turbolinks, but you
|
|
89
91
|
</div>
|
90
92
|
```
|
91
93
|
|
92
|
-
Note that internal links to files containing a file extension other than **.html** will automatically be opted out of Turbolinks. So links to /images/panda.gif will just work as expected.
|
94
|
+
Note that internal links to files containing a file extension other than **.html** will automatically be opted out of Turbolinks. So links to /images/panda.gif will just work as expected. To whitelist additional file extensions to be processed by Turbolinks, use `Turbolinks.allowLinkExtensions()`.
|
95
|
+
|
96
|
+
```javascript
|
97
|
+
Turbolinks.allowLinkExtensions(); // => ['html']
|
98
|
+
Turbolinks.allowLinkExtensions('md'); // => ['html', 'md']
|
99
|
+
Turbolinks.allowLinkExtensions('coffee', 'scss'); // => ['html', 'md', 'coffee', 'scss']
|
100
|
+
```
|
93
101
|
|
94
102
|
Also, Turbolinks is installed as the last click handler for links. So if you install another handler that calls event.preventDefault(), Turbolinks will not run. This ensures that you can safely use Turbolinks with stuff like `data-method`, `data-remote`, or `data-confirm` from Rails.
|
95
103
|
|
@@ -2,6 +2,7 @@ pageCache = {}
|
|
2
2
|
cacheSize = 10
|
3
3
|
currentState = null
|
4
4
|
loadedAssets = null
|
5
|
+
htmlExtensions = ['html']
|
5
6
|
|
6
7
|
referer = null
|
7
8
|
|
@@ -9,7 +10,7 @@ createDocument = null
|
|
9
10
|
xhr = null
|
10
11
|
|
11
12
|
|
12
|
-
fetchReplacement = (url) ->
|
13
|
+
fetchReplacement = (url) ->
|
13
14
|
rememberReferer()
|
14
15
|
cacheCurrentPage()
|
15
16
|
triggerEvent 'page:fetch', url: url
|
@@ -60,15 +61,15 @@ pagesCached = (size = cacheSize) ->
|
|
60
61
|
cacheSize = parseInt(size) if /^[\d]+$/.test size
|
61
62
|
|
62
63
|
constrainPageCacheTo = (limit) ->
|
63
|
-
for own key, value of pageCache
|
64
|
-
pageCache[key]
|
64
|
+
for own key, value of pageCache when key <= currentState.position - limit
|
65
|
+
triggerEvent 'page:expire', pageCache[key]
|
66
|
+
pageCache[key] = null
|
65
67
|
return
|
66
68
|
|
67
69
|
changePage = (title, body, csrfToken, runScripts) ->
|
68
70
|
document.title = title
|
69
71
|
document.documentElement.replaceChild body, document.body
|
70
72
|
CSRFToken.update csrfToken if csrfToken?
|
71
|
-
removeNoscriptTags()
|
72
73
|
executeScriptTags() if runScripts
|
73
74
|
currentState = window.history.state
|
74
75
|
triggerEvent 'page:change'
|
@@ -85,10 +86,9 @@ executeScriptTags = ->
|
|
85
86
|
parentNode.insertBefore copy, nextSibling
|
86
87
|
return
|
87
88
|
|
88
|
-
removeNoscriptTags = ->
|
89
|
-
|
90
|
-
|
91
|
-
return
|
89
|
+
removeNoscriptTags = (node) ->
|
90
|
+
node.innerHTML = node.innerHTML.replace /<noscript[\S\s]*?<\/noscript>/ig, ''
|
91
|
+
node
|
92
92
|
|
93
93
|
reflectNewUrl = (url) ->
|
94
94
|
if url isnt referer
|
@@ -170,7 +170,7 @@ processResponse = ->
|
|
170
170
|
|
171
171
|
extractTitleAndBody = (doc) ->
|
172
172
|
title = doc.querySelector 'title'
|
173
|
-
[ title?.textContent, doc.body, CSRFToken.get(doc).token, 'runScripts' ]
|
173
|
+
[ title?.textContent, removeNoscriptTags(doc.body), CSRFToken.get(doc).token, 'runScripts' ]
|
174
174
|
|
175
175
|
CSRFToken =
|
176
176
|
get: (doc = document) ->
|
@@ -247,7 +247,7 @@ anchoredLink = (link) ->
|
|
247
247
|
|
248
248
|
nonHtmlLink = (link) ->
|
249
249
|
url = removeHash link
|
250
|
-
url.match(/\.[a-z]+(\?.*)?$/g) and not url.match(
|
250
|
+
url.match(/\.[a-z]+(\?.*)?$/g) and not url.match(new RegExp("\\.(?:#{htmlExtensions.join('|')})?(\\?.*)?$", 'g'))
|
251
251
|
|
252
252
|
noTurbolink = (link) ->
|
253
253
|
until ignore or link is document
|
@@ -264,6 +264,9 @@ nonStandardClick = (event) ->
|
|
264
264
|
ignoreClick = (event, link) ->
|
265
265
|
crossOriginLink(link) or anchoredLink(link) or nonHtmlLink(link) or noTurbolink(link) or targetLink(link) or nonStandardClick(event)
|
266
266
|
|
267
|
+
allowLinkExtensions = (extensions...) ->
|
268
|
+
htmlExtensions.push extension for extension in extensions
|
269
|
+
htmlExtensions
|
267
270
|
|
268
271
|
installDocumentReadyPageEventTriggers = ->
|
269
272
|
document.addEventListener 'DOMContentLoaded', ( ->
|
@@ -292,8 +295,12 @@ initializeTurbolinks = ->
|
|
292
295
|
document.addEventListener 'click', installClickHandlerLast, true
|
293
296
|
window.addEventListener 'popstate', installHistoryChangeHandler, false
|
294
297
|
|
298
|
+
# Handle bug in Firefox 26 where history.state is initially undefined
|
299
|
+
historyStateIsDefined =
|
300
|
+
window.history.state != undefined or navigator.userAgent.match /Firefox\/26/
|
301
|
+
|
295
302
|
browserSupportsPushState =
|
296
|
-
window.history and window.history.pushState and window.history.replaceState and
|
303
|
+
window.history and window.history.pushState and window.history.replaceState and historyStateIsDefined
|
297
304
|
|
298
305
|
browserIsntBuggy =
|
299
306
|
!navigator.userAgent.match /CriOS\//
|
@@ -303,8 +310,12 @@ requestMethodIsSafe =
|
|
303
310
|
|
304
311
|
browserSupportsTurbolinks = browserSupportsPushState and browserIsntBuggy and requestMethodIsSafe
|
305
312
|
|
306
|
-
|
307
|
-
|
313
|
+
browserSupportsCustomEvents =
|
314
|
+
document.addEventListener and document.createEvent
|
315
|
+
|
316
|
+
if browserSupportsCustomEvents
|
317
|
+
installDocumentReadyPageEventTriggers()
|
318
|
+
installJqueryAjaxSuccessPageUpdateTrigger()
|
308
319
|
|
309
320
|
if browserSupportsTurbolinks
|
310
321
|
visit = fetchReplacement
|
@@ -316,5 +327,6 @@ else
|
|
316
327
|
# Turbolinks.visit(url)
|
317
328
|
# Turbolinks.pagesCached()
|
318
329
|
# Turbolinks.pagesCached(20)
|
330
|
+
# Turbolinks.allowLinkExtensions('md')
|
319
331
|
# Turbolinks.supported
|
320
|
-
@Turbolinks = { visit, pagesCached, supported: browserSupportsTurbolinks }
|
332
|
+
@Turbolinks = { visit, pagesCached, allowLinkExtensions, supported: browserSupportsTurbolinks }
|
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.
|
4
|
+
version: 2.1.0
|
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-12-
|
11
|
+
date: 2013-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coffee-rails
|
@@ -41,7 +41,7 @@ files:
|
|
41
41
|
- test/offline.html
|
42
42
|
- test/other.html
|
43
43
|
- test/reload.html
|
44
|
-
homepage:
|
44
|
+
homepage: https://github.com/rails/turbolinks/
|
45
45
|
licenses:
|
46
46
|
- MIT
|
47
47
|
metadata: {}
|
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
61
|
version: '0'
|
62
62
|
requirements: []
|
63
63
|
rubyforge_project:
|
64
|
-
rubygems_version: 2.0.
|
64
|
+
rubygems_version: 2.0.5
|
65
65
|
signing_key:
|
66
66
|
specification_version: 4
|
67
67
|
summary: Turbolinks makes following links in your web application faster (use with
|