Skip to content

Commit

Permalink
fix(styleguide): Scroll to correct position from top level nav
Browse files Browse the repository at this point in the history
[#80392096]

Signed-off-by: Nicole Sullivan <nsullivan@pivotal.io>
  • Loading branch information
bebepeng committed Oct 15, 2014
1 parent 6406d79 commit bf97096
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 27 deletions.
6 changes: 3 additions & 3 deletions hologram/doc_assets/_header.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
<% @pages[file_name][:blocks].each do |b| %>
<% if (b[:categories].include?(category_name)) && (b[:parent] == nil) %>
<% if file_name == @file_name %>
<li><a href="?target=<%= b[:name] %>" class="styleguide-subsection"><%= b[:title] %></a></li>
<li><a href="#<%= b[:name] %>" class="styleguide-subsection"><%= b[:title] %></a></li>
<% else %>
<li><a href="<%= file_name %>?target=<%= b[:name] %>"><%= b[:title] %></a></li>
<li><a href="<%= file_name %>#<%= b[:name] %>"><%= b[:title] %></a></li>
<% end %>
<% end %>
<% end %>
Expand All @@ -38,6 +38,6 @@
</ul>
</div>
</nav>
<div class="container mtxxl ptl">
<div class="container ptl">
<section class="content">

28 changes: 4 additions & 24 deletions src/style_guide/style_guide.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
// jquery plugin from: http://css-tricks.com/snippets/jquery/get-query-params-object/
jQuery.extend({
getQueryParameters : function(str) {
return (str || document.location.search).replace(/(^\?)/,'').split("&").map(function(n){return n = n.split("="),this[n[0]] = n[1],this}.bind({}))[0];
}
});

/* Stylesheet swappin */
$(document).ready(function(){
$('input.alternate-css').change(function() {
Expand All @@ -19,15 +12,12 @@ $(document).ready(function(){
});

/* Adjust scrollTop when navigating to a subsection on the current page */

$(document).ready(function() {
var headerHeight = 50;
$('a.styleguide-subsection').on('click', function(e) {
var queryString = e.target.href.slice(e.target.href.indexOf('?'));
window.history.pushState('', '', queryString);
e.preventDefault();

var $target = $('#' + $.getQueryParameters(queryString).target);
var desiredScrollPosition = $target.offset().top - headerHeight;
var $target = $(e.target.hash);
var desiredScrollPosition = $target.offset().top;
window.history.pushState('', '', e.target.hash);
$('body, html').animate({
scrollTop: desiredScrollPosition
}, 500, function () {
Expand All @@ -36,13 +26,3 @@ $(document).ready(function() {
return false;
});
});

/* Adjust scrollTop when navigating to a subsection on a different page */
$(document).ready (function() {
if ($.getQueryParameters().target) {
$target = $('#' + $.getQueryParameters().target);
var newScrollTop = $target.offset().top - 50;
$(window).scrollTop(newScrollTop);
}
});

3 changes: 3 additions & 0 deletions src/style_guide/style_guide.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ h5.styleguide,
h6.styleguide {
color: $brand-3;
font-weight: 600;
margin-top: 0;
padding-top: 50px;
}

h1.styleguide {
Expand Down Expand Up @@ -258,6 +260,7 @@ table.styleguide {
padding: 7px;
border: 1px solid #ccc;
width: 100%;
margin-bottom: 12px;

tr, th, td {
padding: 7px;
Expand Down

0 comments on commit bf97096

Please sign in to comment.