Skip to content

Commit

Permalink
added hash support and go to hash on load
Browse files Browse the repository at this point in the history
  • Loading branch information
themarkappleby committed Sep 19, 2014
1 parent 446c3cf commit 89e1068
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ If you should want to tinker with Guidedog itself, you're more than welcome to.
- [DONE] ~~rename "example" to "html"~~
- [DONE] ~~turn Guidedog into a jQuery plugin~~
- [DONE] ~~pass an array of stylesheets to the Guidedog initializer~~
- [DONE] ~~hash support and go to hash on load~~
- add Less.js, Sass, Scss, and plain CSS examples
- add support for custom colour schemes (pass primary/secondary colours to initializer)
- re-write Guidedog stylesheet (use .gd- instead of .sg- prefixes)
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "guidedog",
"version": "0.1.7",
"version": "0.1.8",
"homepage": "https://github.com/themarkappleby/guidedog",
"authors": [
"Mark Appleby <themarkappleby@gmail.com>"
Expand Down
2 changes: 1 addition & 1 deletion dist/guidedog.min.js

Large diffs are not rendered by default.

19 changes: 13 additions & 6 deletions src/js/guidedog.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
$('.guidedog').each(function(){ $(this).css('background', '#'+Math.floor(Math.random()*16777215).toString(16)); });
syntaxHighlight();
updateNav();
scrollTo();
scrollToClick();
scrollTo(window.location.hash, 0);
initTabs();
$(document).on('scroll', function(){updateNav();});
if (typeof callback == 'function') {
Expand Down Expand Up @@ -128,16 +129,22 @@
});
}

// scrollto nav items
var scrollTo = function(){
// scrollToClick nav items
var scrollToClick = function(){
$('nav.sg').on('click', 'a', function(e){
e.preventDefault();
$('html, body').animate({
scrollTop: $($(this).attr('href')).offset().top - 30
}, 1000);
window.history.pushState('', '', $(this).attr('href'));
scrollTo($(this).attr('href'), 1000);
});
}

// scrollTo nav items
var scrollTo = function(target, speed){
$('html, body').animate({
scrollTop: $(target).offset().top - 30
}, speed);
}

// fetch the index of a section
var sectionIndex = function(match){
for (var i=0; i<gd.data.sections.length; i++){
Expand Down

0 comments on commit 89e1068

Please sign in to comment.