Files

9 lines
6.2 KiB
JavaScript

/**
* angular-strap
* @version v2.1.1 - 2014-09-26
* @link http://mgcrea.github.io/angular-strap
* @author Olivier Louvignes (olivier@mg-crea.com)
* @license MIT License, http://www.opensource.org/licenses/MIT
*/
"use strict";angular.module("mgcrea.ngStrap.tooltip",["mgcrea.ngStrap.helpers.dimensions"]).provider("$tooltip",function(){var t=this.defaults={animation:"am-fade",customClass:"",prefixClass:"tooltip",prefixEvent:"tooltip",container:!1,target:!1,placement:"top",template:"tooltip/tooltip.tpl.html",contentTemplate:!1,trigger:"hover focus",keyboard:!1,html:!1,show:!1,title:"",type:"",delay:0};this.$get=["$window","$rootScope","$compile","$q","$templateCache","$http","$animate","dimensions","$$rAF",function(e,o,n,i,a,r,l,s,u){function c(e,i){function a(){y.$emit(w.prefixEvent+".show",m)}function r(){return y.$emit(w.prefixEvent+".hide",m),blur&&"focus"===w.trigger?e[0].blur():void 0}function c(){return"body"===w.container?s.offset(w.target[0]||e[0]):s.position(w.target[0]||e[0])}function $(t,e,o,n){var i,a=t.split("-");switch(a[0]){case"right":i={top:e.top+e.height/2-n/2,left:e.left+e.width};break;case"bottom":i={top:e.top+e.height,left:e.left+e.width/2-o/2};break;case"left":i={top:e.top+e.height/2-n/2,left:e.left-o};break;default:i={top:e.top-n,left:e.left+e.width/2-o/2}}if(!a[1])return i;if("top"===a[0]||"bottom"===a[0])switch(a[1]){case"left":i.left=e.left;break;case"right":i.left=e.left+e.width-o}else if("left"===a[0]||"right"===a[0])switch(a[1]){case"top":i.top=e.top-n;break;case"bottom":i.top=e.top+e.height}return i}var m={},v=e[0].nodeName.toLowerCase(),w=m.$options=angular.extend({},t,i);m.$promise=f(w.template);var y=m.$scope=w.scope&&w.scope.$new()||o.$new();if(w.delay&&angular.isString(w.delay)){var b=w.delay.split(",").map(parseFloat);w.delay=b.length>1?{show:b[0],hide:b[1]}:b[0]}w.title&&(m.$scope.title=w.title),y.$hide=function(){y.$$postDigest(function(){m.hide()})},y.$show=function(){y.$$postDigest(function(){m.show()})},y.$toggle=function(){y.$$postDigest(function(){m.toggle()})},m.$isShown=y.$isShown=!1;var S,k;w.contentTemplate&&(m.$promise=m.$promise.then(function(t){var e=angular.element(t);return f(w.contentTemplate).then(function(t){var o=p('[ng-bind="content"]',e[0]);return o.length||(o=p('[ng-bind="title"]',e[0])),o.removeAttr("ng-bind").html(t),e[0].outerHTML})}));var T,x,C,E;return m.$promise.then(function(t){angular.isObject(t)&&(t=t.data),w.html&&(t=t.replace(g,'ng-bind-html="')),t=h.apply(t),C=t,T=n(t),m.init()}),m.init=function(){w.delay&&angular.isNumber(w.delay)&&(w.delay={show:w.delay,hide:w.delay}),"self"===w.container?E=e:angular.isElement(w.container)?E=w.container:w.container&&(E=p(w.container));var t=w.trigger.split(" ");angular.forEach(t,function(t){"click"===t?e.on("click",m.toggle):"manual"!==t&&(e.on("hover"===t?"mouseenter":"focus",m.enter),e.on("hover"===t?"mouseleave":"blur",m.leave),"button"===v&&"hover"!==t&&e.on(d?"touchstart":"mousedown",m.$onFocusElementMouseDown))}),w.target&&(w.target=angular.isElement(w.target)?w.target:p(w.target)),w.show&&y.$$postDigest(function(){"focus"===w.trigger?e[0].focus():m.show()})},m.destroy=function(){for(var t=w.trigger.split(" "),o=t.length;o--;){var n=t[o];"click"===n?e.off("click",m.toggle):"manual"!==n&&(e.off("hover"===n?"mouseenter":"focus",m.enter),e.off("hover"===n?"mouseleave":"blur",m.leave),"button"===v&&"hover"!==n&&e.off(d?"touchstart":"mousedown",m.$onFocusElementMouseDown))}x&&(x.remove(),x=null),clearTimeout(S),y.$destroy()},m.enter=function(){return clearTimeout(S),k="in",w.delay&&w.delay.show?void(S=setTimeout(function(){"in"===k&&m.show()},w.delay.show)):m.show()},m.show=function(){y.$emit(w.prefixEvent+".show.before",m);var t=w.container?E:null,o=w.container?null:e;x&&x.remove(),x=m.$element=T(y,function(){}),x.css({top:"-9999px",left:"-9999px",display:"block",visibility:"hidden"}).addClass(w.placement),w.animation&&x.addClass(w.animation),w.type&&x.addClass(w.prefixClass+"-"+w.type),w.customClass&&x.addClass(w.customClass);var n=l.enter(x,t,o,a);n&&n.then&&n.then(a),m.$isShown=y.$isShown=!0,y.$$phase||y.$root&&y.$root.$$phase||y.$digest(),u(function(){m.$applyPlacement(),x.css({visibility:"visible"})}),w.keyboard&&("focus"!==w.trigger?(m.focus(),x.on("keyup",m.$onKeyUp)):e.on("keyup",m.$onFocusKeyUp))},m.leave=function(){return clearTimeout(S),k="out",w.delay&&w.delay.hide?void(S=setTimeout(function(){"out"===k&&m.hide()},w.delay.hide)):m.hide()},m.hide=function(){if(m.$isShown){y.$emit(w.prefixEvent+".hide.before",m);var t=l.leave(x,r);t&&t.then&&t.then(r),m.$isShown=y.$isShown=!1,y.$$phase||y.$root&&y.$root.$$phase||y.$digest(),w.keyboard&&null!==x&&x.off("keyup",m.$onKeyUp)}},m.toggle=function(){m.$isShown?m.leave():m.enter()},m.focus=function(){x[0].focus()},m.$applyPlacement=function(){if(x){var t=c(),e=x.prop("offsetWidth"),o=x.prop("offsetHeight"),n=$(w.placement,t,e,o);n.top+="px",n.left+="px",x.css(n)}},m.$onKeyUp=function(t){27===t.which&&m.$isShown&&(m.hide(),t.stopPropagation())},m.$onFocusKeyUp=function(t){27===t.which&&(e[0].blur(),t.stopPropagation())},m.$onFocusElementMouseDown=function(t){t.preventDefault(),t.stopPropagation(),m.$isShown?e[0].blur():e[0].focus()},m}function p(t,e){return angular.element((e||document).querySelectorAll(t))}function f(t){return i.when(a.get(t)||r.get(t)).then(function(e){return angular.isObject(e)?(a.put(t,e.data),e.data):e})}var h=String.prototype.trim,d="createTouch"in e.document,g=/ng-bind="/gi;return c}]}).directive("bsTooltip",["$window","$location","$sce","$tooltip","$$rAF",function(t,e,o,n,i){return{restrict:"EAC",scope:!0,link:function(t,e,a){var r={scope:t};angular.forEach(["template","contentTemplate","placement","container","target","delay","trigger","keyboard","html","animation","type","customClass"],function(t){angular.isDefined(a[t])&&(r[t]=a[t])}),a.$observe("title",function(e,n){t.title=o.trustAsHtml(e),angular.isDefined(n)&&i(function(){l&&l.$applyPlacement()})}),a.bsTooltip&&t.$watch(a.bsTooltip,function(e,o){angular.isObject(e)?angular.extend(t,e):t.title=e,angular.isDefined(o)&&i(function(){l&&l.$applyPlacement()})},!0),a.bsShow&&t.$watch(a.bsShow,function(t){l&&angular.isDefined(t)&&(angular.isString(t)&&(t=!!t.match(",?(tooltip),?")),t===!0?l.show():l.hide())});var l=n(e,r);t.$on("$destroy",function(){l&&l.destroy(),r=null,l=null})}}}]);
//# sourceMappingURL=tooltip.min.js.map