turbograft 0.1.10 → 0.1.11

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: 4d6ed5cfa12fb229dbe15a95c663d588fb286968
4
- data.tar.gz: eb7db0db4ab8e83d2b99c84a734afd249abf976e
3
+ metadata.gz: f51cd95b7cebb4dc5951437b2a1026f6c3b810c8
4
+ data.tar.gz: 27867ee91c017ea05233ada000f44b15fdbd1cba
5
5
  SHA512:
6
- metadata.gz: 139ff3da9750ac52978ab7de428a2da45ff9b506c0a5c42d29a33dfdbd9aafa07535cbf88870ebea0df5309c3d56493f34b45f6bf016cd19f139caa017ea00aa
7
- data.tar.gz: 63a0480ab0ab39cb02133ab41692745f0ae15a30b742e0869543b28c9094e54bb393a16dd1b7986f92abf45746f7f3950c3e16a8dffe6d52c0115d7f31f3ee08
6
+ metadata.gz: ebad3b4003a5d3a2c34597c382f84b0b66e4966d24e827ef098ad5beb769d8a17dcf1913711627f8999ed3ba389d089aead2cc299a66541074551e60aac83d34
7
+ data.tar.gz: 1b6c92c9f37b6ccaa8519267276de41b8144faeb9250a7d690d84dccd82b084761d1f4cd51e10b0ba0bc6197b321380bb42e6e3ce136fc548066609645cb391a
@@ -104,7 +104,6 @@ class window.Turbolinks
104
104
  @loadPage: (url, xhr, partialReplace = false, onLoadFunction = (->), replaceContents = [], replaceAllExcept = []) ->
105
105
  triggerEvent 'page:receive'
106
106
 
107
-
108
107
  if doc = processResponse(xhr, partialReplace)
109
108
  reflectNewUrl url
110
109
  nodes = changePage(extractTitleAndBody(doc)..., partialReplace, replaceContents, replaceAllExcept)
@@ -121,7 +120,9 @@ class window.Turbolinks
121
120
 
122
121
  if onlyKeys.length
123
122
  nodesToRefresh = [].concat(getNodesWithRefreshAlways(), getNodesMatchingRefreshKeys(onlyKeys))
124
- return refreshNodes(nodesToRefresh, body)
123
+ nodes = refreshNodes(nodesToRefresh, body)
124
+ setAutofocusElement() if anyAutofocusElement(nodes)
125
+ return nodes
125
126
  else
126
127
  refreshNodes(getNodesWithRefreshAlways(), body)
127
128
  persistStaticElements(body)
@@ -133,6 +134,7 @@ class window.Turbolinks
133
134
  triggerEvent 'page:before-replace'
134
135
  document.documentElement.replaceChild body, document.body
135
136
  CSRFToken.update csrfToken if csrfToken?
137
+ setAutofocusElement()
136
138
  executeScriptTags() if runScripts
137
139
  currentState = window.history.state
138
140
  triggerEvent 'page:change'
@@ -155,6 +157,18 @@ class window.Turbolinks
155
157
 
156
158
  return matchingNodes
157
159
 
160
+ anyAutofocusElement = (nodes) ->
161
+ for node in nodes
162
+ if node.querySelectorAll('input[autofocus], textarea[autofocus]').length > 0
163
+ return true
164
+
165
+ false
166
+
167
+ setAutofocusElement = ->
168
+ autofocusElement = (list = document.querySelectorAll 'input[autofocus], textarea[autofocus]')[list.length - 1]
169
+ if autofocusElement and document.activeElement isnt autofocusElement
170
+ autofocusElement.focus()
171
+
158
172
  deleteRefreshNeverNodes = (body) ->
159
173
  for node in body.querySelectorAll('[refresh-never]')
160
174
  node.parentNode.removeChild(node)
@@ -1,3 +1,3 @@
1
1
  module TurboGraft
2
- VERSION = '0.1.10'
2
+ VERSION = '0.1.11'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbograft
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kristian Plettenberg-Dussault
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2015-01-20 00:00:00.000000000 Z
16
+ date: 2015-01-22 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: coffee-rails