tooltip.min.js 9.3 KB

123456789
  1. /**
  2. * angular-strap
  3. * @version v2.3.5 - 2015-10-29
  4. * @link http://mgcrea.github.io/angular-strap
  5. * @author Olivier Louvignes <olivier@mg-crea.com> (https://github.com/mgcrea)
  6. * @license MIT License, http://www.opensource.org/licenses/MIT
  7. */
  8. 'use strict';angular.module('mgcrea.ngStrap.tooltip',['mgcrea.ngStrap.core','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',templateUrl:'tooltip/tooltip.tpl.html',template:'',contentTemplate:!1,trigger:'hover focus',keyboard:!1,html:!1,show:!1,title:'',type:'',delay:0,autoClose:!1,bsEnabled:!0,viewport:{selector:'body',padding:0}};this.$get=['$window','$rootScope','$bsCompiler','$q','$templateCache','$http','$animate','$sce','dimensions','$$rAF','$timeout',function(e,o,n,i,r,l,a,s,f,c,u){function p(i,r){function l(){U.$emit(A.prefixEvent+'.show',F)}function p(){if(U.$emit(A.prefixEvent+'.hide',F),q===j){if(V&&'focus'===A.trigger)return i[0].blur();P()}}function $(){var t=A.trigger.split(' ');angular.forEach(t,function(t){'click'===t?i.on('click',F.toggle):'manual'!==t&&(i.on('hover'===t?'mouseenter':'focus',F.enter),i.on('hover'===t?'mouseleave':'blur',F.leave),'button'===H&&'hover'!==t&&i.on(g?'touchstart':'mousedown',F.$onFocusElementMouseDown))})}function v(){for(var t=A.trigger.split(' '),e=t.length;e--;){var o=t[e];'click'===o?i.off('click',F.toggle):'manual'!==o&&(i.off('hover'===o?'mouseenter':'focus',F.enter),i.off('hover'===o?'mouseleave':'blur',F.leave),'button'===H&&'hover'!==o&&i.off(g?'touchstart':'mousedown',F.$onFocusElementMouseDown))}}function w(){'focus'!==A.trigger?q.on('keyup',F.$onKeyUp):i.on('keyup',F.$onFocusKeyUp)}function b(){'focus'!==A.trigger?q.off('keyup',F.$onKeyUp):i.off('keyup',F.$onFocusKeyUp)}function y(){u(function(){q.on('click',k),m.on('click',F.hide),L=!0},0,!1)}function E(){L&&(q.off('click',k),m.off('click',F.hide),L=!1)}function k(t){t.stopPropagation()}function C(t){t=t||A.target||i;var o=t[0],n='BODY'===o.tagName,r=o.getBoundingClientRect(),l={};for(var a in r)l[a]=r[a];null===l.width&&(l=angular.extend({},l,{width:r.right-r.left,height:r.bottom-r.top}));var s=n?{top:0,left:0}:f.offset(o),c={scroll:n?document.documentElement.scrollTop||document.body.scrollTop:t.prop('scrollTop')||0},u=n?{width:document.documentElement.clientWidth,height:e.innerHeight}:null;return angular.extend({},l,c,u,s)}function S(t,e,o,n){var i,r=t.split('-');switch(r[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(!r[1])return i;if('top'===r[0]||'bottom'===r[0])switch(r[1]){case'left':i.left=e.left;break;case'right':i.left=e.left+e.width-o}else if('left'===r[0]||'right'===r[0])switch(r[1]){case'top':i.top=e.top-n;break;case'bottom':i.top=e.top+e.height}return i}function D(t,e){var o=q[0],n=o.offsetWidth,i=o.offsetHeight,r=parseInt(f.css(o,'margin-top'),10),l=parseInt(f.css(o,'margin-left'),10);isNaN(r)&&(r=0),isNaN(l)&&(l=0),t.top=t.top+r,t.left=t.left+l,f.setOffset(o,angular.extend({using:function(t){q.css({top:Math.round(t.top)+'px',left:Math.round(t.left)+'px',right:''})}},t),0);var a=o.offsetWidth,s=o.offsetHeight;if('top'===e&&s!==i&&(t.top=t.top+i-s),!/top-left|top-right|bottom-left|bottom-right/.test(e)){var c=x(e,t,a,s);if(c.left?t.left+=c.left:t.top+=c.top,f.setOffset(o,t),/top|right|bottom|left/.test(e)){var u=/top|bottom/.test(e),p=u?2*c.left-n+a:2*c.top-i+s,h=u?'offsetWidth':'offsetHeight';T(p,o[h],u)}}}function x(t,e,o,n){var i={top:0,left:0};if(!F.$viewport)return i;var r=A.viewport&&A.viewport.padding||0,l=C(F.$viewport);if(/right|left/.test(t)){var a=e.top-r-l.scroll,s=e.top+r-l.scroll+n;a<l.top?i.top=l.top-a:s>l.top+l.height&&(i.top=l.top+l.height-s)}else{var f=e.left-r,c=e.left+r+o;f<l.left?i.left=l.left-f:c>l.right&&(i.left=l.left+l.width-c)}return i}function T(t,e,o){var n=d('.tooltip-arrow, .arrow',q[0]);n.css(o?'left':'top',50*(1-t/e)+'%').css(o?'top':'left','')}function P(){clearTimeout(K),F.$isShown&&null!==q&&(A.autoClose&&E(),A.keyboard&&b()),I&&(I.$destroy(),I=null),q&&(q.remove(),q=F.$element=null)}var F={},A=F.$options=angular.extend({},t,r),O=F.$promise=n.compile(A),U=F.$scope=A.scope&&A.scope.$new()||o.$new(),H=i[0].nodeName.toLowerCase();if(A.delay&&angular.isString(A.delay)){var N=A.delay.split(',').map(parseFloat);A.delay=N.length>1?{show:N[0],hide:N[1]}:N[0]}F.$id=A.id||i.attr('id')||'',A.title&&(U.title=s.trustAsHtml(A.title)),U.$setEnabled=function(t){U.$$postDigest(function(){F.setEnabled(t)})},U.$hide=function(){U.$$postDigest(function(){F.hide()})},U.$show=function(){U.$$postDigest(function(){F.show()})},U.$toggle=function(){U.$$postDigest(function(){F.toggle()})},F.$isShown=U.$isShown=!1;var K,M,W,q,B,I;O.then(function(t){W=t,F.init()}),F.init=function(){A.delay&&angular.isNumber(A.delay)&&(A.delay={show:A.delay,hide:A.delay}),'self'===A.container?B=i:angular.isElement(A.container)?B=A.container:A.container&&(B=d(A.container)),$(),A.target&&(A.target=angular.isElement(A.target)?A.target:d(A.target)),A.show&&U.$$postDigest(function(){'focus'===A.trigger?i[0].focus():F.show()})},F.destroy=function(){v(),P(),U.$destroy()},F.enter=function(){return clearTimeout(K),M='in',A.delay&&A.delay.show?void(K=setTimeout(function(){'in'===M&&F.show()},A.delay.show)):F.show()},F.show=function(){if(A.bsEnabled&&!F.$isShown){U.$emit(A.prefixEvent+'.show.before',F);var t,e;A.container?(t=B,e=B[0].lastChild?angular.element(B[0].lastChild):null):(t=null,e=i),q&&P(),I=F.$scope.$new(),q=F.$element=W.link(I,function(t,e){}),q.css({top:'-9999px',left:'-9999px',right:'auto',display:'block',visibility:'hidden'}),A.animation&&q.addClass(A.animation),A.type&&q.addClass(A.prefixClass+'-'+A.type),A.customClass&&q.addClass(A.customClass),e?e.after(q):t.prepend(q),F.$isShown=U.$isShown=!0,h(U),F.$applyPlacement(),angular.version.minor<=2?a.enter(q,t,e,l):a.enter(q,t,e).then(l),h(U),c(function(){q&&q.css({visibility:'visible'}),A.keyboard&&('focus'!==A.trigger&&F.focus(),w())}),A.autoClose&&y()}},F.leave=function(){return clearTimeout(K),M='out',A.delay&&A.delay.hide?void(K=setTimeout(function(){'out'===M&&F.hide()},A.delay.hide)):F.hide()};var V,j;F.hide=function(t){F.$isShown&&(U.$emit(A.prefixEvent+'.hide.before',F),V=t,j=q,angular.version.minor<=2?a.leave(q,p):a.leave(q).then(p),F.$isShown=U.$isShown=!1,h(U),A.keyboard&&null!==q&&b(),A.autoClose&&null!==q&&E())},F.toggle=function(){F.$isShown?F.leave():F.enter()},F.focus=function(){q[0].focus()},F.setEnabled=function(t){A.bsEnabled=t},F.setViewport=function(t){A.viewport=t},F.$applyPlacement=function(){if(q){var e=A.placement,o=/\s?auto?\s?/i,n=o.test(e);n&&(e=e.replace(o,'')||t.placement),q.addClass(A.placement);var i=C(),r=q.prop('offsetWidth'),l=q.prop('offsetHeight');if(F.$viewport=A.viewport&&d(A.viewport.selector||A.viewport),n){var a=e,s=C(F.$viewport);a.indexOf('bottom')>=0&&i.bottom+l>s.bottom?e=a.replace('bottom','top'):a.indexOf('top')>=0&&i.top-l<s.top&&(e=a.replace('top','bottom')),('right'===a||'bottom-left'===a||'top-left'===a)&&i.right+r>s.width?e='right'===a?'left':e.replace('left','right'):('left'===a||'bottom-right'===a||'top-right'===a)&&i.left-r<s.left&&(e='left'===a?'right':e.replace('right','left')),q.removeClass(a).addClass(e)}var f=S(e,i,r,l);D(f,e)}},F.$onKeyUp=function(t){27===t.which&&F.$isShown&&(F.hide(),t.stopPropagation())},F.$onFocusKeyUp=function(t){27===t.which&&(i[0].blur(),t.stopPropagation())},F.$onFocusElementMouseDown=function(t){t.preventDefault(),t.stopPropagation(),F.$isShown?i[0].blur():i[0].focus()};var L=!1;return F}function h(t){t.$$phase||t.$root&&t.$root.$$phase||t.$digest()}function d(t,e){return angular.element((e||document).querySelectorAll(t))}var g=(String.prototype.trim,'createTouch'in e.document),m=angular.element(e.document);return p}]}).directive('bsTooltip',['$window','$location','$sce','$tooltip','$$rAF',function(t,e,o,n,i){return{restrict:'EAC',scope:!0,link:function(t,e,r,l){var a={scope:t};angular.forEach(['template','templateUrl','controller','controllerAs','contentTemplate','placement','container','delay','trigger','html','animation','backdropAnimation','type','customClass','id'],function(t){angular.isDefined(r[t])&&(a[t]=r[t])});var s=/^(false|0|)$/i;angular.forEach(['html','container'],function(t){angular.isDefined(r[t])&&s.test(r[t])&&(a[t]=!1)});var f=e.attr('data-target');angular.isDefined(f)&&(s.test(f)?a.target=!1:a.target=f),t.hasOwnProperty('title')||(t.title=''),r.$observe('title',function(e){if(angular.isDefined(e)||!t.hasOwnProperty('title')){var n=t.title;t.title=o.trustAsHtml(e),angular.isDefined(n)&&i(function(){c&&c.$applyPlacement()})}}),r.bsTooltip&&t.$watch(r.bsTooltip,function(e,o){angular.isObject(e)?angular.extend(t,e):t.title=e,angular.isDefined(o)&&i(function(){c&&c.$applyPlacement()})},!0),r.bsShow&&t.$watch(r.bsShow,function(t,e){c&&angular.isDefined(t)&&(angular.isString(t)&&(t=!!t.match(/true|,?(tooltip),?/i)),t===!0?c.show():c.hide())}),r.bsEnabled&&t.$watch(r.bsEnabled,function(t,e){c&&angular.isDefined(t)&&(angular.isString(t)&&(t=!!t.match(/true|1|,?(tooltip),?/i)),t===!1?c.setEnabled(!1):c.setEnabled(!0))}),r.viewport&&t.$watch(r.viewport,function(t){c&&angular.isDefined(t)&&c.setViewport(t)});var c=n(e,a);t.$on('$destroy',function(){c&&c.destroy(),a=null,c=null})}}}]);
  9. //# sourceMappingURL=tooltip.min.js.map