hugo.soucy.cc

The personnal website source code of Hugo Soucy. Creates from an homebrewed static website generator (Ferron).
Log | Files | Refs

commit 27286a82dc8ae00784f8806168a5bc1b868b6aa1
parent 81da2cfe60e777692ee78fd738772df0b6392d12
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Sat, 30 Dec 2017 17:24:40 -0500

add function to set current section in the menu

Diffstat:
Mstatic/dst/js/script.js | 21+++++++++++++++++++++
Mstatic/dst/js/script.min.js | 1+
Mstatic/src/js/custom/init.js | 21+++++++++++++++++++++
3 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/static/dst/js/script.js b/static/dst/js/script.js @@ -454,4 +454,25 @@ function setNavigation() { } } +function setCurrentPage() { + 'use strict'; + var navLinks = document.querySelectorAll('.nav__link'); + var lengthOf; + var pathname; + + if (navLinks.item(0)) { + pathname = window.location.pathname; + lengthOf = navLinks.length; + + while(lengthOf--) { + var navLinkHref = navLinks[lengthOf].getAttribute('href'); + + if (navLinkHref.indexOf(pathname.split('/')[1]) > 0) { + navLinks[lengthOf].removeAttribute('href'); + } + } + } +} + setNavigation(); +//setCurrentPage(); diff --git a/static/dst/js/script.min.js b/static/dst/js/script.min.js @@ -29,4 +29,5 @@ function triggerCustomEvent(el,eventType,eventData){var customEvent;if(window.Cu el.dispatchEvent(customEvent);} function isElementInViewport(el){var elRect=el.getBoundingClientRect();return(elRect.top>=0&&elRect.left>=0&&elRect.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&elRect.right<=(window.innerWidth||document.documentElement.clientWidth));} return{doExtend:doExtend,queryAll:queryAll,setAttrs:setAttrs,setEvent:setEvent,setEventList:setEventList,getIndex:getIndex,getClosest:getClosest,getHeight:getHeight,setClass:setClass,unsetClass:unsetClass,hasClass:hasClass,toggleClass:toggleClass,setDebounce:setDebounce,setThrottle:setThrottle,isElement:isElement,isObject:isObject,triggerEvent:triggerEvent,triggerCustomEvent:triggerCustomEvent,isElementInViewport:isElementInViewport};})(window);function setNavigation(){'use strict';var $nav=document.querySelector('.nav');var visible='state--visible';var hidden='state--hidden';var $nav_panel;var $nav_button;var $nav_close;if(du.isElement($nav)){$nav_panel=$nav.querySelector('.nav__panel');document.body.insertAdjacentHTML('afterbegin',document.querySelector('#navButtonTpl').innerHTML);$nav_panel.insertAdjacentHTML('afterbegin',document.querySelector('#navCloseTpl').innerHTML);$nav_panel.insertAdjacentHTML('afterbegin',document.querySelector('#navTrapTpl').innerHTML);$nav_panel.insertAdjacentHTML('beforeend',document.querySelector('#navTrapTpl').innerHTML);$nav_button=document.querySelector('.nav-button');$nav_close=$nav_panel.querySelector('.nav__close');du.setClass($nav_panel,hidden);du.setEvent($nav_button,'click',function(thatEvt){thatEvt.preventDefault();du.toggleClass($nav_panel,hidden);du.toggleClass($nav_panel,visible);$nav_close.focus();});du.setEvent($nav_close,'click',function(thatEvt){thatEvt.preventDefault();du.toggleClass($nav_panel,hidden);du.toggleClass($nav_panel,visible);$nav_button.focus();});du.setEventList($nav_panel.querySelectorAll('.nav__trap'),'focus',function(){$nav_close.focus();});du.setEvent($nav_panel,'focus',function(){$nav_button.focus();});}} +function setCurrentPage(){'use strict';var navLinks=document.querySelectorAll('.nav__link');var lengthOf;var pathname;if(navLinks.item(0)){pathname=window.location.pathname;lengthOf=navLinks.length;while(lengthOf--){var navLinkHref=navLinks[lengthOf].getAttribute('href');if(navLinkHref.indexOf(pathname.split('/')[1])>0){navLinks[lengthOf].removeAttribute('href');}}}} setNavigation(); \ No newline at end of file diff --git a/static/src/js/custom/init.js b/static/src/js/custom/init.js @@ -64,4 +64,25 @@ function setNavigation() { } } +function setCurrentPage() { + 'use strict'; + var navLinks = document.querySelectorAll('.nav__link'); + var lengthOf; + var pathname; + + if (navLinks.item(0)) { + pathname = window.location.pathname; + lengthOf = navLinks.length; + + while(lengthOf--) { + var navLinkHref = navLinks[lengthOf].getAttribute('href'); + + if (navLinkHref.indexOf(pathname.split('/')[1]) > 0) { + navLinks[lengthOf].removeAttribute('href'); + } + } + } +} + setNavigation(); +//setCurrentPage();