-
Notifications
You must be signed in to change notification settings - Fork 3
/
freefocus.min.js
1 lines (1 loc) · 3.62 KB
/
freefocus.min.js
1
!function(){"use strict";function a(a){if(!a)return console.error("Can't get freefocus dimensions for nothing"),{left:0,top:0,width:0,height:0};var b=l(a,!0,!1);return{left:b.x1,top:b.y1,width:b.x2-b.x1,height:b.y2-b.y1}}function b(a){return a?void l(a,!0,!0):void console.error("Can't populate freefocus cache for nothing")}function c(a){return a?void delete a.freefocusDimensions:void console.error("Can't invalidate freefocus cache for nothing")}function d(a){if(!a)return void console.error("Can't clear freefocus hint for nothing");for(var b in v)a.removeAttribute("data-nav-"+b)}function e(a,b,c){if(!a)return void console.error("Can't set freefocus hints for nothing");for(var d in b)c===!1&&a.getAttribute("data-nav-"+d)||a.setAttribute("data-nav-"+d,b[d])}function f(a,b,c){var d;if(!a)return console.error("Can't move freefocus from nothing"),d;if(!v[b])return console.error('Unknown freefocus direction "'+b+'"'),d;if(!c)return console.error("Can't move freefocus without candidates function"),d;p(a,b,x.cache);var e=g(a,b,c);if(e)if(e.length<=1)d=e[0];else{var f=function(){return e};d=h(a,b,f)}else d=h(a,b,c);return d&&q(d,b,x.cache),d}function g(a,b,c){var d=s(w,function(c){var d=c(a,b);return d&&d.trim()});return d&&(d=d.trim()),d?"none"===d?[]:s(d.split(/\s*;\s*/),function(a){if(a){var b=c(a);if(b.length)return b}}):void 0}function h(a,b,c){for(var d,e=m(l(a,x.cache,x.cache),b),f=c(),g=x.maxDistance,h=0,j=f.length;j>h;h++){var k=f[h];if(k!==a){var n=m(l(k,x.cache,x.cache),b);if(!(n.fwd1<e.fwd2)){var o=i(e,n);g>o&&(d=k,g=o)}}}return d}function i(a,b){var c,d=y.updatedInDirection,e={fwd:b.fwd1,ort:r(d.ort,b.ort1,b.ort2)},f=Math.abs(e.fwd-d.fwd),g=Math.abs(e.ort-d.ort);c=e.ort===d.ort?0:Math.sqrt(f*f+g*g);var h=j(a,b);return c+f+2*g-Math.sqrt(h)}function j(a,b){var c={ort1:a.ort1,ort2:a.ort2};b.ort1>c.ort1&&(c.ort1=b.ort1),b.ort2<c.ort2&&(c.ort2=b.ort2);var d=c.ort2-c.ort1;return 0>d&&(d=0),d}function k(a){var b=a.getBoundingClientRect();return{x1:b.left,y1:b.top,x2:b.right,y2:b.bottom}}function l(a,b,c){var d;return b&&(d=a.freefocusDimensions),d||(d=k(a)),c&&(a.freefocusDimensions=d),d}function m(a,b){var c=v[b].toUnified({x:a.x1,y:a.y1}),d=v[b].toUnified({x:a.x2,y:a.y2});return{fwd1:Math.min(c.fwd,d.fwd),ort1:Math.min(c.ort,d.ort),fwd2:Math.max(c.fwd,d.fwd),ort2:Math.max(c.ort,d.ort)}}function n(a,b){return{x:a.x+b.x1,y:a.y+b.y1}}function o(a,b){return{x:a.x-b.x1,y:a.y-b.y1}}function p(a,b,c){var d=l(a,c,c);a.freefocusId&&a.freefocusId===y.elementId||(y.elementId=t(a),y.box={x:(d.x2-d.x1)/2,y:(d.y2-d.y1)/2}),y.updatedInDirection=v[b].toUnified(n(y.box,d)),y.updatedInDirection.fwd=m(d,b).fwd2}function q(a,b,c){var d=l(a,c,c);y.elementId=t(a);var e=m(d,b),f={fwd:e.fwd1,ort:r(y.updatedInDirection.ort,e.ort1,e.ort2)};y.box=o(v[b].fromUnified(f),d)}function r(a,b,c){return Math.min(Math.max(a,b),c)}function s(a,b){for(var c=0,d=a.length;d>c;c++){var e=b(a[c]);if(e)return e}}function t(a){var b=a.freefocusId;return b||(b=a.freefocusId=++z),b}var u=window.freefocus={move:f,getDimensions:a,populateDimensionsCache:b,invalidateDimensionsCache:c,setHint:e,clearHint:d,configuration:void 0},v={left:{toUnified:function(a){return{fwd:-a.x,ort:-a.y}},fromUnified:function(a){return{x:-a.fwd,y:-a.ort}}},right:{toUnified:function(a){return{fwd:a.x,ort:a.y}},fromUnified:function(a){return{x:a.fwd,y:a.ort}}},up:{toUnified:function(a){return{fwd:-a.y,ort:a.x}},fromUnified:function(a){return{x:a.ort,y:-a.fwd}}},down:{toUnified:function(a){return{fwd:a.y,ort:-a.x}},fromUnified:function(a){return{x:-a.ort,y:a.fwd}}}},w=[function(a,b){return a.getAttribute("data-nav-"+b)}],x=u.configuration={maxDistance:1/0,cache:!1,directions:v,hintSources:w},y={freefocusId:-1},z=0}();