12 lines
9.3 KiB
JavaScript
12 lines
9.3 KiB
JavaScript
/*
|
|
* angular-tooltips
|
|
* 1.2.2
|
|
*
|
|
* Angular.js tooltips module.
|
|
* http://720kb.github.io/angular-tooltips
|
|
*
|
|
* MIT license
|
|
* Tue Jun 20 2017
|
|
*/
|
|
!function(t,o){"use strict";var e="tooltips",i=function(){var t,e=[],i=0,r=function(t){t-i>=15?(e.forEach(function(t){t()}),i=t):o.console.log("Skipped!")},l=function(){o.clearTimeout(t),t=o.setTimeout(function(){o.requestAnimationFrame(r)},500)},n=function(t){t&&e.push(t)};return{add:function(t){e.length||o.addEventListener("resize",l),n(t)},remove:function(){e.length||(o.clearTimeout(t),o.removeEventListener("resize",l))}}}(),r=function(t){var o={};return t.removeAttr(e),void 0!==t.attr("tooltip-template")&&(o["tooltip-template"]=t.attr("tooltip-template"),t.removeAttr("tooltip-template")),void 0!==t.attr("tooltip-template-url")&&(o["tooltip-template-url"]=t.attr("tooltip-template-url"),t.removeAttr("tooltip-template-url")),void 0!==t.attr("tooltip-template-url-cache")&&(o["tooltip-template-url-cache"]=t.attr("tooltip-template-url-cache"),t.removeAttr("tooltip-template-url-cache")),void 0!==t.attr("tooltip-controller")&&(o["tooltip-controller"]=t.attr("tooltip-controller"),t.removeAttr("tooltip-controller")),void 0!==t.attr("tooltip-side")&&(o["tooltip-side"]=t.attr("tooltip-side"),t.removeAttr("tooltip-side")),void 0!==t.attr("tooltip-show-trigger")&&(o["tooltip-show-trigger"]=t.attr("tooltip-show-trigger"),t.removeAttr("tooltip-show-trigger")),void 0!==t.attr("tooltip-hide-trigger")&&(o["tooltip-hide-trigger"]=t.attr("tooltip-hide-trigger"),t.removeAttr("tooltip-hide-trigger")),void 0!==t.attr("tooltip-smart")&&(o["tooltip-smart"]=t.attr("tooltip-smart"),t.removeAttr("tooltip-smart")),void 0!==t.attr("tooltip-class")&&(o["tooltip-class"]=t.attr("tooltip-class"),t.removeAttr("tooltip-class")),void 0!==t.attr("tooltip-show")&&(o["tooltip-show"]=t.attr("tooltip-show"),t.removeAttr("tooltip-show")),void 0!==t.attr("tooltip-close-button")&&(o["tooltip-close-button"]=t.attr("tooltip-close-button"),t.removeAttr("tooltip-close-button")),void 0!==t.attr("tooltip-size")&&(o["tooltip-size"]=t.attr("tooltip-size"),t.removeAttr("tooltip-size")),void 0!==t.attr("tooltip-speed")&&(o["tooltip-speed"]=t.attr("tooltip-speed"),t.removeAttr("tooltip-speed")),o},l=function(t){return o.getComputedStyle?o.getComputedStyle(t,""):t.currentStyle?t.currentStyle:void 0},n=function(e){for(var i,r,l=o.document.querySelectorAll("._exradicated-tooltip"),n=0,p=l.length;n<p;n+=1)if(i=l.item(n),i&&(r=t.element(i),r.data("_tooltip-parent")&&r.data("_tooltip-parent")===e))return r},p=function(t){var o=n(t);o&&o.remove()},a=function(t){if(t){var e=t[0].getBoundingClientRect();return(e.top<0||e.top>o.document.body.offsetHeight||e.left<0||e.left>o.document.body.offsetWidth||e.bottom<0||e.bottom>o.document.body.offsetHeight||e.right<0||e.right>o.document.body.offsetWidth)&&(t.css({top:"",left:"",bottom:"",right:""}),!0)}throw new Error("You must provide a position")},s=function(t){return t.split(" ").map(function(t){return"_"+t}).join(" ")},d=["_top","_top _left","_left","_bottom _left","_bottom","_bottom _right","_right","_top _right"],c=function(t,o,e){for(var i=d.indexOf(s(e)),r=d.length,l=0;l<r&&a(t);l+=1)i+=1,i>=d.length&&(i=0),o.removeClass("_top _left _bottom _right"),o.addClass(d[i])},u=function(){var t={side:"top",showTrigger:"mouseenter",hideTrigger:"mouseleave","class":"",smart:!1,closeButton:!1,size:"",speed:"steady",tooltipTemplateUrlCache:!1,show:null};return{configure:function(o){var e,i=Object.keys(t),r=0;if(o)for(;r<i.length;r+=1)e=i[r],e&&o[e]&&(t[e]=o[e])},$get:function(){return t}}},m=["$log","$http","$compile","$timeout","$controller","$injector","tooltipsConf","$templateCache","$q",function(e,a,d,u,m,f,g,h,v){var C=function(f,C,b,y,w){if(b.tooltipTemplate&&b.tooltipTemplateUrl)throw new Error("You can not define tooltip-template and tooltip-template-url together");if(!b.tooltipTemplateUrl&&!b.tooltipTemplate&&b.tooltipController)throw new Error("You can not have a controller without a template or templateUrl defined");var _,T=s(g.side),S=g.showTrigger,$=g.hideTrigger,A=g.size,B="_"+g.speed;b.tooltipSide=b.tooltipSide||g.side,b.tooltipShowTrigger=b.tooltipShowTrigger||g.showTrigger,b.tooltipHideTrigger=b.tooltipHideTrigger||g.hideTrigger,b.tooltipShow=b.tooltipShow||g.show,b.tooltipClass=b.tooltipClass||g["class"],b.tooltipSmart="true"===b.tooltipSmart||g.smart,b.tooltipCloseButton=b.tooltipCloseButton||g.closeButton.toString(),b.tooltipSize=b.tooltipSize||g.size,b.tooltipSpeed=b.tooltipSpeed||g.speed,b.tooltipAppendToBody="true"===b.tooltipAppendToBody,w(f,function(f,g){var y=r(f),w=t.element(o.document.createElement("tooltip")),z=t.element(o.document.createElement("tip-cont")),E=t.element(o.document.createElement("tip")),P=t.element(o.document.createElement("tip-tip")),x=t.element(o.document.createElement("span")),H=t.element(o.document.createElement("tip-arrow")),V=function(){return z.html()},U=function(t){void 0!==t&&z[0].getClientRects().length>1?w.addClass("_multiline"):w.removeClass("_multiline")},k=function(e){if(e&&!w.hasClass("active")&&e.stopImmediatePropagation(),E.addClass("_hidden"),b.tooltipSmart)switch(b.tooltipSide){case"top":case"left":case"bottom":case"right":case"top left":case"top right":case"bottom left":case"bottom right":c(E,w,b.tooltipSide);break;default:throw new Error("Position not supported")}if(b.tooltipAppendToBody){var i,r,n,a,s,d=l(P[0]),u=l(H[0]),m=l(E[0]),f=E[0].getBoundingClientRect(),g=t.copy(E),h=0,v=d.length,C=0,y=u.length,_=0,T=m.length,S={},$={},A={};for(E.removeClass("_hidden"),g.removeClass("_hidden"),g.data("_tooltip-parent",w),p(w);h<v;h+=1)i=d[h],i&&d.getPropertyValue(i)&&(S[i]=d.getPropertyValue(i));for(;C<y;C+=1)i=u[C],i&&u.getPropertyValue(i)&&(A[i]=u.getPropertyValue(i));for(;_<T;_+=1)i=m[_],i&&"position"!==i&&"display"!==i&&"opacity"!==i&&"z-index"!==i&&"bottom"!==i&&"height"!==i&&"left"!==i&&"right"!==i&&"top"!==i&&"width"!==i&&m.getPropertyValue(i)&&($[i]=m.getPropertyValue(i));r=o.parseInt(m.getPropertyValue("padding-top"),10),n=o.parseInt(m.getPropertyValue("padding-bottom"),10),a=o.parseInt(m.getPropertyValue("padding-left"),10),s=o.parseInt(m.getPropertyValue("padding-right"),10),$.top=f.top+o.pageYOffset+"px",$.left=f.left+o.pageXOffset+"px",$.height=f.height-(r+n)+"px",$.width=f.width-(a+s)+"px",g.css($),g.children().css(S),g.children().next().css(A),e&&"true"!==b.tooltipHidden&&(g.addClass("_exradicated-tooltip"),t.element(o.document.body).append(g))}else E.removeClass("_hidden"),e&&"true"!==b.tooltipHidden&&w.addClass("active")},I=function(t){t&&w.hasClass("active")&&t.stopImmediatePropagation(),b.tooltipAppendToBody?p(w):w.removeClass("active")},O=function ft(t){var o,e=t.parent();t[0]&&(t[0].scrollHeight>t[0].clientHeight||t[0].scrollWidth>t[0].clientWidth)&&t.on("scroll",function(){var t=this;o&&u.cancel(o),o=u(function(){var o=n(w),e=w[0].getBoundingClientRect(),i=t.getBoundingClientRect();e.top<i.top||e.bottom>i.bottom||e.left<i.left||e.right>i.right?p(w):o&&k(!0)})}),e&&e.length&&ft(e)},R=function(t){w.removeClass("_force-hidden"),P.empty(),P.append(x),P.append(t),u(function(){k()})},W=function(){P.empty(),w.addClass("_force-hidden")},Y=function(t){var o=h.get(t);return"undefined"!=typeof o?v.resolve(o):a.get(t).then(function(o){return h.put(t,o.data),o.data})},j=function(t){t?R(t):W()},q=function(t){t&&!b.tooltipTemplateUrlCache?Y(t).then(function(t){R(d(t)(g))})["catch"](function(t){e.error(t)}):W()},L=function(t){t&&b.tooltipTemplateUrl?Y(b.tooltipTemplateUrl).then(function(t){R(d(t)(g))})["catch"](function(t){e.error(t)}):W()},F=function(t){t&&(T&&w.removeClass(T),w.addClass(s(t)),T=t)},X=function(t){t&&(S&&w.off(S),w.on(t,k),S=t)},D=function(t){t&&($&&w.off($),w.on(t,I),$=t)},G=function(t){"true"===t?w.addClass("active"):w.removeClass("active")},J=function(t){t&&(_&&E.removeClass(_),E.addClass(t),_=t)},K=function(){"boolean"!=typeof b.tooltipSmart&&(b.tooltipSmart="true"===b.tooltipSmart)},M=function(t){var o="true"===t;o?(x.on("click",I),x.css("display","block")):(x.off("click"),x.css("display","none"))},N=function(o){if(o){var e,i=m(o,{$scope:g}),r=g.$new(!1,g),l=o.indexOf("as");l>=0?(e=o.substr(l+3),r[e]=i):t.extend(r,i),P.replaceWith(d(P)(r)),dt()}},Q=function(t){t&&(A&&P.removeClass("_"+A),P.addClass("_"+t),A=t)},Z=function(t){t&&(B&&w.removeClass("_"+B),w.addClass("_"+t),B=t)},tt=b.$observe("tooltipTemplate",j),ot=b.$observe("tooltipTemplateUrl",q),et=b.$observe("tooltipTemplateUrlCache",L),it=b.$observe("tooltipSide",F),rt=b.$observe("tooltipShowTrigger",X),lt=b.$observe("tooltipHideTrigger",D),nt=b.$observe("tooltipShow",G),pt=b.$observe("tooltipClass",J),at=b.$observe("tooltipSmart",K),st=b.$observe("tooltipCloseButton",M),dt=b.$observe("tooltipController",N),ct=b.$observe("tooltipSize",Q),ut=b.$observe("tooltipSpeed",Z),mt=g.$watch(V,U);x.addClass("close-button"),x.html("×"),E.addClass("_hidden"),P.append(x),P.append(b.tooltipTemplate),E.append(P),E.append(H),z.append(f),w.attr(y),w.addClass("tooltips"),w.append(z),w.append(E),C.after(w),b.tooltipAppendToBody&&(i.add(function(){O(w)}),O(w)),i.add(function(){U(),k()}),u(function(){k(),E.removeClass("_hidden"),w.addClass("_ready")}),g.$on("$destroy",function(){tt(),ot(),et(),it(),rt(),lt(),nt(),pt(),at(),st(),ct(),ut(),mt(),i.remove(),f.off(b.tooltipShowTrigger+" "+b.tooltipHideTrigger)})})};return{restrict:"A",transclude:"element",priority:1,terminal:!0,link:C}}];t.module("720kb.tooltips",[]).provider(e+"Conf",u).directive(e,m)}(angular,window);
|