turbolinks 2.5.4 → 5.0.0.beta1

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: '0912c3f96e36af55ff15e6090feb8bb5d153c6a2'
4
- data.tar.gz: bb11128a5055b2730ddf1133671e7a3975bdad7d
3
+ metadata.gz: b406fb2b32195723c5a61a68f9839bac2f6c5fa2
4
+ data.tar.gz: aaf7a03f4944172141332d8131ec3fbb0afbae7c
5
5
  SHA512:
6
- metadata.gz: 9d3da852a6f31f86b3b9191ce755fe017450fd663337ab610bca3d3ffd7c31cbdad0d08591df289e30501e91c7076bcbc6e9209e10e768c9b27d00fcf40a9fde
7
- data.tar.gz: ec47299dbd6c27caf25b560ed42757fa7006689052fd142ebbb2f4f1f13347bb830d326f847300b806d67d9591f5365126612e9f9b927744716af48f56452f48
6
+ metadata.gz: 7c9d8e8f4bcafcd542a015d0485b416284426ca0d6d4a99c1fbcd750898c42228803c45fbe23b3c75a63de1ca6619bb83032c7a7e731b7860635419fcb64bb9a
7
+ data.tar.gz: f450ff75f5f79136d30fe47773c362ba9893648b13c38e467f117642b2a6f18bd4182f184a4860e804f7e52b8054adeabb74d7dac7c36ab35295f0c325f40d6d
@@ -1,4 +1,4 @@
1
- Copyright 2012-2014 David Heinemeier Hansson
1
+ Copyright 2016 Basecamp, LLC
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,241 +0,0 @@
1
- Turbolinks
2
- ===========
3
-
4
- Turbolinks makes following links in your web application faster. Instead of letting the browser recompile the JavaScript and CSS between each page change, it keeps the current page instance alive and replaces only the body and the title in the head. Think CGI vs persistent process.
5
-
6
- This is similar to [pjax](https://github.com/defunkt/jquery-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
-
8
- Do note that this of course means that you'll have a long-running, persistent session with maintained state. That's what's making it so fast. But it also means that you may have to pay additional care not to leak memory or otherwise bloat that long-running state. That should rarely be a problem unless you're doing something really funky, but you do have to be aware of it. Your memory leaking sins will not be swept away automatically by the cleansing page change any more.
9
-
10
-
11
- How much faster is it really?
12
- -----------------------------
13
-
14
- It depends. The more CSS and JavaScript you have, the bigger the benefit of not throwing away the browser instance and recompiling all of it for every page. Just like a CGI script that says "hello world" will be fast, but a CGI script loading Rails on every request will not.
15
-
16
- In any case, the benefit can be up to [twice as fast](https://github.com/steveklabnik/turbolinks_test/tree/all_the_assets) in apps with lots of JS and CSS. Of course, your mileage may vary, be dependent on your browser version, the moon cycle, and all other factors affecting performance testing. But at least it's a yardstick.
17
-
18
- The best way to find out just how fast it is? Try it on your own application. It hardly takes any effort at all.
19
-
20
-
21
- No jQuery or any other library
22
- --------------------------------
23
-
24
- Turbolinks is designed to be as light-weight as possible (so you won't think twice about using it even for mobile stuff). It does not require jQuery or any other library to work. But it works great _with_ the jQuery or Prototype framework, or whatever else have you.
25
-
26
-
27
- Events
28
- ------
29
-
30
- With Turbolinks pages will change without a full reload, so you can't rely on `DOMContentLoaded` or `jQuery.ready()` to trigger your code. Instead Turbolinks fires events on `document` to provide hooks into the lifecycle of the page.
31
-
32
- ***Load* a fresh version of a page from the server:**
33
- * `page:before-change` a Turbolinks-enabled link has been clicked *(see below for more details)*
34
- * `page:fetch` starting to fetch a new target page
35
- * `page:receive` the page has been fetched from the server, but not yet parsed
36
- * `page:before-unload` the page has been parsed and is about to be changed
37
- * `page:change` the page has been changed to the new version (and on DOMContentLoaded)
38
- * `page:update` is triggered alongside both page:change and jQuery's ajaxSuccess (if jQuery is available - otherwise you can manually trigger it when calling XMLHttpRequest in your own code)
39
- * `page:load` is fired at the end of the loading process.
40
-
41
- Handlers bound to the `page:before-change` event may return `false`, which will cancel the Turbolinks process.
42
-
43
- By default, Turbolinks caches 10 of these page loads. It listens to the [popstate](https://developer.mozilla.org/en-US/docs/DOM/Manipulating_the_browser_history#The_popstate_event) event and attempts to restore page state from the cache when it's triggered. When `popstate` is fired the following process happens:
44
-
45
- ***Restore* a cached page from the client-side cache:**
46
- * `page:before-unload` page has been fetched from the cache and is about to be changed
47
- * `page:change` page has changed to the cached page.
48
- * `page:restore` is fired at the end of restore process.
49
-
50
- The number of pages Turbolinks caches can be configured to suit your application's needs:
51
-
52
- ```javascript
53
- // View the current cache size
54
- Turbolinks.pagesCached();
55
-
56
- // Set the cache size
57
- Turbolinks.pagesCached(20);
58
- ```
59
-
60
- When a page is removed from the cache due to the cache reaching its size limit, the `page:expire` event is triggered. Listeners bound to this event can access the cached page object using `event.originalEvent.data`. Keys of note for this page cache object include `url`, `body`, and `title`.
61
-
62
- To implement a client-side spinner, you could listen for `page:fetch` to start it and `page:receive` to stop it.
63
-
64
- ```javascript
65
- // using jQuery for simplicity
66
-
67
- $(document).on("page:fetch", startSpinner);
68
- $(document).on("page:receive", stopSpinner);
69
- ```
70
-
71
- DOM transformations that are idempotent are best. If you have transformations that are not, bind them to `page:load` (in addition to the initial page load) instead of `page:change` (as that would run them again on the cached pages):
72
-
73
- ```javascript
74
- // using jQuery for simplicity
75
-
76
- $(document).on("ready page:load", nonIdempotentFunction);
77
- ```
78
-
79
- Transition Cache: A Speed Boost
80
- -------------------------------
81
-
82
- Transition Cache, added in v2.2.0, makes loading cached pages instantaneous. Once a user has visited a page, returning later to the page results in an instant load.
83
-
84
- For example, if Page A is already cached by Turbolinks and you are on Page B, clicking a link to Page A will *immediately* display the cached copy of Page A. Turbolinks will then fetch Page A from the server and replace the cached page once the new copy is returned.
85
-
86
- To enable Transition Cache, include the following in your javascript:
87
- ```javascript
88
- Turbolinks.enableTransitionCache();
89
- ```
90
-
91
- The one drawback is that dramatic differences in appearance between a cached copy and new copy may lead to a jarring affect for the end-user. This will be especially true for pages that have many moving parts (expandable sections, sortable tables, infinite scrolling, etc.).
92
-
93
- If you find that a page is causing problems, you can have Turbolinks skip displaying the cached copy by adding `data-no-transition-cache` to any DOM element on the offending page.
94
-
95
- Progress Bar
96
- ------------
97
-
98
- Because Turbolinks skips the traditional full page reload, browsers won't display their native progress bar when changing pages. To fill this void, Turbolinks offers an optional JavaScript-and-CSS-based progress bar to display page loading progress.
99
-
100
- To enable the progress bar, include the following in your JavaScript:
101
- ```javascript
102
- Turbolinks.enableProgressBar();
103
- ```
104
-
105
- The progress bar is implemented on the `<html>` element's pseudo `:before` element and can be **customized** by including CSS with higher specificity than the included styles. For example:
106
-
107
- ```css
108
- html.turbolinks-progress-bar::before {
109
- background-color: red !important;
110
- height: 5px !important;
111
- }
112
- ```
113
-
114
- In Turbolinks 3.0, the progress bar will be turned on by default.
115
-
116
-
117
- Initialization
118
- --------------
119
-
120
- Turbolinks will be enabled **only** if the server has rendered a `GET` request.
121
-
122
- Some examples, given a standard RESTful resource:
123
-
124
- * `POST :create` => resource successfully created => redirect to `GET :show`
125
- * Turbolinks **ENABLED**
126
- * `POST :create` => resource creation failed => render `:new`
127
- * Turbolinks **DISABLED**
128
-
129
- **Why not all request types?** Some browsers track the request method of each page load, but triggering pushState methods don't change this value. This could lead to the situation where pressing the browser's reload button on a page that was fetched with Turbolinks would attempt a `POST` (or something other than `GET`) because the last full page load used that method.
130
-
131
-
132
- Opting out of Turbolinks
133
- ------------------------
134
-
135
- By default, all internal HTML links will be funneled through Turbolinks, but you can opt out by marking links or their parent container with `data-no-turbolink`. For example, if you mark a div with `data-no-turbolink`, then all links inside of that div will be treated as regular links. If you mark the body, every link on that entire page will be treated as regular links.
136
-
137
- ```html
138
- <a href="/">Home (via Turbolinks)</a>
139
- <div id="some-div" data-no-turbolink>
140
- <a href="/">Home (without Turbolinks)</a>
141
- </div>
142
- ```
143
-
144
- Note that internal links to files containing a file extension other than **.html** will automatically be opted out of Turbolinks. So links to /images/panda.gif will just work as expected. To whitelist additional file extensions to be processed by Turbolinks, use `Turbolinks.allowLinkExtensions()`.
145
-
146
- ```javascript
147
- Turbolinks.allowLinkExtensions(); // => ['html']
148
- Turbolinks.allowLinkExtensions('md'); // => ['html', 'md']
149
- Turbolinks.allowLinkExtensions('coffee', 'scss'); // => ['html', 'md', 'coffee', 'scss']
150
- ```
151
-
152
- Also, Turbolinks is installed as the last click handler for links. So if you install another handler that calls event.preventDefault(), Turbolinks will not run. This ensures that you can safely use Turbolinks with stuff like `data-method`, `data-remote`, or `data-confirm` from Rails.
153
-
154
-
155
- jquery.turbolinks
156
- -----------------
157
-
158
- If you have a lot of existing JavaScript that binds elements on jQuery.ready(), you can pull the [jquery.turbolinks](https://github.com/kossnocorp/jquery.turbolinks) library into your project that will trigger ready() when Turbolinks triggers the `page:load` event. It may restore functionality of some libraries.
159
-
160
- Add the gem to your project, then add the following line to your JavaScript manifest file, after `jquery.js` but before `turbolinks.js`:
161
-
162
- ``` js
163
- //= require jquery.turbolinks
164
- ```
165
-
166
- Additional details and configuration options can be found in the [jquery.turbolinks README](https://github.com/kossnocorp/jquery.turbolinks/blob/master/README.md).
167
-
168
- Asset change detection
169
- ----------------------
170
-
171
- You can track certain assets, like application.js and application.css, that you want to ensure are always of the latest version inside a Turbolinks session. This is done by marking those asset links with data-turbolinks-track, like so:
172
-
173
- ```html
174
- <link href="/assets/application-9bd64a86adb3cd9ab3b16e9dca67a33a.css" rel="stylesheet"
175
- type="text/css" data-turbolinks-track>
176
- ```
177
-
178
- If those assets change URLs (embed an md5 stamp to ensure this), the page will do a full reload instead of going through Turbolinks. This ensures that all Turbolinks sessions will always be running off your latest JavaScript and CSS.
179
-
180
- When this happens, you'll technically be requesting the same page twice. Once through Turbolinks to detect that the assets changed, and then again when we do a full redirect to that page.
181
-
182
-
183
- Evaluating script tags
184
- ----------------------
185
-
186
- Turbolinks will evaluate any script tags in pages it visits, if those tags do not have a type or if the type is text/javascript. All other script tags will be ignored.
187
-
188
- As a rule of thumb when switching to Turbolinks, move all of your javascript tags inside the `head` and then work backwards, only moving javascript code back to the body if absolutely necessary. If you have any script tags in the body you do not want to be re-evaluated then you can set the `data-turbolinks-eval` attribute to `false`:
189
-
190
- ```html
191
- <script type="text/javascript" data-turbolinks-eval=false>
192
- console.log("I'm only run once on the initial page load");
193
- </script>
194
- ```
195
-
196
- Triggering a Turbolinks visit manually
197
- ---------------------------------------
198
-
199
- You can use `Turbolinks.visit(path)` to go to a URL through Turbolinks.
200
-
201
- You can also use `redirect_via_turbolinks_to` in Rails to perform a redirect via Turbolinks.
202
-
203
-
204
- Full speed for pushState browsers, graceful fallback for everything else
205
- ------------------------------------------------------------------------
206
-
207
- Like pjax, this naturally only works with browsers capable of pushState. But of course we fall back gracefully to full page reloads for browsers that do not support it.
208
-
209
-
210
- Compatibility
211
- -------------
212
-
213
- 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.
214
-
215
- 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. For help with this, check out the [Turbolinks Compatibility](http://reed.github.io/turbolinks-compatibility) project.
216
-
217
-
218
- Installation
219
- ------------
220
-
221
- 1. Add `gem 'turbolinks'` to your Gemfile.
222
- 1. Run `bundle install`.
223
- 1. Add `//= require turbolinks` to your Javascript manifest file (usually found at `app/assets/javascripts/application.js`). If your manifest requires both turbolinks and jQuery, make sure turbolinks is listed *after* jQuery.
224
- 1. Restart your server and you're now using turbolinks!
225
-
226
- Language Ports
227
- --------------
228
-
229
- *These projects are not affiliated with or endorsed by the Rails Turbolinks team.*
230
-
231
- * [Flask Turbolinks](https://github.com/lepture/flask-turbolinks) (Python Flask)
232
- * [Django Turbolinks](https://github.com/dgladkov/django-turbolinks) (Python Django)
233
- * [ASP.NET MVC Turbolinks](https://github.com/kazimanzurrashid/aspnetmvcturbolinks)
234
- * [PHP Turbolinks Component](https://github.com/helthe/Turbolinks) (Symfony Component)
235
- * [PHP Turbolinks Package](https://github.com/frenzyapp/turbolinks) (Laravel Package)
236
- * [Grails Turbolinks](http://grails.org/plugin/turbolinks) (Grails Plugin)
237
-
238
- Credits
239
- -------
240
-
241
- Thanks to Chris Wanstrath for his original work on Pjax. Thanks to Sam Stephenson and Josh Peek for their additional work on Pjax and Stacker and their help with getting Turbolinks released. Thanks to David Estes and Nick Reed for handling the lion's share of post-release issues and feature requests. And thanks to everyone else who's fixed or reported an issue!
@@ -1,42 +1,27 @@
1
1
  require 'turbolinks/version'
2
- require 'turbolinks/xhr_headers'
3
- require 'turbolinks/xhr_url_for'
4
- require 'turbolinks/cookies'
5
- require 'turbolinks/x_domain_blocker'
6
2
  require 'turbolinks/redirection'
3
+ require 'turbolinks/source'
7
4
 
8
5
  module Turbolinks
6
+ module Controller
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ include Redirection
11
+ end
12
+ end
13
+
9
14
  class Engine < ::Rails::Engine
10
- initializer :turbolinks do |config|
11
- ActiveSupport.on_load(:action_controller) do
12
- ActionController::Base.class_eval do
13
- include XHRHeaders, Cookies, XDomainBlocker, Redirection
14
- if respond_to?(:before_action)
15
- before_action :set_xhr_redirected_to, :set_request_method_cookie
16
- after_action :abort_xdomain_redirect
17
- else
18
- before_filter :set_xhr_redirected_to, :set_request_method_cookie
19
- after_filter :abort_xdomain_redirect
20
- end
21
- end
15
+ config.turbolinks = ActiveSupport::OrderedOptions.new
16
+ config.turbolinks.auto_include = true
17
+ config.assets.paths += [Turbolinks::Source.asset_path]
22
18
 
23
- ActionDispatch::Request.class_eval do
24
- def referer
25
- self.headers['X-XHR-Referer'] || super
26
- end
27
- alias referrer referer
19
+ initializer :turbolinks do |app|
20
+ ActiveSupport.on_load(:action_controller) do
21
+ if app.config.turbolinks.auto_include
22
+ include Controller
28
23
  end
29
24
  end
30
-
31
- ActiveSupport.on_load(:action_view) do
32
- (ActionView::RoutingUrlFor rescue ActionView::Helpers::UrlHelper).module_eval do
33
- if defined?(prepend) && Rails.version >= '4'
34
- prepend XHRUrlFor
35
- else
36
- include LegacyXHRUrlFor
37
- end
38
- end
39
- end unless RUBY_VERSION =~ /^1\.8/
40
25
  end
41
26
  end
42
27
  end
@@ -1,15 +1,48 @@
1
1
  module Turbolinks
2
- # Provides a means of using Turbolinks to perform redirects. The server
3
- # will respond with a JavaScript call to Turbolinks.visit(url).
4
2
  module Redirection
5
3
  extend ActiveSupport::Concern
6
4
 
7
- def redirect_via_turbolinks_to(url = {}, response_status = {})
8
- redirect_to(url, response_status)
5
+ included do
6
+ before_action :set_turbolinks_location_header_from_session
7
+ end
8
+
9
+ def redirect_to(url = {}, options = {})
10
+ turbolinks = options.delete(:turbolinks)
9
11
 
10
- self.status = 200
11
- self.response_body = "Turbolinks.visit('#{location}');"
12
- response.content_type = Mime[:js]
12
+ super.tap do
13
+ if turbolinks != false && request.xhr? && !request.get?
14
+ visit_location_with_turbolinks(location, turbolinks)
15
+ else
16
+ if request.headers["Turbolinks-Referrer"]
17
+ store_turbolinks_location_in_session(location)
18
+ end
19
+ end
20
+ end
13
21
  end
22
+
23
+ private
24
+ def visit_location_with_turbolinks(location, action)
25
+ visit_options = {
26
+ action: action.to_s == "advance" ? action : "replace"
27
+ }
28
+
29
+ script = []
30
+ script << "Turbolinks.clearCache()"
31
+ script << "Turbolinks.visit(#{location.to_json}, #{visit_options.to_json})"
32
+
33
+ self.status = 200
34
+ self.response_body = script.join("\n")
35
+ response.content_type = "text/javascript"
36
+ end
37
+
38
+ def store_turbolinks_location_in_session(location)
39
+ session[:_turbolinks_location] = location if session
40
+ end
41
+
42
+ def set_turbolinks_location_header_from_session
43
+ if session && session[:_turbolinks_location]
44
+ response.headers["Turbolinks-Location"] = session.delete(:_turbolinks_location)
45
+ end
46
+ end
14
47
  end
15
48
  end
@@ -1,3 +1,3 @@
1
1
  module Turbolinks
2
- VERSION = '2.5.4'
2
+ VERSION = '5.0.0.beta1'
3
3
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbolinks
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.4
4
+ version: 5.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-06 00:00:00.000000000 Z
11
+ date: 2016-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: coffee-rails
14
+ name: turbolinks-source
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -30,27 +30,12 @@ executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
- - MIT-LICENSE
33
+ - LICENSE
34
34
  - README.md
35
- - lib/assets/javascripts/turbolinks.js.coffee
36
35
  - lib/turbolinks.rb
37
- - lib/turbolinks/cookies.rb
38
36
  - lib/turbolinks/redirection.rb
39
37
  - lib/turbolinks/version.rb
40
- - lib/turbolinks/x_domain_blocker.rb
41
- - lib/turbolinks/xhr_headers.rb
42
- - lib/turbolinks/xhr_url_for.rb
43
- - test/config.ru
44
- - test/dummy.gif
45
- - test/index.html
46
- - test/manifest.appcache
47
- - test/offline.html
48
- - test/other.html
49
- - test/redirect1.html
50
- - test/redirect2.html
51
- - test/reload.html
52
- - test/withoutextension
53
- homepage: https://github.com/rails/turbolinks/
38
+ homepage: https://github.com/turbolinks/turbolinks-rails
54
39
  licenses:
55
40
  - MIT
56
41
  metadata: {}
@@ -65,14 +50,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
50
  version: '0'
66
51
  required_rubygems_version: !ruby/object:Gem::Requirement
67
52
  requirements:
68
- - - ">="
53
+ - - ">"
69
54
  - !ruby/object:Gem::Version
70
- version: '0'
55
+ version: 1.3.1
71
56
  requirements: []
72
57
  rubyforge_project:
73
- rubygems_version: 2.6.12
58
+ rubygems_version: 2.4.8
74
59
  signing_key:
75
60
  specification_version: 4
76
- summary: Turbolinks makes following links in your web application faster (use with
77
- Rails Asset Pipeline)
61
+ summary: Turbolinks makes navigating your web application faster
78
62
  test_files: []