Skip to content

Commit

Permalink
update anchor on specific link
Browse files Browse the repository at this point in the history
  • Loading branch information
kichik committed Nov 10, 2017
1 parent d9b65d3 commit 073fc3a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions index.html
Expand Up @@ -114,7 +114,9 @@ <h1><img src="python.png" width="64" height="64"> Why Python 3?</h1>
</button>
<ul class="dropdown-menu">
{% for post in site.posts %}
<li><a onclick="setSnippetBySlug('{{ post.slug }}')" href="#">{{ post.title }}</a></li>
<li><a class="snippet-link" data-slug="{{ post.slug }}" href="#{{ post.slug }}">
{{ post.title }}
</a></li>
{% endfor %}
</ul>
</div>
Expand Down Expand Up @@ -154,10 +156,6 @@ <h5 class="text-right"><strong id="title"></strong></h5>
setSnippet(snippets.eq(random));
}

function setSnippetBySlug(slug) {
setSnippet($('#' + slug));
}

function setSnippet(snippet) {
snippets.hide();
snippet.show();
Expand All @@ -175,6 +173,13 @@ <h5 class="text-right"><strong id="title"></strong></h5>
randomSnippet();
window.scrollTo(0, 0);
});

$(".snippet-link").click(function (ev) {
ev.preventDefault();
setSnippet($("#" + $(ev.target).data("slug")));
window.scrollTo(0, 0);
})

if (window.location.hash) {
var snippet = $(window.location.hash);
if (snippet.length > 0) {
Expand Down

0 comments on commit 073fc3a

Please sign in to comment.