/*! * jQuery Nearest plugin v1.4.0 * * Finds elements closest to a single point based on screen location and pixel dimensions * http://gilmoreorless.github.io/jquery-nearest/ * Copyright (c) 2011-2015 Gilmore Davidson under the MIT licence: * http://gilmoreorless.github.io/jquery-nearest/LICENSE.txt * * Requires jQuery 1.4 or above * Also supports Ben Alman's "each2" plugin for faster looping (if available) */ !function(t,e){function r(e,r,o){e||(e="div");var s,a,h,u=t(r.container),c=u.offset()||{left:0,top:0},f=[u.width()||0,u.height()||0],d={x:[c.left,c.left+f[0]],y:[c.top,c.top+f[1]],w:[0,f[0]],h:[0,f[1]]},l=r.directionConstraints;for(s in d)d.hasOwnProperty(s)&&(h=i.exec(r[s]),h&&(a=d[s],r[s]=(a[1]-a[0])*h[1]/100+a[0]));t.isArray(l)||(l="string"==typeof l?[l]:[]),r.sameX===!1&&r.checkHoriz===!1&&(r.sameX=!r.checkHoriz),r.sameY===!1&&r.checkVert===!1&&(r.sameY=!r.checkVert);var y=u.find(e),p=[],x=!!r.furthest,m=!r.sameX,v=!r.sameY,g=!!r.onlyX,k=!!r.onlyY,w=x?0:1/0,X=parseFloat(r.x)||0,Y=parseFloat(r.y)||0,F=parseFloat(X+r.w)||X,S=parseFloat(Y+r.h)||Y,H={x1:X,y1:Y,x2:F,y2:S},M=parseFloat(r.tolerance)||0,b=!!t.fn.each2,j=Math.min,z=Math.max;!r.includeSelf&&o&&(y=y.not(o)),0>M&&(M=0),y[b?"each2":"each"](function(e,r){var i,o,s,a,h=b?r:t(this),u=h.offset(),c=u.left,f=u.top,d=h.outerWidth(),y=h.outerHeight(),C=c+d,O=f+y,P=z(c,X),V=j(C,F),W=z(f,Y),q=j(O,S),A={x1:c,y1:f,x2:C,y2:O},Q=V>=P,$=q>=W;(m&&v||!m&&!v&&Q&&$||m&&$||v&&Q||m&&g||v&&k)&&(i=Q?0:P-V,o=$?0:W-q,s=g||k?g?i:o:Q||$?z(i,o):Math.sqrt(i*i+o*o),a=x?s>=w-M:w+M>=s,n(H,A,l)||(a=!1),a&&(w=x?z(w,s):j(w,s),p.push({node:this,dist:s})))}),"nearest"===r.sort?p.sort(function(t,e){return t.dist-e.dist}):"furthest"===r.sort&&p.sort(function(t,e){return e.dist-t.dist});var C,O,P,V,W=p.length,q=[];if(W)for(x?(C=w-M,O=w):(C=w,O=w+M),P=0;W>P;P++)V=p[P],V.dist>=C&&V.dist<=O&&q.push(V.node);return q}function n(t,e,r){var n={left:t.x1>e.x1,right:t.x2e.y1,bottom:t.y2