| 1 |
+function($){'use strict';$.support.transition=!1;var Tooltip=function(element,options){this.type=null |
| 2 |
this.options=null |
| 3 |
this.enabled=null |
| 4 |
this.timeout=null |
| 5 |
this.hoverState=null |
| 6 |
this.$element=null |
| 7 |
this.inState=null |
| 8 |
this.init('tooltip',element,options)} |
| 9 |
Tooltip.VERSION='3.3.7' |
| 10 |
Tooltip.TRANSITION_DURATION=150 |
| 11 |
Tooltip.DEFAULTS={animation:!0,placement:'top',selector:!1,template:'<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>',trigger:'hover focus',title:'',delay:0,html:!1,container:!1,viewport:{selector:'body',padding:0}} |
| 12 |
Tooltip.prototype.init=function(type,element,options){this.enabled=!0 |
| 13 |
this.type=type |
| 14 |
this.$element=$(element) |
| 15 |
this.options=this.getOptions(options) |
| 16 |
this.$viewport=this.options.viewport&&$($.isFunction(this.options.viewport)?this.options.viewport.call(this,this.$element):(this.options.viewport.selector||this.options.viewport)) |
| 17 |
this.inState={click:!1,hover:!1,focus:!1} |
| 18 |
if(this.$element[0]instanceof document.constructor&&!this.options.selector){throw new Error('`selector` option must be specified when initializing '+this.type+' on the window.document object!')} |
| 19 |
var triggers=this.options.trigger.split(' ') |
| 20 |
for(var i=triggers.length;i--;){var trigger=triggers[i] |
| 21 |
if(trigger=='click'){this.$element.on('click.'+this.type,this.options.selector,$.proxy(this.toggle,this))}else if(trigger!='manual'){var eventIn=trigger=='hover'?'mouseenter':'focusin' |
| 22 |
var eventOut=trigger=='hover'?'mouseleave':'focusout' |
| 23 |
this.$element.on(eventIn+'.'+this.type,this.options.selector,$.proxy(this.enter,this)) |
| 24 |
this.$element.on(eventOut+'.'+this.type,this.options.selector,$.proxy(this.leave,this))}} |
| 25 |
this.options.selector?(this._options=$.extend({},this.options,{trigger:'manual',selector:''})):this.fixTitle()} |
| 26 |
Tooltip.prototype.getDefaults=function(){return Tooltip.DEFAULTS} |
| 27 |
Tooltip.prototype.getOptions=function(options){options=$.extend({},this.getDefaults(),this.$element.data(),options) |
| 28 |
if(options.delay&&typeof options.delay=='number'){options.delay={show:options.delay,hide:options.delay}} |
| 29 |
return options} |
| 30 |
Tooltip.prototype.getDelegateOptions=function(){var options={} |
| 31 |
var defaults=this.getDefaults() |
| 32 |
this._options&&$.each(this._options,function(key,value){if(defaults[key]!=value)options[key]=value}) |
| 33 |
return options} |
| 34 |
Tooltip.prototype.enter=function(obj){var self=obj instanceof this.constructor?obj:$(obj.currentTarget).data('bs.'+this.type) |
| 35 |
if(!self){self=new this.constructor(obj.currentTarget,this.getDelegateOptions()) |
| 36 |
$(obj.currentTarget).data('bs.'+this.type,self)} |
| 37 |
if(obj instanceof $.Event){self.inState[obj.type=='focusin'?'focus':'hover']=!0} |
| 38 |
if(self.tip().hasClass('in')||self.hoverState=='in'){self.hoverState='in' |
| 39 |
return} |
| 40 |
clearTimeout(self.timeout) |
| 41 |
self.hoverState='in' |
| 42 |
if(!self.options.delay||!self.options.delay.show)return self.show() |
| 43 |
self.timeout=setTimeout(function(){if(self.hoverState=='in')self.show()},self.options.delay.show)} |
| 44 |
Tooltip.prototype.isInStateTrue=function(){for(var key in this.inState){if(this.inState[key])return!0} |
| 45 |
return!1} |
| 46 |
Tooltip.prototype.leave=function(obj){var self=obj instanceof this.constructor?obj:$(obj.currentTarget).data('bs.'+this.type) |
| 47 |
if(!self){self=new this.constructor(obj.currentTarget,this.getDelegateOptions()) |
| 48 |
$(obj.currentTarget).data('bs.'+this.type,self)} |
| 49 |
if(obj instanceof $.Event){self.inState[obj.type=='focusout'?'focus':'hover']=!1} |
| 50 |
if(self.isInStateTrue())return |
| 51 |
clearTimeout(self.timeout) |
| 52 |
self.hoverState='out' |
| 53 |
if(!self.options.delay||!self.options.delay.hide)return self.hide() |
| 54 |
self.timeout=setTimeout(function(){if(self.hoverState=='out')self.hide()},self.options.delay.hide)} |
| 55 |
Tooltip.prototype.show=function(){var e=$.Event('show.bs.'+this.type) |
| 56 |
if(this.hasContent()&&this.enabled){this.$element.trigger(e) |
| 57 |
var inDom=$.contains(this.$element[0].ownerDocument.documentElement,this.$element[0]) |
| 58 |
if(e.isDefaultPrevented()||!inDom)return |
| 59 |
var that=this |
| 60 |
var $tip=this.tip() |
| 61 |
var tipId=this.getUID(this.type) |
| 62 |
this.setContent() |
| 63 |
$tip.attr('id',tipId) |
| 64 |
this.$element.attr('aria-describedby',tipId) |
| 65 |
if(this.options.animation)$tip.addClass('fade') |
| 66 |
var placement=typeof this.options.placement=='function'?this.options.placement.call(this,$tip[0],this.$element[0]):this.options.placement |
| 67 |
var autoToken=/\s?auto?\s?/i |
| 68 |
var autoPlace=autoToken.test(placement) |
| 69 |
if(autoPlace)placement=placement.replace(autoToken,'')||'top' |
| 70 |
$tip.detach().css({top:0,left:0,display:'block'}).addClass(placement).data('bs.'+this.type,this) |
| 71 |
this.options.container?$tip.appendTo(this.options.container):$tip.insertAfter(this.$element) |
| 72 |
this.$element.trigger('inserted.bs.'+this.type) |
| 73 |
var pos=this.getPosition() |
| 74 |
var actualWidth=$tip[0].offsetWidth |
| 75 |
var actualHeight=$tip[0].offsetHeight |
| 76 |
if(autoPlace){var orgPlacement=placement |
| 77 |
var viewportDim=this.getPosition(this.$viewport) |
| 78 |
placement=placement=='bottom'&&pos.bottom+actualHeight>viewportDim.bottom?'top':placement=='top'&&pos.top-actualHeight<viewportDim.top?'bottom':placement=='right'&&pos.right+actualWidth>viewportDim.width?'left':placement=='left'&&pos.left-actualWidth<viewportDim.left?'right':placement |
| 79 |
$tip.removeClass(orgPlacement).addClass(placement)} |
| 80 |
var calculatedOffset=this.getCalculatedOffset(placement,pos,actualWidth,actualHeight) |
| 81 |
this.applyPlacement(calculatedOffset,placement) |
| 82 |
var complete=function(){var prevHoverState=that.hoverState |
| 83 |
that.$element.trigger('shown.bs.'+that.type) |
| 84 |
that.hoverState=null |
| 85 |
if(prevHoverState=='out')that.leave(that)} |
| 86 |
$.support.transition&&this.$tip.hasClass('fade')?$tip.one('bsTransitionEnd',complete).emulateTransitionEnd(Tooltip.TRANSITION_DURATION):complete()}} |
| 87 |
Tooltip.prototype.applyPlacement=function(offset,placement){var $tip=this.tip() |
| 88 |
var width=$tip[0].offsetWidth |
| 89 |
var height=$tip[0].offsetHeight |
| 90 |
var marginTop=parseInt($tip.css('margin-top'),10) |
| 91 |
var marginLeft=parseInt($tip.css('margin-left'),10) |
| 92 |
if(isNaN(marginTop))marginTop=0 |
| 93 |
if(isNaN(marginLeft))marginLeft=0 |
| 94 |
offset.top+=marginTop |
| 95 |
offset.left+=marginLeft |
| 96 |
$.offset.setOffset($tip[0],$.extend({using:function(props){$tip.css({top:Math.round(props.top),left:Math.round(props.left)})}},offset),0) |
| 97 |
$tip.addClass('in') |
| 98 |
var actualWidth=$tip[0].offsetWidth |
| 99 |
var actualHeight=$tip[0].offsetHeight |
| 100 |
if(placement=='top'&&actualHeight!=height){offset.top=offset.top+height-actualHeight} |
| 101 |
var delta=this.getViewportAdjustedDelta(placement,offset,actualWidth,actualHeight) |
| 102 |
if(delta.left)offset.left+=delta.left |
| 103 |
else offset.top+=delta.top |
| 104 |
var isVertical=/top|bottom/.test(placement) |
| 105 |
var arrowDelta=isVertical?delta.left*2-width+actualWidth:delta.top*2-height+actualHeight |
| 106 |
var arrowOffsetPosition=isVertical?'offsetWidth':'offsetHeight' |
| 107 |
$tip.offset(offset) |
| 108 |
this.replaceArrow(arrowDelta,$tip[0][arrowOffsetPosition],isVertical)} |
| 109 |
Tooltip.prototype.replaceArrow=function(delta,dimension,isVertical){this.arrow().css(isVertical?'left':'top',50*(1-delta/dimension)+'%').css(isVertical?'top':'left','')} |
| 110 |
Tooltip.prototype.setContent=function(){var $tip=this.tip() |
| 111 |
var title=this.getTitle() |
| 112 |
$tip.find('.tooltip-inner')[this.options.html?'html':'text'](title) |
| 113 |
$tip.removeClass('fade in top bottom left right')} |
| 114 |
Tooltip.prototype.hide=function(callback){var that=this |
| 115 |
var $tip=$(this.$tip) |
| 116 |
var e=$.Event('hide.bs.'+this.type) |
| 117 |
function complete(){if(that.hoverState!='in')$tip.detach() |
| 118 |
if(that.$element){that.$element.removeAttr('aria-describedby').trigger('hidden.bs.'+that.type)} |
| 119 |
callback&&callback()} |
| 120 |
this.$element.trigger(e) |
| 121 |
if(e.isDefaultPrevented())return |
| 122 |
$tip.removeClass('in') |
| 123 |
$.support.transition&&$tip.hasClass('fade')?$tip.one('bsTransitionEnd',complete).emulateTransitionEnd(Tooltip.TRANSITION_DURATION):complete() |
| 124 |
this.hoverState=null |
| 125 |
return this} |
| 126 |
Tooltip.prototype.fixTitle=function(){var $e=this.$element |
| 127 |
if($e.attr('title')||typeof $e.attr('data-original-title')!='string'){$e.attr('data-original-title',$e.attr('title')||'').attr('title','')}} |
| 128 |
Tooltip.prototype.hasContent=function(){return this.getTitle()} |
| 129 |
Tooltip.prototype.getPosition=function($element){$element=$element||this.$element |
| 130 |
var el=$element[0] |
| 131 |
var isBody=el.tagName=='BODY' |
| 132 |
var elRect=el.getBoundingClientRect() |
| 133 |
if(elRect.width==null){elRect=$.extend({},elRect,{width:elRect.right-elRect.left,height:elRect.bottom-elRect.top})} |
| 134 |
var isSvg=window.SVGElement&&el instanceof window.SVGElement |
| 135 |
var elOffset=isBody?{top:0,left:0}:(isSvg?null:$element.offset()) |
| 136 |
var scroll={scroll:isBody?document.documentElement.scrollTop||document.body.scrollTop:$element.scrollTop()} |
| 137 |
var outerDims=isBody?{width:$(window).width(),height:$(window).height()}:null |
| 138 |
return $.extend({},elRect,scroll,outerDims,elOffset)} |
| 139 |
Tooltip.prototype.getCalculatedOffset=function(placement,pos,actualWidth,actualHeight){return placement=='bottom'?{top:pos.top+pos.height,left:pos.left+pos.width/2-actualWidth/2}:placement=='top'?{top:pos.top-actualHeight,left:pos.left+pos.width/2-actualWidth/2}:placement=='left'?{top:pos.top+pos.height/2-actualHeight/2,left:pos.left-actualWidth}:{top:pos.top+pos.height/2-actualHeight/2,left:pos.left+pos.width}} |
| 140 |
Tooltip.prototype.getViewportAdjustedDelta=function(placement,pos,actualWidth,actualHeight){var delta={top:0,left:0} |
| 141 |
if(!this.$viewport)return delta |
| 142 |
var viewportPadding=this.options.viewport&&this.options.viewport.padding||0 |
| 143 |
var viewportDimensions=this.getPosition(this.$viewport) |
| 144 |
if(/right|left/.test(placement)){var topEdgeOffset=pos.top-viewportPadding-viewportDimensions.scroll |
| 145 |
var bottomEdgeOffset=pos.top+viewportPadding-viewportDimensions.scroll+actualHeight |
| 146 |
if(topEdgeOffset<viewportDimensions.top){delta.top=viewportDimensions.top-topEdgeOffset}else if(bottomEdgeOffset>viewportDimensions.top+viewportDimensions.height){delta.top=viewportDimensions.top+viewportDimensions.height-bottomEdgeOffset}}else{var leftEdgeOffset=pos.left-viewportPadding |
| 147 |
var rightEdgeOffset=pos.left+viewportPadding+actualWidth |
| 148 |
if(leftEdgeOffset<viewportDimensions.left){delta.left=viewportDimensions.left-leftEdgeOffset}else if(rightEdgeOffset>viewportDimensions.right){delta.left=viewportDimensions.left+viewportDimensions.width-rightEdgeOffset}} |
| 149 |
return delta} |
| 150 |
Tooltip.prototype.getTitle=function(){var title |
| 151 |
var $e=this.$element |
| 152 |
var o=this.options |
| 153 |
title=$e.attr('data-original-title')||(typeof o.title=='function'?o.title.call($e[0]):o.title) |
| 154 |
return title} |
| 155 |
Tooltip.prototype.getUID=function(prefix){do prefix+=~~(Math.random()*1000000) |
| 156 |
while(document.getElementById(prefix)) |
| 157 |
return prefix} |
| 158 |
Tooltip.prototype.tip=function(){if(!this.$tip){this.$tip=$(this.options.template) |
| 159 |
if(this.$tip.length!=1){throw new Error(this.type+' `template` option must consist of exactly 1 top-level element!')}} |
| 160 |
return this.$tip} |
| 161 |
Tooltip.prototype.arrow=function(){return(this.$arrow=this.$arrow||this.tip().find('.tooltip-arrow'))} |
| 162 |
Tooltip.prototype.enable=function(){this.enabled=!0} |
| 163 |
Tooltip.prototype.disable=function(){this.enabled=!1} |
| 164 |
Tooltip.prototype.toggleEnabled=function(){this.enabled=!this.enabled} |
| 165 |
Tooltip.prototype.toggle=function(e){var self=this |
| 166 |
if(e){self=$(e.currentTarget).data('bs.'+this.type) |
| 167 |
if(!self){self=new this.constructor(e.currentTarget,this.getDelegateOptions()) |
| 168 |
$(e.currentTarget).data('bs.'+this.type,self)}} |
| 169 |
if(e){self.inState.click=!self.inState.click |
| 170 |
if(self.isInStateTrue())self.enter(self) |
| 171 |
else self.leave(self)}else{self.tip().hasClass('in')?self.leave(self):self.enter(self)}} |
| 172 |
Tooltip.prototype.destroy=function(){var that=this |
| 173 |
clearTimeout(this.timeout) |
| 174 |
this.hide(function(){that.$element.off('.'+that.type).removeData('bs.'+that.type) |
| 175 |
if(that.$tip){that.$tip.detach()} |
| 176 |
that.$tip=null |
| 177 |
that.$arrow=null |
| 178 |
that.$viewport=null |
| 179 |
that.$element=null})} |
| 180 |
function Plugin(option){return this.each(function(){var $this=$(this) |
| 181 |
var data=$this.data('bs.tooltip') |
| 182 |
var options=typeof option=='object'&&option |
| 183 |
if(!data&&/destroy|hide/.test(option))return |
| 184 |
if(!data)$this.data('bs.tooltip',(data=new Tooltip(this,options))) |
| 185 |
if(typeof option=='string')data[option]()})} |
| 186 |
var old=$.fn.tooltip |
| 187 |
$.fn.tooltip=Plugin |
| 188 |
$.fn.tooltip.Constructor=Tooltip |
| 189 |
$.fn.tooltip.noConflict=function(){$.fn.tooltip=old |
| 190 |
return this}}(jQuery) |