UNPKG

mcs-ng-material

Version:

MCS NG-Meterial is based on mcs-web.

7 lines 4.72 kB
/*! * AngularJS Material Design * https://github.com/angular/material * @license MIT * v1.1.5-master-515959d */ function MdTooltipDirective(e,t,i,o,n,r,l,a){function d(d,b,h){function v(){d.mdZIndex=d.mdZIndex||u,d.mdDelay=d.mdDelay||m,p[d.mdDirection]||(d.mdDirection=f)}function y(e){var t=e||n(b.text().trim())(d.$parent);(!q.attr("aria-label")&&!q.attr("aria-labelledby")||q.attr("md-labeled-by-tooltip"))&&(q.attr("aria-label",t),q.attr("md-labeled-by-tooltip")||q.attr("md-labeled-by-tooltip",R))}function g(){v(),A&&A.panelEl&&A.panelEl.removeClass(D),D="md-origin-"+d.mdDirection,O=p[d.mdDirection],V=l.newPanelPosition().relativeTo(q).addPanelPosition(O.x,O.y),A&&A.panelEl&&(A.panelEl.addClass(D),A.updatePosition(V))}function E(){function i(e){return e.some(function(e){return"disabled"===e.attributeName&&q[0].disabled}),!1}function n(){w(!1)}function l(){F=document.activeElement===q[0]}function u(e){"focus"===e.type&&F?F=!1:d.mdVisible||(q.on(s,m),w(!0),"touchstart"===e.type&&q.one("touchend",function(){r.nextTick(function(){o.one("touchend",m)},!1)}))}function m(){C=d.hasOwnProperty("mdAutohide")?d.mdAutohide:h.hasOwnProperty("mdAutohide"),(C||N||o[0].activeElement!==q[0])&&(M&&(e.cancel(M),w.queued=!1,M=null),q.off(s,m),q.triggerHandler("blur"),w(!1)),N=!1}function f(){N=!0}function p(){a.deregister("scroll",n,!0),a.deregister("blur",l),a.deregister("resize",W),q.off(c,u).off(s,m).off("mousedown",f),m(),b&&b.disconnect()}if(q[0]&&"MutationObserver"in t){var b=new MutationObserver(function(e){i(e)&&r.nextTick(function(){w(!1)})});b.observe(q[0],{attributes:!0})}F=!1,a.register("scroll",n,!0),a.register("blur",l),a.register("resize",W),d.$on("$destroy",p),q.on("mousedown",f),q.on(c,u)}function x(){function e(){d.$destroy()}if(b[0]&&"MutationObserver"in t){var i=new MutationObserver(function(e){e.forEach(function(e){"md-visible"!==e.attributeName||d.visibleWatcher||(d.visibleWatcher=d.$watch("mdVisible",$))})});i.observe(b[0],{attributes:!0}),h.hasOwnProperty("mdVisible")&&(d.visibleWatcher=d.$watch("mdVisible",$))}else d.visibleWatcher=d.$watch("mdVisible",$);d.$watch("mdDirection",g),b.one("$destroy",e),q.one("$destroy",e),d.$on("$destroy",function(){w(!1),A&&A.destroy(),i&&i.disconnect(),b.remove()}),b.text().indexOf(n.startSymbol())>-1&&d.$watch(function(){return b.text().trim()},y)}function w(t){w.queued&&w.value===!!t||!w.queued&&d.mdVisible===!!t||(w.value=!!t,w.queued||(t?(w.queued=!0,M=e(function(){d.mdVisible=w.value,w.queued=!1,M=null,d.visibleWatcher||$(d.mdVisible)},d.mdDelay)):r.nextTick(function(){d.mdVisible=!1,d.visibleWatcher||$(!1)})))}function $(e){e?T():P()}function T(){if(!b[0].textContent.trim())throw new Error("Text for the tooltip has not been provided. Please include text within the mdTooltip element.");if(!A){var e=angular.element(document.body),t=l.newPanelAnimation().openFrom(q).closeTo(q).withAnimation({open:"md-show",close:"md-hide"}),i={id:R,attachTo:e,contentElement:b,propagateContainerEvents:!0,panelClass:"md-tooltip "+D,animation:t,position:V,zIndex:d.mdZIndex,focusOnOpen:!1};A=l.create(i)}A.open().then(function(){A.panelEl.attr("role","tooltip")})}function P(){A&&A.close()}var D,O,V,A,C,M,R="md-tooltip-"+r.nextUid(),q=r.getParentWithPointerEvents(b),W=i.throttle(g),N=!1,F=null;v(),y(),b.detach(),g(),E(),x()}var c="focus touchstart mouseenter",s="blur touchcancel mouseleave",u=100,m=0,f="bottom",p={top:{x:l.xPosition.CENTER,y:l.yPosition.ABOVE},right:{x:l.xPosition.OFFSET_END,y:l.yPosition.CENTER},bottom:{x:l.xPosition.CENTER,y:l.yPosition.BELOW},left:{x:l.xPosition.OFFSET_START,y:l.yPosition.CENTER}};return{restrict:"E",priority:210,scope:{mdZIndex:"=?mdZIndex",mdDelay:"=?mdDelay",mdVisible:"=?mdVisible",mdAutohide:"=?mdAutohide",mdDirection:"@?mdDirection"},link:d}}function MdTooltipRegistry(){function e(e){o[e.type]&&o[e.type].forEach(function(t){t.call(this,e)},this)}function t(t,i,r){var l=o[t]=o[t]||[];l.length||(r?window.addEventListener(t,e,!0):n.on(t,e)),l.indexOf(i)===-1&&l.push(i)}function i(t,i,r){var l=o[t],a=l?l.indexOf(i):-1;a>-1&&(l.splice(a,1),0===l.length&&(r?window.removeEventListener(t,e,!0):n.off(t,e)))}var o={},n=angular.element(window);return{register:t,deregister:i}}goog.provide("ngmaterial.components.tooltip"),goog.require("ngmaterial.components.panel"),goog.require("ngmaterial.core"),MdTooltipDirective.$inject=["$timeout","$window","$$rAF","$document","$interpolate","$mdUtil","$mdPanel","$$mdTooltipRegistry"],angular.module("material.components.tooltip",["material.core","material.components.panel"]).directive("mdTooltip",MdTooltipDirective).service("$$mdTooltipRegistry",MdTooltipRegistry),ngmaterial.components.tooltip=angular.module("material.components.tooltip");