turbolinks-js 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/assets/javascripts/turbolinks.js +27 -18
- data/test/config.ru +1 -1
- data/test/index.html +3 -3
- data/test/other.html +1 -1
- metadata +2 -2
@@ -1,6 +1,6 @@
|
|
1
1
|
// Generated by CoffeeScript 1.3.3
|
2
2
|
(function() {
|
3
|
-
var anchoredLink, browserSupportsPushState, cacheCurrentPage, changePage, constrainPageCacheTo, createDocument, crossOriginLink, currentState, extractLink, extractTitleAndBody, fetchHistory, fetchReplacement, handleClick, ignoreClick, initialized, newTabClick, noTurbolink, nonHtmlLink, pageCache, recallScrollPosition, reflectNewUrl, rememberCurrentState, rememberCurrentUrl, rememberInitialPage, samePageLink, triggerEvent, visit;
|
3
|
+
var anchoredLink, browserSupportsPushState, cacheCurrentPage, changePage, constrainPageCacheTo, createDocument, crossOriginLink, currentState, extractLink, extractTitleAndBody, fetchHistory, fetchReplacement, handleClick, ignoreClick, initialized, newTabClick, noTurbolink, nonHtmlLink, pageCache, recallScrollPosition, reflectNewUrl, rememberCurrentState, rememberCurrentUrl, rememberInitialPage, remoteLink, samePageLink, triggerEvent, visit;
|
4
4
|
|
5
5
|
pageCache = [];
|
6
6
|
|
@@ -20,11 +20,13 @@
|
|
20
20
|
|
21
21
|
fetchReplacement = function(url) {
|
22
22
|
var xhr;
|
23
|
+
triggerEvent('page:fetch');
|
23
24
|
xhr = new XMLHttpRequest;
|
24
25
|
xhr.open('GET', url, true);
|
25
26
|
xhr.setRequestHeader('Accept', 'text/html, application/xhtml+xml, application/xml');
|
26
27
|
xhr.onload = function() {
|
27
|
-
|
28
|
+
changePage.apply(null, extractTitleAndBody(xhr.responseText));
|
29
|
+
return triggerEvent('page:load');
|
28
30
|
};
|
29
31
|
xhr.onabort = function() {
|
30
32
|
return console.log('Aborted turbolink fetch!');
|
@@ -37,7 +39,8 @@
|
|
37
39
|
cacheCurrentPage();
|
38
40
|
if (page = pageCache[state.position]) {
|
39
41
|
changePage(page.title, page.body.cloneNode(true));
|
40
|
-
|
42
|
+
recallScrollPosition(page);
|
43
|
+
return triggerEvent('page:restore');
|
41
44
|
} else {
|
42
45
|
return fetchReplacement(document.location.href);
|
43
46
|
}
|
@@ -69,10 +72,12 @@
|
|
69
72
|
};
|
70
73
|
|
71
74
|
reflectNewUrl = function(url) {
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
75
|
+
if (url !== document.location.href) {
|
76
|
+
return window.history.pushState({
|
77
|
+
turbolinks: true,
|
78
|
+
position: currentState.position + 1
|
79
|
+
}, '', url);
|
80
|
+
}
|
76
81
|
};
|
77
82
|
|
78
83
|
rememberCurrentUrl = function() {
|
@@ -95,7 +100,7 @@
|
|
95
100
|
};
|
96
101
|
|
97
102
|
recallScrollPosition = function(page) {
|
98
|
-
return window.scrollTo(page.positionX, page.
|
103
|
+
return window.scrollTo(page.positionX, page.positionY);
|
99
104
|
};
|
100
105
|
|
101
106
|
triggerEvent = function(name) {
|
@@ -135,6 +140,15 @@
|
|
135
140
|
}
|
136
141
|
})();
|
137
142
|
|
143
|
+
handleClick = function(event) {
|
144
|
+
var link;
|
145
|
+
link = extractLink(event);
|
146
|
+
if (link.nodeName === 'A' && !ignoreClick(event, link)) {
|
147
|
+
visit(link.href);
|
148
|
+
return event.preventDefault();
|
149
|
+
}
|
150
|
+
};
|
151
|
+
|
138
152
|
extractLink = function(event) {
|
139
153
|
var link;
|
140
154
|
link = event.target;
|
@@ -160,6 +174,10 @@
|
|
160
174
|
return link.href.match(/\.[a-z]+(\?.*)?$/g) && !link.href.match(/\.html?(\?.*)?$/g);
|
161
175
|
};
|
162
176
|
|
177
|
+
remoteLink = function(link) {
|
178
|
+
return link.getAttribute('data-remote') != null;
|
179
|
+
};
|
180
|
+
|
163
181
|
noTurbolink = function(link) {
|
164
182
|
return link.getAttribute('data-no-turbolink') != null;
|
165
183
|
};
|
@@ -169,16 +187,7 @@
|
|
169
187
|
};
|
170
188
|
|
171
189
|
ignoreClick = function(event, link) {
|
172
|
-
return samePageLink(link) || crossOriginLink(link) || anchoredLink(link) || nonHtmlLink(link) || noTurbolink(link) || newTabClick(event);
|
173
|
-
};
|
174
|
-
|
175
|
-
handleClick = function(event) {
|
176
|
-
var link;
|
177
|
-
link = extractLink(event);
|
178
|
-
if (link.nodeName === 'A' && !ignoreClick(event, link)) {
|
179
|
-
visit(link.href);
|
180
|
-
return event.preventDefault();
|
181
|
-
}
|
190
|
+
return samePageLink(link) || crossOriginLink(link) || anchoredLink(link) || nonHtmlLink(link) || remoteLink(link) || noTurbolink(link) || newTabClick(event);
|
182
191
|
};
|
183
192
|
|
184
193
|
browserSupportsPushState = window.history && window.history.pushState && window.history.replaceState;
|
data/test/config.ru
CHANGED
data/test/index.html
CHANGED
@@ -12,10 +12,10 @@
|
|
12
12
|
</head>
|
13
13
|
<body class="page-index">
|
14
14
|
<ul style="margin-top:200px;">
|
15
|
-
<li><a href="/
|
16
|
-
<li><a href="/
|
15
|
+
<li><a href="/other.html">Other page</a></li>
|
16
|
+
<li><a href="/other.html"><span>Wrapped link</span></a></li>
|
17
17
|
<li><a href="http://www.google.com/">Cross origin</a></li>
|
18
|
-
<li><a href="/
|
18
|
+
<li><a href="/dummy.gif?12345">Query Param Image Link</a></li>
|
19
19
|
<li><a href="#">Hash link</a></li>
|
20
20
|
</ul>
|
21
21
|
|
data/test/other.html
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: turbolinks-js
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-09-
|
13
|
+
date: 2012-09-28 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description:
|
16
16
|
email:
|