Skip to content

Commit

Permalink
added topbar for mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
wookay committed Mar 21, 2017
1 parent bd134c5 commit d868862
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 33 deletions.
112 changes: 92 additions & 20 deletions assets/html/documenter.css
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ nav.toc {
box-shadow: inset -14px 0px 5px -12px rgb(210,210,210);
}

nav.toc.off {
display: none;
}

nav.toc .logo {
margin: 0 auto;
display: block;
Expand Down Expand Up @@ -241,6 +237,10 @@ nav.toc li.current > .toctext {
background-color: white;
}

div.topbar {
display: none;
}

article {
margin-left: 20em;
min-width: 20em;
Expand All @@ -262,24 +262,15 @@ article > header nav li {
padding-right: 0.2em;
}

article > header nav ul.float-left li:before {
article > header nav li:before {
content: "»";
padding-right: 0.2em;
}

article > header nav ul.float-right {
article > header .edit-page {
float: right;
}

article > header nav ul.float-right a.btn {
display: none;
}

article > header nav ul.float-right i.fa-bars {
text-align: center;
width: 3em;
}

article > footer {}

article > footer a.prev {
Expand Down Expand Up @@ -415,16 +406,97 @@ article section.docstring a.source-link {
padding: 0;
}

@media only screen and (min-width: 320px) and (max-width: 768px) {
@media only screen and (max-width: 768px) {
div.topbar {
display: block; /* is mobile */
position: fixed;
top: 0px;
left: 0px;
right: 0px;
height: 2.5em;
overflow: hidden;
background-color: white;
box-shadow: 0 2px 2px 0 rgba(0,0,0,.14),
0 1px 5px 0 rgba(0,0,0,.12),
0 3px 1px -2px rgba(0,0,0,.2);
z-index: 1;
}

div.topbar div.container {
height: 100%;
width: 100vw;
}

div.topbar ul {
font-weight: bold;
line-height: 2.5em;
list-style: none;
}

div.topbar ul.float-left {
float: left;
font-size: smaller;
width: 60%;
padding-left: 1em;
margin-top: 0.3em;
}

div.topbar ul.float-left li {
white-space: nowrap;
display: inline-block;
}

div.topbar ul.float-right {
float: right;
padding: 0 0 0 0;
margin-top: 0.1em;
}

div.topbar ul.float-right i.fa-bars {
width: 1em;
padding-left: 0.5em;
padding-right: 0.5em;
text-align: right;
font-size: x-large;
background-color: white;
}

div.main div.container {
margin-top: 1em;
}

nav.toc {
position: relative;
position: fixed;
overflow-y: scroll;
z-index: 2;
width: 80%;
-webkit-overflow-scrolling: touch;
-webkit-transition-property: left; /* Safari */
-webkit-transition-duration: 0.3s; /* Safari */
transition-property: left;
transition-duration: 0.3s;
left: -768px;
-webkit-transition-timing-function: ease-in; /* Safari */
transition-timing-function: ease-in;
}

nav.toc.show {
left: 0rem;
-webkit-transition-timing-function: ease-out; /* Safari */
transition-timing-function: ease-out;
}

article {
margin-left: 0em;
padding-top: -3em;
padding-left: 0.9em;
padding-right: 0.9em;
margin-left: 0;
}

article ul.float-right a.btn {
display: block !important;
article [id]:before {
display: inline-block;
content: "";
padding-top: 5em;
margin-top: -5em;
}
}
16 changes: 11 additions & 5 deletions assets/html/documenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,17 @@ require(['jquery', 'highlight', 'highlight-julia'], function($, hljs) {
}
hljs.initHighlighting();

if ($("nav.toc").css('position') == 'relative') {
$("nav.toc").toggleClass('off')
}
$("article ul.float-right a.btn").click(function() {
$("nav.toc").toggleClass('off')
// mobile
var navtoc = $("nav.toc");
var navtoc_current_top = $('nav.toc li.current').offset().top;
$("nav.toc li.current a.toctext").click(function(ev) {
navtoc.toggleClass('show');
});
$("div.topbar ul.float-right a.btn").click(function() {
navtoc.toggleClass('show');
if (navtoc.hasClass('show')) {
navtoc.animate({scrollTop: navtoc_current_top}, 0);
}
});
})

Expand Down
29 changes: 21 additions & 8 deletions src/Writers/HTMLWriter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,19 @@ end
Constructs and writes the page referred to by the `navnode` to `.build`.
"""
function render_page(ctx, navnode)
@tags html body
@tags html body div

page = getpage(ctx, navnode)

head = render_head(ctx, navnode)
topbar = render_topbar(ctx, navnode)
navmenu = render_navmenu(ctx, navnode)
article = render_article(ctx, navnode)

htmldoc = DOM.HTMLDocument(
html[:lang=>"en"](
head,
body(navmenu, article)
body(topbar, div[".main"](div[".container"](navmenu, article)))
)
)
open(Formats.extension(:html, page.build), "w") do io
Expand Down Expand Up @@ -262,6 +263,20 @@ function render_search(ctx)
end
end


# topbar for mobile
# ------------------------------------------------------------------------------

function render_topbar(ctx, navnode)
@tags div ul li span a i

page_title = string(mdflatten(pagetitle(ctx, navnode)))
topbarleft = ul[".float-left"](li(span(page_title)))
topbarright = ul[".float-right"](li(a[".btn", :href => "#"](i[".fa .fa-bars", Symbol("aria-hidden") => "true"])))
div[".topbar"](div[".container"](topbarleft, topbarright))
end


# Navigation menu
# ------------------------------------------------------------------------------

Expand Down Expand Up @@ -360,20 +375,18 @@ end
# ------------------------------------------------------------------------------

function render_article(ctx, navnode)
@tags article header footer nav ul li hr span a i
@tags article header footer nav ul li hr span a

header_links = map(Documents.navpath(navnode)) do nn
title = mdconvert(pagetitle(ctx, nn))
isnull(nn.page) ? li(title) : li(a[:href => navhref(nn, navnode)](title))
end

topnavleft = ul[".float-left"](header_links)
topnavright = ul[".float-right"]
topnav = nav(ul(header_links))
Utilities.unwrap(Utilities.url(ctx.doc.user.repo, getpage(ctx, navnode).source)) do url
push!(topnavright.nodes, li(a[".edit-page", :href => url](span[".fa"]("\uf09b"), " Edit on GitHub")))
push!(topnav.nodes, a[".edit-page", :href => url](span[".fa"]("\uf09b"), " Edit on GitHub"))
end
push!(topnavright.nodes, li(a[".btn", :href => "#"](i[".fa .fa-bars", Symbol("aria-hidden") => "true"])))
art_header = header(nav(topnavleft, topnavright), hr())
art_header = header(topnav, hr())

# build the footer with nav links
art_footer = footer(hr())
Expand Down

0 comments on commit d868862

Please sign in to comment.