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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2bb9ae664cef07039bfb5326ff85ebcfbbca0e8
4
- data.tar.gz: 2b55c3358f99361d016329ccfa661872599069ba
3
+ metadata.gz: 7189329adf13178c8d0734735e1affc9f7cabbcd
4
+ data.tar.gz: ee154008520bd38704aa60fe9519fa71a74fb43b
5
5
  SHA512:
6
- metadata.gz: edd2489816d02cbfd4754b28f82a95d64c4b1290c41ee28984d3333c432c339c437d27c9d4cef1b526c0b9d076ea8d0c2f5fd50a0807cd5c98aed5cec8389af7
7
- data.tar.gz: 1fbb34bbd7831d6e72ebfc36a9aba4a019535118e0fc95db586d445f74700261a6f6bf9f26936019726f8dad510aede638671245369e43c406cb3f6744033a07
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 gives you a range of events to deal with the lifecycle of the page:
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:change` to stop it. 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).
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.0
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-24 00:00:00.000000000 Z
11
+ date: 2013-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coffee-rails