/*
 * Jatt - just another tooltip v2.8.4 min
 * https://github.com/Mottie/Jatt
 * by Rob Garrison (aka Mottie)
 *
 * based on tooltip by Alen Grakalic (https://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery)
 * tooltip modification by Rob G, aka Mottie (https://wowmotty.blogspot.com/)
 *
 */

(function(b,v,t){b.jatt=function(w){var g,r,s=[],u=b("body"),e=b(t),q=b(v),d=b.extend({},b.jatt.defaultOptions,w);b.jatt.ttrelocate=function(g,j){var l=b("#"+j),a=l.outerWidth(),f=l.outerHeight(),c=l.data("options")||d,n={e:[c.xOffset,-f/2,a+c.xOffset,f/2],se:[c.xOffset,c.yOffset,a+c.xOffset,f+c.yOffset],s:[-a/2,c.yOffset,a/2,f+c.yOffset],sw:[-a-c.xOffset,c.yOffset,-c.xOffset,f+c.yOffset],w:[-a-c.xOffset,-f/2,-c.xOffset,f/2],nw:[-a-c.xOffset,-f-c.yOffset,-c.xOffset,-c.yOffset],n:[-a/2,-f-c.yOffset, a/2,-c.yOffset],ne:[c.xOffset,-f-c.yOffset,a+c.xOffset,-c.yOffset]}[c.direction],m=q.scrollTop(),e=q.scrollLeft(),i=b(g.target),h=g.pageX||i.position().left+i.width()/2,k=g.pageY||i.position().top+i.height()/2;c.followMouse||(h=i.outerWidth(),k=i.outerHeight(),k={e:[h,k/2],se:[h,k],s:[h/2,k],sw:[0,k],w:[0,k/2],nw:[0,0],n:[h/2,0],ne:[h,0]},h=i.offset().left+k[c.direction][0],k=i.offset().top+k[c.direction][1]);var i=h+n[0],o=k+n[1];h+n[2]>e+q.width()-c.xOffset&&(i=q.width()-a-c.xOffset);k+n[3]>m+q.height()- c.yOffset&&(o=k-f-c.yOffset);i<e+c.xOffset&&(i=e+c.xOffset);o<m+c.yOffset&&(o=k+c.yOffset);h>i&&h<i+a&&k>o&&k<o+f&&(o+=o-f/2-c.yOffset<m+c.yOffset?f/2+c.yOffset:-f/2-c.yOffset);l.css({left:i+"px",top:o+"px"})};b.jatt.getMeta=function(e){g=b.extend({},d);var j,l=[],a=e.attr(d.metadata)||"",a=a.match(/(\{.*\})/g)?a.match(/(\{.*\})/g)[0]:e.attr(d.metadata)||"",a=a.match("width|background|color|border|direction|followMouse|content|speed|local|xOffset|yOffset|zIndex")?a:e.attr("data-jatt")||"";""!==a&& (a=a.replace(/(\{|\'|\"|\})/g,""),a.match("direction|followMouse|content|speed|local|xOffset|yOffset|zIndex")&&(b.each(a.split(";"),function(a,c){j=c.split(":");if(j[0].match("direction|followMouse|content|speed|local|xOffset|yOffset|zIndex")){var d=b.trim(j[0]),e=b.trim(j[1]);g[d]="true"==e||"false"==e?"true"==e?!0:!1:isNaN(e)?e:parseFloat(e)}else l.push(c)}),a=l.join(";")));return[g,a]};b.jatt.removeTooltips=function(){var g=b("#"+d.previewId+", #"+d.tooltipId);g.length&&(g.remove(),e.trigger("hidden.jatt", b.data(e,"jatt")));for(;0<b("#"+d.previewId+", #"+d.tooltipId).length;)b("#"+d.previewId+", #"+d.tooltipId).remove()};b.jatt.preloadContent=function(g){var e,l,a,f,c,n=[],m=b(d.tooltip);for(c=g.length;-1<c;c--)e=t.createElement("img"),e.src=g[c],s.push(e);m.each(function(c){l=b(this);"A"===this.tagName&&l.is(d.preloadContent)&&(f=b(this).attr("href")||"",""!==f&&!f.match(/^#/)&&(a=b('<div rel="'+c+'" />'),n.push(a),a.load(f,function(){m.eq(a.attr("rel")).data("tooltip",a.html())})))})};(function(){var p= d.live?"live":"bind",j=[];b.each("initialized.jatt beforeReveal.jatt revealed.jatt hidden.jatt".split(" "),function(g,a){var f=a.split(".")[0];b.isFunction(d[f])&&e.bind(a,d[f])});b.data(e,"jatt","");b(d.tooltip)[p](d.activate,function(l){var a,f,c,n,m,j,i,h=b(this);a="false"===d.metadata.toString()?[d,""]:b.jatt.getMeta(h);this!==b.data(e,"jatt")[0]&&b.jatt.removeTooltips();e.trigger("initialized.jatt",h);g=a[0];f=""===h.attr(g.content)?h.data("tooltip")||"":h.attr(g.content)||"";n=h.attr("rel")|| "";m=h.attr("href")||"";h.data("tooltip",f);h.attr("title","");a='<div id="'+d.tooltipId+'" style="position:absolute;z-index:'+g.zIndex+";"+a[1]+'"><span class="body"></span><span class="close">x</span></div>';g.local?h.before(a):u.append(a);c=b("#"+d.tooltipId);if(""===f)if(""!==n)f=b(n).html()||d.notFound;else if(""!==m&&"#"!==m)f=d.loading,j=b("<div />"),j.load(m,function(){i=j.html();s=d.cacheData?i:"";c.hide().find(".body").html(i);h.data("tooltip",s);b.jatt.ttrelocate(l,d.tooltipId);c.fadeIn(g.speed)}); c.data("options",g).find(".body").html(f);b.jatt.ttrelocate(l,d.tooltipId);c.find(".close")[h.is(d.sticky)?"show":"hide"]().click(function(){b.jatt.removeTooltips()});b.data(e,"jatt",h);e.trigger("beforeReveal.jatt",h);c.fadeIn(g.speed);e.trigger("revealed.jatt",h)})[p](d.deactivate,function(){b(this).is(d.sticky)||b.jatt.removeTooltips()})[p]("mousemove",function(e){b("#"+d.tooltipId).length&&g.followMouse&&b.jatt.ttrelocate(e,d.tooltipId)});r=function(l,a,f){e.trigger("initialized.jatt",a);var c, j="false"==d.metadata.toString()?[d,""]:b.jatt.getMeta(a);g=j[0];c=""===a.attr(g.content)?a.data("tooltip")||"":a.attr(g.content)||"";a.data("tooltip",c);"title"===g.content&&a.attr(g.content,"");f='<div id="'+d.previewId+'" style="position:absolute;z-index:'+g.zIndex+";"+j[1]+'"><span class="body"><img src="'+f+(""!==c?"<br/>"+c:"")+'</span><span class="close">x</span></div>';g.local?a.before(f):u.append(f);f=b("#"+d.previewId);b.data(e,"jatt",a);e.trigger("beforeReveal.jatt",a);f.hide().data("options", g).fadeIn(g.speed);f.find(".close")[a.is(d.sticky)?"show":"hide"]().click(function(){b.jatt.removeTooltips()});b.jatt.ttrelocate(l,d.previewId);e.trigger("revealed.jatt",a)};b(d.preview)[p](d.activate,function(e){var a=b(this);b.jatt.removeTooltips();r(e,a,a.attr("href")+'" alt="'+d.imagePreview+'" />')}).each(function(){j.push(b(this).attr("href"))});b(d.screenshot)[p](d.activate,function(e){var a=b(this),f=("#"===a.attr("rel")?d.websitePreview+a.attr("href"):a.attr("rel"))+'" alt="'+d.siteScreenshot+ a.attr("href")+'" />';b.jatt.removeTooltips();r(e,a,f)}).each(function(){var e=b(this);j.push("#"===e.attr("rel")?d.websitePreview+e.attr("href"):e.attr("rel"))});b(d.preview+","+d.screenshot)[p](d.deactivate,function(){b(this).is(d.sticky)||b.jatt.removeTooltips()})[p]("mousemove",function(e){b("#"+d.previewId).length&&g.followMouse&&b.jatt.ttrelocate(e,d.previewId)});b.jatt.preloadContent(j)})()};b.jatt.defaultOptions={direction:"n",followMouse:!0,content:"title",speed:300,local:!1,xOffset:20,yOffset:20, zIndex:1E3,live:!1,metadata:"class",activate:"mouseenter focusin",deactivate:"mouseleave focusout",cacheData:!0,websitePreview:"https://api1.thumbalizr.com/?width=250&url=",loading:"Loading...",notFound:"No tooltip found",imagePreview:"Image preview",siteScreenshot:"URL preview: ",tooltip:".tooltip",screenshot:"a.screenshot",preview:"a.preview",preloadContent:".preload",sticky:".sticky",tooltipId:"tooltip",previewId:"preview"}})(jQuery,this,document);
