aboutsummaryrefslogtreecommitdiffstats
path: root/guides/assets/javascripts/guides.js
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2018-09-06 11:13:00 -0400
committerGitHub <noreply@github.com>2018-09-06 11:13:00 -0400
commit53be0132c3f66dd8510921215d940641bbfd9588 (patch)
treeb69e2f988a7f24b4c9a55d12f5916f5b93acbe5c /guides/assets/javascripts/guides.js
parent54a9dbf5f19e128a2da851707fdaf34868b50078 (diff)
parente5d38a24dc03c765c0b6a1fb39cae0b0758a1c4a (diff)
downloadrails-53be0132c3f66dd8510921215d940641bbfd9588.tar.gz
rails-53be0132c3f66dd8510921215d940641bbfd9588.tar.bz2
rails-53be0132c3f66dd8510921215d940641bbfd9588.zip
Merge pull request #32405 from yhirano55/use_turbolinks_in_guide
Use Turbolinks in Rails guides
Diffstat (limited to 'guides/assets/javascripts/guides.js')
-rw-r--r--guides/assets/javascripts/guides.js25
1 files changed, 23 insertions, 2 deletions
diff --git a/guides/assets/javascripts/guides.js b/guides/assets/javascripts/guides.js
index e39ac239cd..a37f5d1927 100644
--- a/guides/assets/javascripts/guides.js
+++ b/guides/assets/javascripts/guides.js
@@ -19,7 +19,18 @@
return elem;
}
- document.addEventListener("DOMContentLoaded", function() {
+ // For old browsers
+ this.each = function(node, callback) {
+ var array = Array.prototype.slice.call(node);
+ for(var i = 0; i < array.length; i++) callback(array[i]);
+ }
+
+ // Viewable on local
+ if (window.location.protocol === "file:") Turbolinks.supported = false;
+
+ document.addEventListener("turbolinks:load", function() {
+ window.SyntaxHighlighter.highlight({ "auto-links": false });
+
var guidesMenu = document.getElementById("guidesMenu");
var guides = document.getElementById("guides");
@@ -28,12 +39,22 @@
guides.classList.toggle("visible");
});
+ each(document.querySelectorAll("#guides a"), function(element) {
+ element.addEventListener("click", function(e) {
+ guides.classList.toggle("visible");
+ });
+ });
+
var guidesIndexItem = document.querySelector("select.guides-index-item");
var currentGuidePath = window.location.pathname;
guidesIndexItem.value = currentGuidePath.substring(currentGuidePath.lastIndexOf("/") + 1);
guidesIndexItem.addEventListener("change", function(e) {
- window.location = e.target.value;
+ if (Turbolinks.supported) {
+ Turbolinks.visit(e.target.value);
+ } else {
+ window.location = e.target.value;
+ }
});
var moreInfoButton = document.querySelector(".more-info-button");