/** * koglossarylinks - KOglossaryLinks is a jQuery plugin that shows glossary-style tooltips when hovered (or tapped on touchscreen devices) * @version v0.4.0 * @link https://github.com/mrmartineau/KOglossaryLinks * @license MIT */ !function(t){var o=function(){var o=this;o.tooltipClass="KOglossaryLinkTooltip",o.element="[data-koglossarylink]",o.options={sourceURL:"",tooltipwidth:260,debug:!1},o.init=function(s,i){return o.options=t.extend(o.options,i),o.el=s,o.overEvent=o.supportsTouch()?"click":"mouseover",o.terms={},o.options.debug&&console.log("_.options",o.options),t.getJSON(o.options.sourceURL).then(function(t){for(var s=t,i=0;i':"",l=o.supportsTouch()?o.tooltipClass+"-title "+o.tooltipClass+"-title--touch":o.tooltipClass+"-title";if(t(this).parent("."+o.tooltipClass).hasClass("is-visible"))t(this).parent("."+o.tooltipClass).removeClass("is-visible");else{if(i)return t(this).find("."+o.tooltipClass).addClass("is-visible"),void o.positionTooltip(t(this));if(void 0!==o.terms[e]){var a='

'+o.terms[e].term+'

'+o.terms[e].description+"
"+n+'
';t(this).wrap("").append(a),t(this).find("."+o.tooltipClass).addClass("is-visible"),o.positionTooltip(t(this))}else o.options.debug&&console.log("No term found")}}),o.el.on("mouseout",o.element,function(){t(this).find("."+o.tooltipClass).removeClass("is-visible")}),o.el.on("click",o.element+" ."+o.tooltipClass+"-close",function(s){s.preventDefault(),s.stopPropagation(),t(this).parent("."+o.tooltipClass).removeClass("is-visible")}),t(window).resize(o.positionTooltip(o.el.find(o.element))),o},o.positionTooltip=function(s){if(void 0!==s.offset()){var i,e,n,l=parseInt(s.offset().left,10),a=s.width(),r=parseInt(l+a/2,10),p=t(window).width(),c=o.options.tooltipwidth/2,d=s.find("."+o.tooltipClass),f=s.find("."+o.tooltipClass+"-triangle");r+c>p?(i=parseInt(r+c-p+20,10),e=parseInt(c+i/2+20,10),n=parseInt(10+i/2,10),o.options.debug&&console.log("El is floating off right side:","\nwindow width",p,"\nelcentrepoint",r,"\ndifference",i,"\nnewtooltipcentre",e,"\nnewarrowcentre",n),d.css({marginLeft:"-"+e+"px"}),f.css({marginLeft:n+"px"})):0>r-c?(i=parseInt(r,10),e=i-20,n=c-10-(i-40),o.options.debug&&console.log("El is floating off left side:","\nwindow width",p,"\nelcentrepoint",r,"\ndifference",i,"\nnewtooltipcentre",e,"\nnewarrowcentre",n),d.css({marginLeft:"-"+e+"px"}),f.css({marginLeft:"-"+n+"px"})):(d.css({marginLeft:"-"+c+"px"}),f.css({marginLeft:"-10px"}))}},o.supportsTouch=function(){return"ontouchstart"in document.documentElement||(window.DocumentTouch&&document instanceof DocumentTouch||navigator.msMaxTouchPoints?!0:!1)}};t.fn.KOglossaryLinks=function(s){var i=this.length;return this.each(function(e){var n=t(this),l="KOglossaryLinks"+(i>1?"-"+ ++e:""),a=(new o).init(n,s);n.data(l,a).data("key",l)})},o.version="0.4.0"}(jQuery,!1);