Titan/webapp/titanembeds/static/js/vendor/jquery.balloon.min.js

11 lines
7.4 KiB
JavaScript
Raw Permalink Normal View History

2018-02-22 12:43:35 +01:00
/**
* Hover balloon on elements without css and images.
*
* Copyright (c) 2011 Hayato Takenaka
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
* @author: Hayato Takenaka (https://urin.github.io)
* @version: 1.1.2 - 2017/04/30
**/
!function(a){function c(){this.initialize.apply(this,arguments)}function d(d,e,f){function p(a,b,c,d,e,f){const g=Math.round(d/1.7320508);b.inactive()["setBorder"+c.camel.pos.f](d)["setBorder"+c.camel.pos.c1](g)["setBorder"+c.camel.pos.c2](g)["set"+c.camel.pos.p1](c.isTopLeft?-d:a.inner[c.size.p])["set"+c.camel.pos.c1](a.inner[c.size.c]/f-g).active().$.css("border-"+c.pos.f+"-color",e)}e.stop(!0,!0);var g,h;const i={position:"absolute",height:"0",width:"0",border:"solid 0 transparent"},j=new c(d),k=new c(e),l=-f.offsetY+(f.position&&f.position.indexOf("top")>=0?j.top-k.height:f.position&&f.position.indexOf("bottom")>=0?j.bottom:j.center.top-k.height/2),m=f.offsetX+(f.position&&f.position.indexOf("left")>=0?j.left-k.width:f.position&&f.position.indexOf("right")>=0?j.right:j.center.left-k.width/2);if(k.setTop(l<0?0:l),k.setLeft(m<0?0:m),f.tipSize>0){e.data("outerTip")&&(e.data("outerTip").remove(),e.removeData("outerTip")),e.data("innerTip")&&(e.data("innerTip").remove(),e.removeData("innerTip")),g=new c(a("<div>").css(i).appendTo(e)),h=new c(a("<div>").css(i).appendTo(e));for(var n,o=0;o<b.pos.length;o++){if(n=b.getRelativeNames(o),k.center[n.pos.c1]>=j[n.pos.c1]&&k.center[n.pos.c1]<=j[n.pos.c2])if(o%2==0){if(k[n.pos.o]>=j[n.pos.o]&&k[n.pos.f]>=j[n.pos.f])break}else if(k[n.pos.o]<=j[n.pos.o]&&k[n.pos.f]<=j[n.pos.f])break;n=null}n?(k["set"+n.camel.pos.p1](k[n.pos.p1]+(n.isTopLeft?1:-1)*(f.tipSize-k["border"+n.camel.pos.o])),p(k,g,n,f.tipSize,e.css("border-"+n.pos.o+"-color"),f.tipPosition),p(k,h,n,f.tipSize-2*k["border"+n.camel.pos.o],e.css("background-color"),f.tipPosition),e.data("outerTip",g.$).data("innerTip",h.$)):a.each([g.$,h.$],function(){this.remove()})}}function e(b,c){const d=b.data("balloon")&&b.data("balloon").get(0);return!(d&&(d===c.relatedTarget||a.contains(d,c.relatedTarget)))}function f(a,b,c){b.html?a.empty().append(c):a.text(c)}function g(a,b,c){b.data("ajaxDisabled",!0),c.ajaxContentsMaxAge>=0&&setTimeout(function(){b.data("ajaxDisabled",!1)},c.ajaxContentsMaxAge),d(a,b,c)}const b={pos:a.extend(["top","bottom","left","right"],{camel:["Top","Bottom","Left","Right"]}),size:a.extend(["height","width"],{camel:["Height","Width"]}),getRelativeNames:function(a){const c={pos:{o:a,f:a%2==0?a+1:a-1,p1:a%2==0?a:a-1,p2:a%2==0?a+1:a,c1:a<2?2:0,c2:a<2?3:1},size:{p:a<2?0:1,c:a<2?1:0}},d={};for(var e in c){d[e]||(d[e]={});for(var f in c[e])d[e][f]=b[e][c[e][f]],d.camel||(d.camel={}),d.camel[e]||(d.camel[e]={}),d.camel[e][f]=b[e].camel[c[e][f]]}return d.isTopLeft=d.pos.o===d.pos.p1,d}};!function(){function f(a,c){if(null==c)return f(a,!0),f(a,!1);const d=b.getRelativeNames(c?0:2);return a[d.size.p]=a.$["outer"+d.camel.size.p](),a[d.pos.f]=a[d.pos.o]+a[d.size.p],a.center[d.pos.o]=a[d.pos.o]+a[d.size.p]/2,a.inner[d.pos.o]=a[d.pos.o]+a["border"+d.camel.pos.o],a.inner[d.size.p]=a.$["inner"+d.camel.size.p](),a.inner[d.pos.f]=a.inner[d.pos.o]+a.inner[d.size.p],a.inner.center[d.pos.o]=a.inner[d.pos.f]+a.inner[d.size.p]/2,a}const d={setBorder:function(a,b){return function(c){return this.$.css("border-"+a.toLowerCase()+"-width",c+"px"),this["border"+a]=c,this.isActive?f(this,b):this}},setPosition:function(a,b){return function(c){return this.$.css(a.toLowerCase(),c+"px"),this[a.toLowerCase()]=c,this.isActive?f(this,b):this}}};c.prototype={initialize:function(c){this.$=c,a.extend(!0,this,this.$.offset(),{center:{},inner:{center:{}}});for(var d=0;d<b.pos.length;d++)this["border"+b.pos.camel[d]]=parseInt(this.$.css("border-"+b.pos[d]+"-width"))||0;this.active()},active:function(){return this.isActive=!0,f(this),this},inactive:function(){return this.isActive=!1,this}};for(var e=0;e<b.pos.length;e++)c.prototype["setBorder"+b.pos.camel[e]]=d.setBorder(b.pos.camel[e],e<2),e%2==0&&(c.prototype["set"+b.pos.camel[e]]=d.setPosition(b.pos.camel[e],e<2))}(),a.fn.balloon=function(b){return this.one("mouseenter",function c(d){const f=a(this),g=this,h=f.on("mouseenter",function(a){e(f,a)&&f.showBalloon()}).off("mouseenter",c).showBalloon(b).data("balloon");h&&h.on("mouseleave",function(b){g===b.relatedTarget||a.contains(g,b.relatedTarget)||f.h