Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #32405 from yhirano55/use_turbolinks_in_guide
Browse files Browse the repository at this point in the history
Use Turbolinks in Rails guides
  • Loading branch information
rafaelfranca committed Sep 6, 2018
2 parents 54a9dbf + e5d38a2 commit 53be013
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 32 deletions.
25 changes: 23 additions & 2 deletions guides/assets/javascripts/guides.js
Expand Up @@ -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");

Expand All @@ -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");
Expand Down
18 changes: 7 additions & 11 deletions guides/assets/javascripts/responsive-tables.js
Expand Up @@ -3,16 +3,6 @@

var switched = false;

// For old browsers
var each = function(node, callback) {
var array = Array.prototype.slice.call(node);
for(var i = 0; i < array.length; i++) callback(array[i]);
}

each(document.querySelectorAll(":not(.syntaxhighlighter)>table"), function(element) {
element.classList.add("responsive");
});

var updateTables = function() {
if (document.documentElement.clientWidth < 767 && !switched) {
switched = true;
Expand All @@ -23,7 +13,13 @@
}
}

document.addEventListener("DOMContentLoaded", updateTables);
document.addEventListener("turbolinks:load", function() {
each(document.querySelectorAll(":not(.syntaxhighlighter)>table"), function(element) {
element.classList.add("responsive");
});
updateTables();
});

window.addEventListener("resize", updateTables);

var splitTable = function(original) {
Expand Down
6 changes: 6 additions & 0 deletions guides/assets/javascripts/turbolinks.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions guides/assets/stylesheets/style.css
Expand Up @@ -11,3 +11,4 @@ Import advanced style sheet

@import url("reset.css");
@import url("main.css");
@import url("turbolinks.css");
3 changes: 3 additions & 0 deletions guides/assets/stylesheets/turbolinks.css
@@ -0,0 +1,3 @@
.turbolinks-progress-bar {
background-color: #c52f24;
}
33 changes: 14 additions & 19 deletions guides/source/layout.html.erb
@@ -1,20 +1,19 @@
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>

<title><%= yield(:page_title) || 'Ruby on Rails Guides' %></title>
<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />

<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />

<link rel="stylesheet" type="text/css" href="stylesheets/fixes.css" />

<link href="images/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><%= yield(:page_title) || 'Ruby on Rails Guides' %></title>
<link rel="stylesheet" type="text/css" href="stylesheets/style.css" data-turbolinks-track="reload">
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print">
<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" data-turbolinks-track="reload">
<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" data-turbolinks-track="reload">
<link rel="stylesheet" type="text/css" href="stylesheets/fixes.css" data-turbolinks-track="reload">
<link href="images/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<script src="javascripts/syntaxhighlighter.js" data-turbolinks-track="reload"></script>
<script src="javascripts/turbolinks.js" data-turbolinks-track="reload"></script>
<script src="javascripts/guides.js" data-turbolinks-track="reload"></script>
<script src="javascripts/responsive-tables.js" data-turbolinks-track="reload"></script>
</head>
<body class="guide">
<% if @edge %>
Expand Down Expand Up @@ -122,9 +121,5 @@
<%= render 'license' %>
</div>
</div>

<script type="text/javascript" src="javascripts/syntaxhighlighter.js"></script>
<script type="text/javascript" src="javascripts/guides.js"></script>
<script type="text/javascript" src="javascripts/responsive-tables.js"></script>
</body>
</html>

0 comments on commit 53be013

Please sign in to comment.