tooltip.min.js 10.0 KB

12345678910
  1. /**
  2. * angular-strap
  3. * @version v2.3.9 - 2016-06-10
  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:'',titleTemplate:!1,trigger:'hover focus',keyboard:!1,html:!1,show:!1,title:'',type:'',delay:0,autoClose:!1,bsEnabled:!0,mouseDownPreventDefault:!0,mouseDownStopPropagation:!0,viewport:{selector:'body',padding:0}};this.$get=['$window','$rootScope','$bsCompiler','$q','$templateCache','$http','$animate','$sce','dimensions','$$rAF','$timeout',function(e,o,n,i,a,r,l,s,u,f,c){function p(i,a){function r(){B.$emit(F.prefixEvent+'.show',T),angular.isDefined(F.onShow)&&angular.isFunction(F.onShow)&&F.onShow(T)}function p(){if(B.$emit(F.prefixEvent+'.hide',T),angular.isDefined(F.onHide)&&angular.isFunction(F.onHide)&&F.onHide(T),W===j){if(V&&'focus'===F.trigger)return i[0].blur();P()}}function g(){var t=F.trigger.split(' ');angular.forEach(t,function(t){'click'===t||'contextmenu'===t?i.on(t,T.toggle):'manual'!==t&&(i.on('hover'===t?'mouseenter':'focus',T.enter),i.on('hover'===t?'mouseleave':'blur',T.leave),'button'===U&&'hover'!==t&&i.on(m?'touchstart':'mousedown',T.$onFocusElementMouseDown))})}function w(){for(var t=F.trigger.split(' '),e=t.length;e--;){var o=t[e];'click'===o||'contextmenu'===o?i.off(o,T.toggle):'manual'!==o&&(i.off('hover'===o?'mouseenter':'focus',T.enter),i.off('hover'===o?'mouseleave':'blur',T.leave),'button'===U&&'hover'!==o&&i.off(m?'touchstart':'mousedown',T.$onFocusElementMouseDown))}}function v(){'focus'!==F.trigger?W.on('keyup',T.$onKeyUp):i.on('keyup',T.$onFocusKeyUp)}function b(){'focus'!==F.trigger?W.off('keyup',T.$onKeyUp):i.off('keyup',T.$onFocusKeyUp)}function y(){c(function(){W.on('click',D),$.on('click',T.hide),L=!0},0,!1)}function S(){L&&(W.off('click',D),$.off('click',T.hide),L=!1)}function D(t){t.stopPropagation()}function E(t){t=t||F.target||i;var o=t[0],n='BODY'===o.tagName,a=o.getBoundingClientRect(),r={};for(var l in a)r[l]=a[l];null===r.width&&(r=angular.extend({},r,{width:a.right-a.left,height:a.bottom-a.top}));var s=n?{top:0,left:0}:u.offset(o),f={scroll:n?document.documentElement.scrollTop||document.body.scrollTop:t.prop('scrollTop')||0},c=n?{width:document.documentElement.clientWidth,height:e.innerHeight}:null;return angular.extend({},r,f,c,s)}function C(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+e.height;break;case'bottom':i.top=e.top}return i}function k(t,e){var o=W[0],n=o.offsetWidth,i=o.offsetHeight,a=parseInt(u.css(o,'margin-top'),10),r=parseInt(u.css(o,'margin-left'),10);isNaN(a)&&(a=0),isNaN(r)&&(r=0),t.top=t.top+a,t.left=t.left+r,u.setOffset(o,angular.extend({using:function(t){W.css({top:Math.round(t.top)+'px',left:Math.round(t.left)+'px',right:''})}},t),0);var l=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 f=x(e,t,l,s);if(f.left?t.left+=f.left:t.top+=f.top,u.setOffset(o,t),/top|right|bottom|left/.test(e)){var c=/top|bottom/.test(e),p=c?2*f.left-n+l:2*f.top-i+s,h=c?'offsetWidth':'offsetHeight';H(p,o[h],c)}}}function x(t,e,o,n){var i={top:0,left:0};if(!T.$viewport)return i;var a=F.viewport&&F.viewport.padding||0,r=E(T.$viewport);if(/right|left/.test(t)){var l=e.top-a-r.scroll,s=e.top+a-r.scroll+n;l<r.top?i.top=r.top-l:s>r.top+r.height&&(i.top=r.top+r.height-s)}else{var u=e.left-a,f=e.left+a+o;u<r.left?i.left=r.left-u:f>r.right&&(i.left=r.left+r.width-f)}return i}function H(t,e,o){var n=d('.tooltip-arrow, .arrow',W[0]);n.css(o?'left':'top',50*(1-t/e)+'%').css(o?'top':'left','')}function P(){clearTimeout(K),T.$isShown&&null!==W&&(F.autoClose&&S(),F.keyboard&&b()),I&&(I.$destroy(),I=null),W&&(W.remove(),W=T.$element=null)}var T={},F=T.$options=angular.extend({},t,a),A=T.$promise=n.compile(F),B=T.$scope=F.scope&&F.scope.$new()||o.$new(),U=i[0].nodeName.toLowerCase();if(F.delay&&angular.isString(F.delay)){var N=F.delay.split(',').map(parseFloat);F.delay=N.length>1?{show:N[0],hide:N[1]}:N[0]}T.$id=F.id||i.attr('id')||'',F.title&&(B.title=s.trustAsHtml(F.title)),B.$setEnabled=function(t){B.$$postDigest(function(){T.setEnabled(t)})},B.$hide=function(){B.$$postDigest(function(){T.hide()})},B.$show=function(){B.$$postDigest(function(){T.show()})},B.$toggle=function(){B.$$postDigest(function(){T.toggle()})},T.$isShown=B.$isShown=!1;var K,O,M,W,q,I;A.then(function(t){M=t,T.init()}),T.init=function(){F.delay&&angular.isNumber(F.delay)&&(F.delay={show:F.delay,hide:F.delay}),'self'===F.container?q=i:angular.isElement(F.container)?q=F.container:F.container&&(q=d(F.container)),g(),F.target&&(F.target=angular.isElement(F.target)?F.target:d(F.target)),F.show&&B.$$postDigest(function(){'focus'===F.trigger?i[0].focus():T.show()})},T.destroy=function(){w(),P(),B.$destroy()},T.enter=function(){return clearTimeout(K),O='in',F.delay&&F.delay.show?void(K=setTimeout(function(){'in'===O&&T.show()},F.delay.show)):T.show()},T.show=function(){if(F.bsEnabled&&!T.$isShown){B.$emit(F.prefixEvent+'.show.before',T),angular.isDefined(F.onBeforeShow)&&angular.isFunction(F.onBeforeShow)&&F.onBeforeShow(T);var t,e;F.container?(t=q,e=q[0].lastChild?angular.element(q[0].lastChild):null):(t=null,e=i),W&&P(),I=T.$scope.$new(),W=T.$element=M.link(I,function(t,e){}),W.css({top:'-9999px',left:'-9999px',right:'auto',display:'block',visibility:'hidden'}),F.animation&&W.addClass(F.animation),F.type&&W.addClass(F.prefixClass+'-'+F.type),F.customClass&&W.addClass(F.customClass),e?e.after(W):t.prepend(W),T.$isShown=B.$isShown=!0,h(B),T.$applyPlacement(),angular.version.minor<=2?l.enter(W,t,e,r):l.enter(W,t,e).then(r),h(B),f(function(){W&&W.css({visibility:'visible'}),F.keyboard&&('focus'!==F.trigger&&T.focus(),v())}),F.autoClose&&y()}},T.leave=function(){return clearTimeout(K),O='out',F.delay&&F.delay.hide?void(K=setTimeout(function(){'out'===O&&T.hide()},F.delay.hide)):T.hide()};var V,j;T.hide=function(t){T.$isShown&&(B.$emit(F.prefixEvent+'.hide.before',T),angular.isDefined(F.onBeforeHide)&&angular.isFunction(F.onBeforeHide)&&F.onBeforeHide(T),V=t,j=W,angular.version.minor<=2?l.leave(W,p):l.leave(W).then(p),T.$isShown=B.$isShown=!1,h(B),F.keyboard&&null!==W&&b(),F.autoClose&&null!==W&&S())},T.toggle=function(t){t&&t.preventDefault(),T.$isShown?T.leave():T.enter()},T.focus=function(){W[0].focus()},T.setEnabled=function(t){F.bsEnabled=t},T.setViewport=function(t){F.viewport=t},T.$applyPlacement=function(){if(W){var e=F.placement,o=/\s?auto?\s?/i,n=o.test(e);n&&(e=e.replace(o,'')||t.placement),W.addClass(F.placement);var i=E(),a=W.prop('offsetWidth'),r=W.prop('offsetHeight');if(T.$viewport=F.viewport&&d(F.viewport.selector||F.viewport),n){var l=e,s=E(T.$viewport);/bottom/.test(l)&&i.bottom+r>s.bottom?e=l.replace('bottom','top'):/top/.test(l)&&i.top-r<s.top&&(e=l.replace('top','bottom')),/left/.test(l)&&i.left-a<s.left?e=e.replace('left','right'):/right/.test(l)&&i.right+a>s.width&&(e=e.replace('right','left')),W.removeClass(l).addClass(e)}var u=C(e,i,a,r);k(u,e)}},T.$onKeyUp=function(t){27===t.which&&T.$isShown&&(T.hide(),t.stopPropagation())},T.$onFocusKeyUp=function(t){27===t.which&&(i[0].blur(),t.stopPropagation())},T.$onFocusElementMouseDown=function(t){F.mouseDownPreventDefault&&t.preventDefault(),F.mouseDownStopPropagation&&t.stopPropagation(),T.$isShown?i[0].blur():i[0].focus()};var L=!1;return T}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=/(ip[ao]d|iphone|android)/gi.test(e.navigator.userAgent),m='createTouch'in e.document&&g,$=angular.element(e.document);return p}]}).directive('bsTooltip',['$window','$location','$sce','$parse','$tooltip','$$rAF',function(t,e,o,n,i,a){return{restrict:'EAC',scope:!0,link:function(t,e,n,r){var l,s={scope:t};angular.forEach(['template','templateUrl','controller','controllerAs','titleTemplate','placement','container','delay','trigger','html','animation','backdropAnimation','type','customClass','id'],function(t){angular.isDefined(n[t])&&(s[t]=n[t])});var u=/^(false|0|)$/i;angular.forEach(['html','container'],function(t){angular.isDefined(n[t])&&u.test(n[t])&&(s[t]=!1)}),angular.forEach(['onBeforeShow','onShow','onBeforeHide','onHide'],function(e){var o='bs'+e.charAt(0).toUpperCase()+e.slice(1);angular.isDefined(n[o])&&(s[e]=t.$eval(n[o]))});var f=e.attr('data-target');angular.isDefined(f)&&(u.test(f)?s.target=!1:s.target=f),t.hasOwnProperty('title')||(t.title=''),n.$observe('title',function(e){if(angular.isDefined(e)||!t.hasOwnProperty('title')){var n=t.title;t.title=o.trustAsHtml(e),angular.isDefined(n)&&a(function(){l&&l.$applyPlacement()})}}),n.$observe('disabled',function(t){t&&l.$isShown&&l.hide()}),n.bsTooltip&&t.$watch(n.bsTooltip,function(e,o){angular.isObject(e)?angular.extend(t,e):t.title=e,angular.isDefined(o)&&a(function(){l&&l.$applyPlacement()})},!0),n.bsShow&&t.$watch(n.bsShow,function(t,e){l&&angular.isDefined(t)&&(angular.isString(t)&&(t=!!t.match(/true|,?(tooltip),?/i)),t===!0?l.show():l.hide())}),n.bsEnabled&&t.$watch(n.bsEnabled,function(t,e){l&&angular.isDefined(t)&&(angular.isString(t)&&(t=!!t.match(/true|1|,?(tooltip),?/i)),t===!1?l.setEnabled(!1):l.setEnabled(!0))}),n.viewport&&t.$watch(n.viewport,function(t){l&&angular.isDefined(t)&&l.setViewport(t)}),l=i(e,s),t.$on('$destroy',function(){l&&l.destroy(),s=null,l=null})}}}]);
  9. //# sourceMappingURL=tooltip.min.js.map