From b7c8f80d9a040b4f9ab49e24743a89d2767dfdac Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Fri, 16 Dec 2016 19:36:44 +0000 Subject: [PATCH] Make nav title scroll or go home --- static/src/js/app.js | 14 ++++++++++- static/src/js/consts.js | 3 +++ static/src/js/creative/creative.js | 37 ---------------------------- static/src/js/creative/index.js | 39 +++++++++++++++++++++++++++++- templates/common/navbar.html | 2 +- 5 files changed, 55 insertions(+), 40 deletions(-) create mode 100644 static/src/js/consts.js delete mode 100644 static/src/js/creative/creative.js diff --git a/static/src/js/app.js b/static/src/js/app.js index adfebec..fd70645 100644 --- a/static/src/js/app.js +++ b/static/src/js/app.js @@ -1,6 +1,6 @@ import './creative'; import ansi_up from 'ansi_up'; - +import { SCROLL_SPEED } from './consts'; $('.image').each(function () { // setup div-image hybrids const ele = $(this); @@ -15,3 +15,15 @@ $('.ansi-up').each(function () { const ele = $(this); ele.html(ansi_up.ansi_to_html(ele.html())); }); + + +$('.navbar-brand').bind('click', function (event) { + if ($('html').scrollTop() > NAVBAR_HEIGHT) { + $('html, body').stop().animate({ + scrollTop: 0 + }, SCROLL_SPEED); + } else { + window.location = '/'; + } + event.preventDefault(); +}); diff --git a/static/src/js/consts.js b/static/src/js/consts.js new file mode 100644 index 0000000..4688da7 --- /dev/null +++ b/static/src/js/consts.js @@ -0,0 +1,3 @@ +export const NAVBAR_HEIGHT = $('#main-nav').height(); + +export const SCROLL_SPEED = 750; diff --git a/static/src/js/creative/creative.js b/static/src/js/creative/creative.js deleted file mode 100644 index 07b7145..0000000 --- a/static/src/js/creative/creative.js +++ /dev/null @@ -1,37 +0,0 @@ -/*! - * Start Bootstrap - Creative Bootstrap Theme (http://startbootstrap.com) - * Code licensed under the Apache License v2.0. - * For details, see http://www.apache.org/licenses/LICENSE-2.0. - * (Edited for theorangeone.net) - */ - -const NAVBAR_HEIGHT = $('#main-nav').height(); - -$('a.page-scroll').bind('click', function(event) { - const anchor = $(this); - $('html, body').stop().animate( - { - scrollTop: ($(anchor.attr('href')).offset().top - NAVBAR_HEIGHT) - }, - 750 - ); - event.preventDefault(); -}); - -// Highlight the top nav as scrolling occurs -$('body').scrollspy({ - target: '.navbar-fixed-top', - offset: NAVBAR_HEIGHT + 1 -}); - -// Closes the Responsive Menu on Menu Item Click -$('.navbar-collapse ul li a').click(function() { - $('.navbar-toggle:visible').click(); -}); - -// Offset for Main Navigation -$('#main-nav').affix({ - offset: { - top: NAVBAR_HEIGHT * 1.5 - } -}); diff --git a/static/src/js/creative/index.js b/static/src/js/creative/index.js index 0df842a..c956c43 100644 --- a/static/src/js/creative/index.js +++ b/static/src/js/creative/index.js @@ -1,4 +1,41 @@ -import './creative'; import WOW from 'wow.js'; +import { NAVBAR_HEIGHT, SCROLL_SPEED } from '../consts'; new WOW().init(); + +/*! + * Start Bootstrap - Creative Bootstrap Theme (http://startbootstrap.com) + * Code licensed under the Apache License v2.0. + * For details, see http://www.apache.org/licenses/LICENSE-2.0. + * (Edited for theorangeone.net) + */ + + + +$('a.page-scroll').bind('click', function(event) { + const anchor = $(this); + $('html, body').stop().animate( + { scrollTop: ($(anchor.attr('href')).offset().top - NAVBAR_HEIGHT) }, + SCROLL_SPEED + ); + event.preventDefault(); +}); + + +// Highlight the top nav as scrolling occurs +$('body').scrollspy({ + target: '.navbar-fixed-top', + offset: NAVBAR_HEIGHT + 1 +}); + +// Closes the Responsive Menu on Menu Item Click +$('.navbar-collapse ul li a').click(function() { + $('.navbar-toggle:visible').click(); +}); + +// Offset for Main Navigation +$('#main-nav').affix({ + offset: { + top: NAVBAR_HEIGHT * 1.5 + } +}); diff --git a/templates/common/navbar.html b/templates/common/navbar.html index 1c49a12..5fe484a 100644 --- a/templates/common/navbar.html +++ b/templates/common/navbar.html @@ -7,7 +7,7 @@ - + {{ django_settings.WAGTAIL_SITE_NAME }}