turbolinks 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@ initialized = false
2
2
  currentState = null
3
3
  referer = document.location.href
4
4
  assets = []
5
- pageCache = []
5
+ pageCache = {}
6
6
  createDocument = null
7
7
 
8
8
  visit = (url) ->
@@ -26,7 +26,7 @@ fetchReplacement = (url) ->
26
26
  doc = createDocument xhr.responseText
27
27
 
28
28
  if assetsChanged doc
29
- document.location.href = url
29
+ document.location.reload()
30
30
  else
31
31
  changePage extractTitleAndBody(doc)...
32
32
  reflectRedirectedUrl xhr
@@ -61,12 +61,13 @@ cacheCurrentPage = ->
61
61
  constrainPageCacheTo(10)
62
62
 
63
63
  constrainPageCacheTo = (limit) ->
64
- delete pageCache[currentState.position - limit]
64
+ for own key, value of pageCache
65
+ pageCache[key] = null if key <= currentState.position - limit
65
66
 
66
- changePage = (title, body) ->
67
+ changePage = (title, body, runScripts) ->
67
68
  document.title = title
68
69
  document.documentElement.replaceChild body, document.body
69
- executeScriptTags()
70
+ executeScriptTags() if runScripts
70
71
  currentState = window.history.state
71
72
  triggerEvent 'page:change'
72
73
 
@@ -84,7 +85,7 @@ reflectRedirectedUrl = (xhr) ->
84
85
  window.history.replaceState currentState, '', location
85
86
 
86
87
  rememberCurrentUrl = ->
87
- window.history.replaceState { turbolinks: true, position: window.history.length - 1 }, '', document.location.href
88
+ window.history.replaceState { turbolinks: true, position: Date.now() }, '', document.location.href
88
89
 
89
90
  rememberCurrentState = ->
90
91
  currentState = window.history.state
@@ -116,7 +117,8 @@ extractAssets = (doc) ->
116
117
  (node.src || node.href) for node in doc.head.childNodes when node.src or node.href
117
118
 
118
119
  assetsChanged = (doc)->
119
- intersection(extractAssets(doc), assets).length != assets.length
120
+ extractedAssets = extractAssets doc
121
+ extractedAssets.length isnt assets.length or intersection(extractedAssets, assets).length != assets.length
120
122
 
121
123
  intersection = (a, b) ->
122
124
  [a, b] = [b, a] if a.length > b.length
@@ -124,7 +126,7 @@ intersection = (a, b) ->
124
126
 
125
127
  extractTitleAndBody = (doc) ->
126
128
  title = doc.querySelector 'title'
127
- [ title?.textContent, doc.body ]
129
+ [ title?.textContent, doc.body, 'runScripts' ]
128
130
 
129
131
  browserCompatibleDocumentParser = ->
130
132
  createDocumentUsingParser = (html) ->
@@ -134,7 +136,7 @@ browserCompatibleDocumentParser = ->
134
136
  doc = document.implementation.createHTMLDocument ''
135
137
  doc.open 'replace'
136
138
  doc.write html
137
- doc.close
139
+ doc.close()
138
140
  doc
139
141
 
140
142
  if window.DOMParser
@@ -154,19 +156,16 @@ installClickHandlerLast = (event) ->
154
156
  handleClick = (event) ->
155
157
  unless event.defaultPrevented
156
158
  link = extractLink event
157
- if link.nodeName is 'A' and !ignoreClick(event, link)
159
+ if link?.nodeName is 'A' and !ignoreClick(event, link)
158
160
  visit link.href
159
161
  event.preventDefault()
160
162
 
161
163
 
162
164
  extractLink = (event) ->
163
165
  link = event.target
164
- link = link.parentNode until link is document or link.nodeName is 'A'
166
+ link = link.parentNode until link is document or !link or link.nodeName is 'A'
165
167
  link
166
168
 
167
- samePageLink = (link) ->
168
- link.href is document.location.href
169
-
170
169
  crossOriginLink = (link) ->
171
170
  location.protocol isnt link.protocol or location.host isnt link.host
172
171
 
@@ -183,11 +182,14 @@ noTurbolink = (link) ->
183
182
  link = link.parentNode
184
183
  ignore
185
184
 
185
+ targetLink = (link) ->
186
+ link.target.length isnt 0
187
+
186
188
  nonStandardClick = (event) ->
187
189
  event.which > 1 or event.metaKey or event.ctrlKey or event.shiftKey or event.altKey
188
190
 
189
191
  ignoreClick = (event, link) ->
190
- crossOriginLink(link) or anchoredLink(link) or nonHtmlLink(link) or noTurbolink(link) or nonStandardClick(event)
192
+ crossOriginLink(link) or anchoredLink(link) or nonHtmlLink(link) or noTurbolink(link) or targetLink(link) or nonStandardClick(event)
191
193
 
192
194
 
193
195
  browserSupportsPushState =
data/lib/turbolinks.rb CHANGED
@@ -24,7 +24,7 @@ module Turbolinks
24
24
  initializer :turbolinks_xhr_headers do |config|
25
25
  ActionController::Base.class_eval do
26
26
  include XHRHeaders
27
- after_filter :set_xhr_current_location
27
+ before_filter :set_xhr_current_location
28
28
  end
29
29
  end
30
30
  end
data/test/index.html CHANGED
@@ -19,6 +19,7 @@
19
19
  <li><a href="/reload.html"><span>Asset Change</span></a></li>
20
20
  <li><a href="/dummy.gif?12345">Query Param Image Link</a></li>
21
21
  <li><a href="#">Hash link</a></li>
22
+ <li><a href="/reload.html#foo">Asset Change with hash link</a></li>
22
23
  </ul>
23
24
 
24
25
  <div style="background:#ccc;height:5000px;width:200px;">
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbolinks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-04 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-11-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: coffee-rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  description:
15
31
  email: david@loudthinking.com
16
32
  executables: []