turbolinks 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Turbolinks
2
2
  ===========
3
3
 
4
- Turbolinks makes following links in your web application faster. Instead of letting the browser reload the JavaScript and CSS between each page change, and spend extra HTTP requests checking if the assets are up-to-date, we keep the current instance alive and replace only the body and the title in the head.
4
+ Turbolinks makes following links in your web application faster. Instead of letting the browser recompile the JavaScript and CSS between each page change, and potentially spend extra HTTP requests checking if the assets are up-to-date, we keep the current instance alive and replace only the body and the title in the head. Think CGI vs persistent process.
5
5
 
6
6
  This is similar to pjax, but instead of worrying about what element on the page to replace, and tailoring the server-side response to fit, we replace the entire body. This means that you get the bulk of the speed benefits from pjax (no recompiling of the JavaScript or CSS) without having to tailor the server-side response. It just works.
7
7
 
@@ -25,12 +25,27 @@ triggerPageChange = ->
25
25
  event.initEvent 'page:change', true, true
26
26
  document.dispatchEvent event
27
27
 
28
- replaceHTML = (html) ->
29
- doc = document.implementation.createHTMLDocument ""
30
- doc.open "replace"
31
- doc.write html
32
- doc.close()
28
+ createDocument = do ->
29
+ createDocumentUsingParser = (html) ->
30
+ (new DOMParser).parseFromString html, "text/html"
31
+
32
+ createDocumentUsingWrite = (html) ->
33
+ doc = document.implementation.createHTMLDocument ""
34
+ doc.open "replace"
35
+ doc.write html
36
+ doc.close
37
+ doc
38
+
39
+ if window.DOMParser
40
+ testDoc = createDocumentUsingParser "<html><body><p>test"
41
+
42
+ if testDoc?.body?.childNodes.length is 1
43
+ createDocumentUsingParser
44
+ else
45
+ createDocumentUsingWrite
33
46
 
47
+ replaceHTML = (html) ->
48
+ doc = createDocument html
34
49
  originalBody = document.body
35
50
  document.documentElement.appendChild doc.body, originalBody
36
51
  document.documentElement.removeChild originalBody
@@ -39,25 +54,27 @@ replaceHTML = (html) ->
39
54
 
40
55
  extractLink = (event) ->
41
56
  link = event.target
42
- until link is document or link.nodeName is 'A'
43
- link = link.parentNode
57
+ link = link.parentNode until link is document or link.nodeName is 'A'
44
58
  link
45
59
 
46
60
  crossOriginLink = (link) ->
47
- location.protocol isnt link.protocol || location.host isnt link.host
61
+ location.protocol isnt link.protocol or location.host isnt link.host
48
62
 
49
63
  anchoredLink = (link) ->
50
- ((link.hash && link.href.replace(link.hash, '')) is location.href.replace(location.hash, '')) ||
64
+ ((link.hash and link.href.replace(link.hash, '')) is location.href.replace(location.hash, '')) or
51
65
  (link.href is location.href + '#')
52
66
 
67
+ nonHtmlLink = (link) ->
68
+ link.href.match(/\.[a-z]+$/g) and not link.href.match(/\.html?$/g)
69
+
53
70
  noTurbolink = (link) ->
54
71
  link.getAttribute('data-no-turbolink')?
55
72
 
56
73
  newTabClick = (event) ->
57
- event.which > 1 || event.metaKey || event.ctrlKey
74
+ event.which > 1 or event.metaKey or event.ctrlKey
58
75
 
59
76
  ignoreClick = (event, link) ->
60
- crossOriginLink(link) || anchoredLink(link) || noTurbolink(link) || newTabClick(event)
77
+ crossOriginLink(link) or anchoredLink(link) or nonHtmlLink(link) or noTurbolink(link) or newTabClick(event)
61
78
 
62
79
  handleClick = (event) ->
63
80
  link = extractLink event
@@ -67,8 +84,7 @@ handleClick = (event) ->
67
84
  event.preventDefault()
68
85
 
69
86
 
70
- browserSupportsPushState =
71
- window.history && window.history.pushState && window.history.replaceState
87
+ browserSupportsPushState = window.history and window.history.pushState and window.history.replaceState
72
88
 
73
89
 
74
90
  if browserSupportsPushState
@@ -80,4 +96,4 @@ if browserSupportsPushState
80
96
  handleClick event
81
97
 
82
98
  # Call Turbolinks.visit(url) from client code
83
- @Turbolinks = { visit: visit }
99
+ @Turbolinks = { visit: visit }
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.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: