On ഞായര് 15 ജനുവരി 2017 09:42 വൈകു, Antonio Terceiro wrote: > I would prefer to not do that this close to a freeze. Is there a good > reason for the fork? What are the differences between the fork and the > original? >
Its basically backported changes from newer releases to 2.5 version. From README.md, Turbolinks 5 is a ground-up rewrite with a new flow, new events, but the same core idea. It's available at [turbolinks/turbolinks](https://github.com/turbolinks/turbolinks). Releases for v2.5 stalled while version 3 was in development, but valuable changes were made on the [master branch](https://github.com/turbolinks/turbolinks-classic/commits/master). This repository is a fork with some changes from Turbolinks 2/3 before the rewrite, with the potential to backport small fixes from version 5 if needed. Full diff between turbolinks 2.5.3 and gitlab-turbolinks-classic 2.5.6 is attached
diff --git a/README.md b/README.md index e6716e0..ab70292 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,11 @@ -Turbolinks +Turbolinks Classic (GitLab fork) =========== +Turbolinks 5 is a ground-up rewrite with a new flow, new events, but the same core idea. It's available at [turbolinks/turbolinks](https://github.com/turbolinks/turbolinks). Releases for v2.5 stalled while version 3 was in development, but valuable changes were made on the [master branch](https://github.com/turbolinks/turbolinks-classic/commits/master). This repository is a fork with some changes from Turbolinks 2/3 before the rewrite, with the potential to backport small fixes from version 5 if needed. + +About Turbolinks +---------------- + 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. 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. @@ -21,7 +26,7 @@ The best way to find out just how fast it is? Try it on your own application. It No jQuery or any other library -------------------------------- -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. +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 you have. Events @@ -57,13 +62,18 @@ Turbolinks.pagesCached(); Turbolinks.pagesCached(20); ``` -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`. +If you need to make dynamic HTML updates in the current page and want it to be cached properly you can call: +```javascript +Turbolinks.cacheCurrentPage(); +``` + +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`. To implement a client-side spinner, you could listen for `page:fetch` to start it and `page:receive` to stop it. ```javascript // using jQuery for simplicity - + $(document).on("page:fetch", startSpinner); $(document).on("page:receive", stopSpinner); ``` diff --git a/gitlab-turbolinks-classic.gemspec b/gitlab-turbolinks-classic.gemspec new file mode 100644 index 0000000..5ef4220 --- /dev/null +++ b/gitlab-turbolinks-classic.gemspec @@ -0,0 +1,32 @@ +######################################################### +# This file has been automatically generated by gem2tgz # +######################################################### +# -*- encoding: utf-8 -*- + +Gem::Specification.new do |s| + s.name = "gitlab-turbolinks-classic" + s.version = "2.5.6" + + s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= + s.authors = ["David Heinemeier Hansson"] + s.date = "2017-01-05" + s.email = "da...@loudthinking.com" + s.files = ["MIT-LICENSE", "README.md", "lib/assets/javascripts/turbolinks.js.coffee", "lib/gitlab-turbolinks-classic.rb", "lib/turbolinks.rb", "lib/turbolinks/cookies.rb", "lib/turbolinks/redirection.rb", "lib/turbolinks/version.rb", "lib/turbolinks/x_domain_blocker.rb", "lib/turbolinks/xhr_headers.rb", "lib/turbolinks/xhr_url_for.rb", "test/attachment.html", "test/config.ru", "test/dummy.gif", "test/index.html", "test/manifest.appcache", "test/offline.html", "test/other.html", "test/redirect1.html", "test/redirect2.html", "test/reload.html", "test/withoutextension"] + s.homepage = "https://gitlab.com/jamedjo/gitlab-turbolinks-classic/" + s.licenses = ["MIT"] + s.require_paths = ["lib"] + s.rubygems_version = "1.8.23" + s.summary = "Turbolinks makes following links in your web application faster (use with Rails Asset Pipeline)" + + if s.respond_to? :specification_version then + s.specification_version = 4 + + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then + s.add_runtime_dependency(%q<coffee-rails>, [">= 0"]) + else + s.add_dependency(%q<coffee-rails>, [">= 0"]) + end + else + s.add_dependency(%q<coffee-rails>, [">= 0"]) + end +end diff --git a/lib/assets/javascripts/turbolinks.js.coffee b/lib/assets/javascripts/turbolinks.js.coffee index dad0f96..7e84e5e 100644 --- a/lib/assets/javascripts/turbolinks.js.coffee +++ b/lib/assets/javascripts/turbolinks.js.coffee @@ -65,10 +65,13 @@ fetchReplacement = (url, onLoadFunction, showProgressBar = true) -> reflectNewUrl url reflectRedirectedUrl() changePage extractTitleAndBody(doc)... + if showProgressBar + progressBar?.done() manuallyTriggerHashChangeForFirefox() onLoadFunction?() triggerEvent EVENTS.LOAD else + progressBar?.done() document.location.href = crossOriginRedirect() or url.absolute if progressBar and showProgressBar @@ -87,6 +90,7 @@ fetchReplacement = (url, onLoadFunction, showProgressBar = true) -> fetchHistory = (cachedPage) -> xhr?.abort() changePage cachedPage.title, cachedPage.body + progressBar?.done() recallScrollPosition cachedPage triggerEvent EVENTS.RESTORE @@ -127,7 +131,6 @@ changePage = (title, body, csrfToken, runScripts) -> setAutofocusElement() executeScriptTags() if runScripts currentState = window.history.state - progressBar?.done() triggerEvent EVENTS.CHANGE triggerEvent EVENTS.UPDATE @@ -228,6 +231,10 @@ processResponse = -> (contentType = xhr.getResponseHeader('Content-Type'))? and contentType.match /^(?:text\/html|application\/xhtml\+xml|application\/xml)(?:;|$)/ + downloadingFile = -> + (disposition = xhr.getResponseHeader('Content-Disposition'))? and + disposition.match /^attachment/ + extractTrackAssets = (doc) -> for node in doc.querySelector('head').childNodes when node.getAttribute?('data-turbolinks-track')? node.getAttribute('src') or node.getAttribute('href') @@ -241,7 +248,7 @@ processResponse = -> [a, b] = [b, a] if a.length > b.length value for value in a when value in b - if not clientOrServerError() and validContent() + if not clientOrServerError() and validContent() and not downloadingFile() doc = createDocument xhr.responseText if doc and !assetsChanged doc return doc @@ -375,14 +382,15 @@ class Click class ProgressBar className = 'turbolinks-progress-bar' + # Setting the opacity to a value < 1 fixes a display issue in Safari 6 and + # iOS 6 where the progress bar would fill the entire page. + originalOpacity = 0.99 constructor: (@elementSelector) -> @value = 0 @content = '' @speed = 300 - # Setting the opacity to a value < 1 fixes a display issue in Safari 6 and - # iOS 6 where the progress bar would fill the entire page. - @opacity = 0.99 + @opacity = originalOpacity @install() install: -> @@ -397,6 +405,10 @@ class ProgressBar document.head.removeChild(@styleElement) start: -> + if @value > 0 + @_reset() + @_reflow() + @advanceTo(5) advanceTo: (value) -> @@ -412,34 +424,41 @@ class ProgressBar done: -> if @value > 0 @advanceTo(100) - @_reset() - - _reset: -> - originalOpacity = @opacity + @_finish() - setTimeout => + _finish: -> + @fadeTimer = setTimeout => @opacity = 0 @_updateStyle() , @speed / 2 - setTimeout => - @value = 0 - @opacity = originalOpacity - @_withSpeed(0, => @_updateStyle(true)) - , @speed + @resetTimer = setTimeout(@_reset, @speed) + + _reflow: -> + @element.offsetHeight + + _reset: => + @_stopTimers() + @value = 0 + @opacity = originalOpacity + @_withSpeed(0, => @_updateStyle(true)) + + _stopTimers: -> + @_stopTrickle() + clearTimeout(@fadeTimer) + clearTimeout(@resetTimer) _startTrickle: -> - return if @trickling - @trickling = true - setTimeout(@_trickle, @speed) + return if @trickleTimer + @trickleTimer = setTimeout(@_trickle, @speed) _stopTrickle: -> - delete @trickling + clearTimeout(@trickleTimer) + delete @trickleTimer _trickle: => - return unless @trickling @advanceTo(@value + Math.random() / 2) - setTimeout(@_trickle, @speed) + @trickleTimer = setTimeout(@_trickle, @speed) _withSpeed: (speed, fn) -> originalSpeed = @speed @@ -544,12 +563,14 @@ else # Turbolinks.pagesCached() # Turbolinks.pagesCached(20) # Turbolinks.enableTransitionCache() +# Turbolinks.cacheCurrentPage() # Turbolinks.allowLinkExtensions('md') # Turbolinks.supported # Turbolinks.EVENTS @Turbolinks = { visit, pagesCached, + cacheCurrentPage, enableTransitionCache, enableProgressBar, allowLinkExtensions: Link.allowExtensions, diff --git a/lib/gitlab-turbolinks-classic.rb b/lib/gitlab-turbolinks-classic.rb new file mode 100644 index 0000000..38d39c9 --- /dev/null +++ b/lib/gitlab-turbolinks-classic.rb @@ -0,0 +1 @@ +require 'turbolinks' \ No newline at end of file diff --git a/lib/turbolinks.rb b/lib/turbolinks.rb index 4dbecf8..38bdd74 100644 --- a/lib/turbolinks.rb +++ b/lib/turbolinks.rb @@ -11,8 +11,14 @@ module Turbolinks ActiveSupport.on_load(:action_controller) do ActionController::Base.class_eval do include XHRHeaders, Cookies, XDomainBlocker, Redirection - before_filter :set_xhr_redirected_to, :set_request_method_cookie - after_filter :abort_xdomain_redirect + + if respond_to?(:before_action) + before_action :set_xhr_redirected_to, :set_request_method_cookie + after_action :abort_xdomain_redirect + else + before_filter :set_xhr_redirected_to, :set_request_method_cookie + after_filter :abort_xdomain_redirect + end end ActionDispatch::Request.class_eval do diff --git a/lib/turbolinks/version.rb b/lib/turbolinks/version.rb index 25fcc5c..89cf18b 100644 --- a/lib/turbolinks/version.rb +++ b/lib/turbolinks/version.rb @@ -1,3 +1,3 @@ module Turbolinks - VERSION = '2.5.3' + VERSION = '2.5.6' end diff --git a/metadata.yml b/metadata.yml deleted file mode 100644 index 7459c23..0000000 --- a/metadata.yml +++ /dev/null @@ -1,78 +0,0 @@ ---- !ruby/object:Gem::Specification -name: turbolinks -version: !ruby/object:Gem::Version - version: 2.5.3 -platform: ruby -authors: -- David Heinemeier Hansson -autorequire: -bindir: bin -cert_chain: [] -date: 2014-12-08 00:00:00.000000000 Z -dependencies: -- !ruby/object:Gem::Dependency - name: coffee-rails - requirement: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: '0' - type: :runtime - prerelease: false - version_requirements: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: '0' -description: -email: da...@loudthinking.com -executables: [] -extensions: [] -extra_rdoc_files: [] -files: -- MIT-LICENSE -- README.md -- lib/assets/javascripts/turbolinks.js.coffee -- lib/turbolinks.rb -- lib/turbolinks/cookies.rb -- lib/turbolinks/redirection.rb -- lib/turbolinks/version.rb -- lib/turbolinks/x_domain_blocker.rb -- lib/turbolinks/xhr_headers.rb -- lib/turbolinks/xhr_url_for.rb -- test/config.ru -- test/dummy.gif -- test/index.html -- test/manifest.appcache -- test/offline.html -- test/other.html -- test/redirect1.html -- test/redirect2.html -- test/reload.html -- test/withoutextension -homepage: https://github.com/rails/turbolinks/ -licenses: -- MIT -metadata: {} -post_install_message: -rdoc_options: [] -require_paths: -- lib -required_ruby_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: '0' -required_rubygems_version: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: '0' -requirements: [] -rubyforge_project: -rubygems_version: 2.2.2 -signing_key: -specification_version: 4 -summary: Turbolinks makes following links in your web application faster (use with - Rails Asset Pipeline) -test_files: [] diff --git a/test/attachment.html b/test/attachment.html new file mode 100644 index 0000000..3aa87c9 --- /dev/null +++ b/test/attachment.html @@ -0,0 +1,5 @@ +<html> +<body> +<script language="javascript">alert("you shouldn't see this");</script> +</body> +</html> diff --git a/test/config.ru b/test/config.ru index 538e2bc..4c239dc 100644 --- a/test/config.ru +++ b/test/config.ru @@ -53,3 +53,11 @@ end map "/" do run Rack::Directory.new(File.join(Root, "test")) end + +map "/attachment.txt" do + run Rack::File.new(File.join(Root, "test", "attachment.html"), "Content-Type" => "text/plain") +end + +map "/attachment.html" do + run Rack::File.new(File.join(Root, "test", "attachment.html"), "Content-Type" => "text/html", "Content-Disposition" => "attachment; filename=attachment.html") +end diff --git a/test/index.html b/test/index.html index 864947c..0f445a1 100644 --- a/test/index.html +++ b/test/index.html @@ -34,6 +34,8 @@ <li><a href="/bounce">Redirect</a></li> <li><a href="#">Hash link</a></li> <li><a href="/reload.html#foo">New assets track with hash link</a></li> + <li><a href="/attachment.txt">A text response should load normally</a></li> + <li><a href="/attachment.html">An html response with Content-Disposition: attachment should load normally</a></li> <li><h5>If you stop the server or go into airplane/offline mode</h5></li> <li><a href="/doesnotexist.html">A page with client error (4xx, rfc2616 sec. 10.4) should error out</a></li> <li><a href="/500">Also server errors (5xx, rfc2616 sec. 10.5) should error out</a></li>
signature.asc
Description: OpenPGP digital signature