turbolinks-js 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -5,6 +5,14 @@ Same as Turbolinks but without the CoffeeScript requirement.
5
5
  Check [Turbolinks](https://github.com/rails/turbolinks) for
6
6
  more information.
7
7
 
8
+ Compatibility
9
+ -------------
10
+
11
+ Turbolinks is designed to work with any browser that fully supports pushState and all the related APIs. This includes Safari 6.0+ (but not Safari 5.1.x!), IE10, and latest Chromes and Firefoxes.
12
+
13
+ Do note that existing JavaScript libraries may not all be compatible with Turbolinks out of the box due to the change in instantiation cycle. You might very well have to modify them to work with Turbolinks' new set of events.
14
+
15
+
8
16
  Installation
9
17
  ------------
10
18
 
@@ -1,6 +1,7 @@
1
1
  // Generated by CoffeeScript 1.3.3
2
2
  (function() {
3
- var anchoredLink, assets, assetsChanged, browserCompatibleDocumentParser, browserSupportsPushState, cacheCurrentPage, changePage, constrainPageCacheTo, createDocument, crossOriginLink, currentState, executeScriptTags, extractAssets, extractLink, extractTitleAndBody, fetchHistory, fetchReplacement, handleClick, ignoreClick, initialized, installClickHandlerLast, intersection, noTurbolink, nonHtmlLink, nonStandardClick, pageCache, recallScrollPosition, referer, reflectNewUrl, reflectRedirectedUrl, rememberCurrentAssets, rememberCurrentState, rememberCurrentUrl, rememberInitialPage, resetScrollPosition, samePageLink, triggerEvent, visit,
3
+ var anchoredLink, assets, assetsChanged, browserCompatibleDocumentParser, browserSupportsPushState, cacheCurrentPage, changePage, constrainPageCacheTo, createDocument, crossOriginLink, currentState, executeScriptTags, extractAssets, extractLink, extractTitleAndBody, fetchHistory, fetchReplacement, handleClick, ignoreClick, initialized, installClickHandlerLast, intersection, noTurbolink, nonHtmlLink, nonStandardClick, pageCache, recallScrollPosition, referer, reflectNewUrl, reflectRedirectedUrl, rememberCurrentAssets, rememberCurrentState, rememberCurrentUrl, rememberInitialPage, resetScrollPosition, targetLink, triggerEvent, visit,
4
+ __hasProp = {}.hasOwnProperty,
4
5
  __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
5
6
 
6
7
  initialized = false;
@@ -11,7 +12,7 @@
11
12
 
12
13
  assets = [];
13
14
 
14
- pageCache = [];
15
+ pageCache = {};
15
16
 
16
17
  createDocument = null;
17
18
 
@@ -37,7 +38,7 @@
37
38
  var doc;
38
39
  doc = createDocument(xhr.responseText);
39
40
  if (assetsChanged(doc)) {
40
- return document.location.href = url;
41
+ return document.location.reload();
41
42
  } else {
42
43
  changePage.apply(null, extractTitleAndBody(doc));
43
44
  reflectRedirectedUrl(xhr);
@@ -76,25 +77,51 @@
76
77
  };
77
78
 
78
79
  constrainPageCacheTo = function(limit) {
79
- return delete pageCache[currentState.position - limit];
80
+ var key, value, _results;
81
+ _results = [];
82
+ for (key in pageCache) {
83
+ if (!__hasProp.call(pageCache, key)) continue;
84
+ value = pageCache[key];
85
+ if (key <= currentState.position - limit) {
86
+ _results.push(pageCache[key] = null);
87
+ } else {
88
+ _results.push(void 0);
89
+ }
90
+ }
91
+ return _results;
80
92
  };
81
93
 
82
- changePage = function(title, body) {
94
+ changePage = function(title, body, runScripts) {
83
95
  document.title = title;
84
96
  document.documentElement.replaceChild(body, document.body);
85
- executeScriptTags();
97
+ if (runScripts) {
98
+ executeScriptTags();
99
+ }
86
100
  currentState = window.history.state;
87
101
  return triggerEvent('page:change');
88
102
  };
89
103
 
90
104
  executeScriptTags = function() {
91
- var script, _i, _len, _ref, _ref1, _results;
105
+ var attr, copy, parent, script, _i, _j, _len, _len1, _ref, _ref1, _ref2, _results;
92
106
  _ref = document.body.getElementsByTagName('script');
93
107
  _results = [];
94
108
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
95
109
  script = _ref[_i];
96
110
  if ((_ref1 = script.type) === '' || _ref1 === 'text/javascript') {
97
- _results.push(eval(script.innerHTML));
111
+ if ((script.src != null) && script.src !== '' && !(script.getAttribute('data-turbolinks-evaluated') != null)) {
112
+ copy = document.createElement('script');
113
+ _ref2 = script.attributes;
114
+ for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
115
+ attr = _ref2[_j];
116
+ copy.setAttribute(attr.name, attr.value);
117
+ }
118
+ copy.setAttribute('data-turbolinks-evaluated', '');
119
+ parent = script.parentNode;
120
+ parent.removeChild(script);
121
+ _results.push(parent.insertBefore(copy, parent.childNodes[0]));
122
+ } else {
123
+ _results.push(window["eval"](script.innerHTML));
124
+ }
98
125
  }
99
126
  }
100
127
  return _results;
@@ -120,7 +147,7 @@
120
147
  rememberCurrentUrl = function() {
121
148
  return window.history.replaceState({
122
149
  turbolinks: true,
123
- position: window.history.length - 1
150
+ position: Date.now()
124
151
  }, '', document.location.href);
125
152
  };
126
153
 
@@ -170,7 +197,9 @@
170
197
  };
171
198
 
172
199
  assetsChanged = function(doc) {
173
- return intersection(extractAssets(doc), assets).length !== assets.length;
200
+ var extractedAssets;
201
+ extractedAssets = extractAssets(doc);
202
+ return extractedAssets.length !== assets.length || intersection(extractedAssets, assets).length !== assets.length;
174
203
  };
175
204
 
176
205
  intersection = function(a, b) {
@@ -191,7 +220,7 @@
191
220
  extractTitleAndBody = function(doc) {
192
221
  var title;
193
222
  title = doc.querySelector('title');
194
- return [title != null ? title.textContent : void 0, doc.body];
223
+ return [title != null ? title.textContent : void 0, doc.body, 'runScripts'];
195
224
  };
196
225
 
197
226
  browserCompatibleDocumentParser = function() {
@@ -204,7 +233,7 @@
204
233
  doc = document.implementation.createHTMLDocument('');
205
234
  doc.open('replace');
206
235
  doc.write(html);
207
- doc.close;
236
+ doc.close();
208
237
  return doc;
209
238
  };
210
239
  if (window.DOMParser) {
@@ -228,7 +257,7 @@
228
257
  var link;
229
258
  if (!event.defaultPrevented) {
230
259
  link = extractLink(event);
231
- if (link.nodeName === 'A' && !ignoreClick(event, link)) {
260
+ if ((link != null ? link.nodeName : void 0) === 'A' && !ignoreClick(event, link)) {
232
261
  visit(link.href);
233
262
  return event.preventDefault();
234
263
  }
@@ -238,16 +267,12 @@
238
267
  extractLink = function(event) {
239
268
  var link;
240
269
  link = event.target;
241
- while (!(link === document || link.nodeName === 'A')) {
270
+ while (!(!link.parentNode || link.nodeName === 'A')) {
242
271
  link = link.parentNode;
243
272
  }
244
273
  return link;
245
274
  };
246
275
 
247
- samePageLink = function(link) {
248
- return link.href === document.location.href;
249
- };
250
-
251
276
  crossOriginLink = function(link) {
252
277
  return location.protocol !== link.protocol || location.host !== link.host;
253
278
  };
@@ -269,12 +294,16 @@
269
294
  return ignore;
270
295
  };
271
296
 
297
+ targetLink = function(link) {
298
+ return link.target.length !== 0;
299
+ };
300
+
272
301
  nonStandardClick = function(event) {
273
302
  return event.which > 1 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey;
274
303
  };
275
304
 
276
305
  ignoreClick = function(event, link) {
277
- return crossOriginLink(link) || anchoredLink(link) || nonHtmlLink(link) || noTurbolink(link) || nonStandardClick(event);
306
+ return crossOriginLink(link) || anchoredLink(link) || nonHtmlLink(link) || noTurbolink(link) || targetLink(link) || nonStandardClick(event);
278
307
  };
279
308
 
280
309
  browserSupportsPushState = window.history && window.history.pushState && window.history.replaceState && window.history.state !== void 0;
@@ -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
@@ -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-js
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
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-10-18 00:00:00.000000000 Z
13
+ date: 2012-11-29 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description:
16
16
  email:
@@ -36,20 +36,20 @@ rdoc_options: []
36
36
  require_paths:
37
37
  - lib
38
38
  required_ruby_version: !ruby/object:Gem::Requirement
39
- none: false
40
39
  requirements:
41
40
  - - ! '>='
42
41
  - !ruby/object:Gem::Version
43
42
  version: '0'
44
- required_rubygems_version: !ruby/object:Gem::Requirement
45
43
  none: false
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
45
  requirements:
47
46
  - - ! '>='
48
47
  - !ruby/object:Gem::Version
49
48
  version: '0'
49
+ none: false
50
50
  requirements: []
51
51
  rubyforge_project:
52
- rubygems_version: 1.8.23
52
+ rubygems_version: 1.8.24
53
53
  signing_key:
54
54
  specification_version: 3
55
55
  summary: Same as Turbolinks but without the CoffeeScript requirement