5 lines
1.7 KiB
Plaintext
5 lines
1.7 KiB
Plaintext
/**
|
|
* Smooth scrollozas oldalon beluli navigaciora
|
|
* @see https://github.com/callmecavs/jump.js
|
|
*/
|
|
!function(e){var t=e.jump,n=e.attribute,r=n.replace(/-([a-z])/g,function(e){return e[1].toUpperCase()}),o=e.headerSelector;if(t&&"querySelector"in document&&"getComputedStyle"in window){var a,u,i=0,c="[data-"+n+"]",d=!1,f=function(e){return JSON.parse(e.dataset[r+"Options"]||"{}")},l={callback:function(){d=!1}},s=function(e,t){return!("up"==t&&v(e)>=0)&&!("down"==t&&v(e)<=0)},p=function(e){if(e.preventDefault(),!d){var n=e.target.closest(c),o=n.dataset[r],a=f(n);if(isNaN(o)){if(o=h(o,a.direction),!s(o,a.direction))return}else if(0===(o=parseInt(o)))return;d=!0,t(o,l)}},v=function(e){return Math.floor(e.getBoundingClientRect().top-i)},g=function(e){for(var t=0,n=e.length-1;t<=n;t++)if(v(e[t])>0)return e[t];return e[e.length-1]},m=function(e){for(var t=e.length-1;t>=0;t--)if(v(e[t])<0)return e[t];return e[0]},h=function(e,t){var n=document.querySelectorAll(e);return 0===n.length?document.querySelector("body"):1===n.length?n[0]:"up"==t?m(n):g(n)},y=function(e){if(!d){var n=e.keyCode||e.charCode;if(-1===["INPUT","TEXTAREA"].indexOf(e.target.tagName)){var r;switch(n){case 37:case 75:r="up";break;case 39:case 74:case 32:r="down"}if(r){e.preventDefault();var o=h(u,r);if(!s(o,r))return;d=!0,t(o,l)}}}},w=function(e){isNaN(e)&&!u&&(u=e,document.addEventListener("keydown",y))},a=function(){if(o){var e=document.querySelector(o);e&&(i=parseInt(window.getComputedStyle(e).height)||0,l.offset=-1*i)}for(var t=document.querySelectorAll(c),n=t.length-1;n>=0;n--)f(t[n]).keysEnabled&&w(t[n].dataset[r]),t[n].addEventListener("click",p,!1)};document.addEventListener("DOMContentLoaded",a,!1)}}({jump:window.Jump,attribute:"js-smoothscroll",headerSelector:".m-cf-fejlec"}); |