(f=>{function s(t,e){this.type=this.options=this.enabled=this.timeout=this.hoverState=this.$element=null,this.init("bsf_tooltip",t,e)}s.DEFAULTS={animation:!0,placement:"top",selector:!1,template:'<div class="bsf_tooltip"><div class="bsf_tooltip-arrow"></div><div class="bsf_tooltip-inner"></div></div>',trigger:"hover focus",title:"",delay:0,html:!1,container:!1},s.prototype.init=function(t,e,i){this.enabled=!0,this.type=t,this.$element=f(e),this.options=this.getOptions(i);var o=this.options.trigger.split(" ");for(let t=o.length;t--;){var s,n=o[t];"click"==n?this.$element.on("click."+this.type,this.options.selector,f.proxy(this.toggle,this)):"manual"!=n&&(s="hover"==n?"mouseleave":"focusout",this.$element.on(("hover"==n?"mouseenter":"focusin")+"."+this.type,this.options.selector,f.proxy(this.enter,this)),this.$element.on(s+"."+this.type,this.options.selector,f.proxy(this.leave,this)))}this.options.selector?this._options=f.extend({},this.options,{trigger:"manual",selector:""}):this.fixTitle()},s.prototype.getDefaults=function(){return s.DEFAULTS},s.prototype.getOptions=function(t){return(t=f.extend({},this.getDefaults(),this.$element.data(),t)).delay&&"number"==typeof t.delay&&(t.delay={show:t.delay,hide:t.delay}),t},s.prototype.getDelegateOptions=function(){let i={},o=this.getDefaults();return this._options&&f.each(this._options,function(t,e){o[t]!=e&&(i[t]=e)}),i},s.prototype.enter=function(t){let e=t instanceof this.constructor?t:f(t.currentTarget)[this.type](this.getDelegateOptions()).data("bs."+this.type);if(clearTimeout(e.timeout),e.hoverState="in",!e.options.delay||!e.options.delay.show)return e.show();e.timeout=setTimeout(function(){"in"==e.hoverState&&e.show()},e.options.delay.show)},s.prototype.leave=function(t){let e=t instanceof this.constructor?t:f(t.currentTarget)[this.type](this.getDelegateOptions()).data("bs."+this.type);if(clearTimeout(e.timeout),e.hoverState="out",!e.options.delay||!e.options.delay.hide)return e.hide();e.timeout=setTimeout(function(){"out"==e.hoverState&&e.hide()},e.options.delay.hide)},s.prototype.show=function(){var i=f.Event("show.bs."+this.type);if(this.hasContent()&&this.enabled&&(this.$element.trigger(i),!i.isDefaultPrevented())){let t=this;i=this.tip();this.setContent(),this.options.animation&&i.addClass("fade");let e="function"==typeof this.options.placement?this.options.placement.call(this,i[0],this.$element[0]):this.options.placement;var o,s,n=/\s?auto?\s?/i,l=n.test(e),n=(l&&(e=e.replace(n,"")||"top"),i.detach().css({top:0,left:0,display:"block"}).addClass(e),this.options.container?i.appendTo(this.options.container):i.insertAfter(this.$element),this.getPosition()),r=i[0].offsetWidth,p=i[0].offsetHeight,h=(l&&(l=this.$element.parent(),o=e,a=document.documentElement.scrollTop||document.body.scrollTop,s="body"==this.options.container?window.innerWidth:l.outerWidth(),h="body"==this.options.container?window.innerHeight:l.outerHeight(),l="body"==this.options.container?0:l.offset().left,e="bottom"==e&&n.top+n.height+p-a>h?"top":"top"==e&&n.top-a-p<0?"bottom":"right"==e&&n.right+r>s?"left":"left"==e&&n.left-r<l?"right":e,i.removeClass(o).addClass(e)),this.getCalculatedOffset(e,n,r,p)),a=(this.applyPlacement(h,e),this.hoverState=null,function(){t.$element.trigger("shown.bs."+t.type)});f.support.transition&&this.$tip.hasClass("fade")?i.one(f.support.transition.end,a).emulateTransitionEnd(150):a()}},s.prototype.applyPlacement=function(e,t){let i,o=this.tip();var s=o[0].offsetWidth,n=o[0].offsetHeight;let l=parseInt(o.css("margin-top"),10),r=parseInt(o.css("margin-left"),10),p=(isNaN(l)&&(l=0),isNaN(r)&&(r=0),e.top=e.top+l,e.left=e.left+r,f.offset.setOffset(o[0],f.extend({using(t){o.css({top:Math.round(t.top),left:Math.round(t.left)})}},e),0),o.addClass("in"),o[0].offsetWidth),h=o[0].offsetHeight;if("top"==t&&h!=n&&(i=!0,e.top=e.top+n-h),/bottom|top/.test(t)){let t=0;e.left<0&&(t=-2*e.left,e.left=0,o.offset(e),p=o[0].offsetWidth,h=o[0].offsetHeight),this.replaceArrow(t-s+p,p,"left")}else this.replaceArrow(h-n,h,"top");i&&o.offset(e)},s.prototype.replaceArrow=function(t,e,i){this.arrow().css(i,t?50*(1-t/e)+"%":"")},s.prototype.setContent=function(){var t=this.tip(),e=this.getTitle();t.find(".bsf_tooltip-inner")[this.options.html?"html":"text"](e),t.removeClass("fade in top bottom left right")},s.prototype.hide=function(){let t=this,e=this.tip();var i=f.Event("hide.bs."+this.type);function o(){"in"!=t.hoverState&&e.detach(),t.$element.trigger("hidden.bs."+t.type)}if(this.$element.trigger(i),!i.isDefaultPrevented())return e.removeClass("in"),f.support.transition&&this.$tip.hasClass("fade")?e.one(f.support.transition.end,o).emulateTransitionEnd(150):o(),this.hoverState=null,this},s.prototype.fixTitle=function(){var t=this.$element;!t.attr("title")&&"string"==typeof t.attr("data-original-title")||t.attr("data-original-title",t.attr("title")||"").attr("title","")},s.prototype.hasContent=function(){return this.getTitle()},s.prototype.getPosition=function(){var t=this.$element[0];return f.extend({},"function"==typeof t.getBoundingClientRect?t.getBoundingClientRect():{width:t.offsetWidth,height:t.offsetHeight},this.$element.offset())},s.prototype.getCalculatedOffset=function(t,e,i,o){return"bottom"==t?{top:e.top+e.height,left:e.left+e.width/2-i/2}:"top"==t?{top:e.top-o,left:e.left+e.width/2-i/2}:"left"==t?{top:e.top+e.height/2-o/2,left:e.left-i}:{top:e.top+e.height/2-o/2,left:e.left+e.width}},s.prototype.getTitle=function(){var t=this.$element,e=this.options;return t.attr("data-original-title")||("function"==typeof e.title?e.title.call(t[0]):e.title)},s.prototype.tip=function(){return this.$tip=this.$tip||f(this.options.template)},s.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".bsf_tooltip-arrow")},s.prototype.validate=function(){this.$element[0].parentNode||(this.hide(),this.$element=null,this.options=null)},s.prototype.enable=function(){this.enabled=!0},s.prototype.disable=function(){this.enabled=!1},s.prototype.toggleEnabled=function(){this.enabled=!this.enabled},s.prototype.toggle=function(t){t=t?f(t.currentTarget)[this.type](this.getDelegateOptions()).data("bs."+this.type):this;t.tip().hasClass("in")?t.leave(t):t.enter(t)},s.prototype.destroy=function(){clearTimeout(this.timeout),this.hide().$element.off("."+this.type).removeData("bs."+this.type)};let t=f.fn.bsf_tooltip;f.fn.bsf_tooltip=function(o){return this.each(function(){var t=f(this);let e=t.data("bs.bsf_tooltip");var i="object"==typeof o&&o;!e&&"destroy"==o||(e||t.data("bs.bsf_tooltip",e=new s(this,i)),"string"!=typeof o)||e[o]()})},f.fn.bsf_tooltip.Constructor=s,f.fn.bsf_tooltip.noConflict=function(){return f.fn.bsf_tooltip=t,this},f("[id^=ubtn-]").bsf_tooltip(),f('ul[data-placement=""]').bsf_tooltip("hide")})(jQuery);