bootstrap-tooltip-extended.min.js 2.42 KB
/*!
 * bootstrap-tooltip-extended.js v1.0.0
 * Copyright 2016 Cyril Rezé
 * Licensed under the MIT license
 */
!function(t){"use strict";var e=t.fn.tooltip.Constructor.VERSION?t.fn.tooltip.Constructor.VERSION.split(".")[0]:"2",o=t.fn.tooltip,i=function(t,e){this.init("tooltip",t,e)};i.prototype=t.extend({},o.Constructor.prototype,{constructor:i,show:function(){var o,i,s,n,r,l,p=t.Event("show");if(this.hasContent()&&this.enabled){if(this.$element.trigger(p),p.isDefaultPrevented())return;o=this.tip(),this.setContent(),this.options.animation&&o.addClass("fade"),r="function"==typeof this.options.placement?this.options.placement.call(this,o[0],this.$element[0]):this.options.placement;var a=/\s?auto-dir?\s?/i,h=a.test(r);h&&(r=r.replace(a,"")||"top"),o.detach().css({top:0,left:0,display:"block"}).addClass(r),this.options.container?o.appendTo(this.options.container):o.insertAfter(this.$element),i=this.getPosition(),s=o[0].offsetWidth,n=o[0].offsetHeight;var f="rtl"===jQuery(document.querySelector("html")).attr("dir")?!0:!1;if(h){var c=r,d=r.replace(/bottom-|top-/g,"")||"",g=r.replace(/left|right/g,"")||"";r="left"==d&&f?g+"right":"right"==d&&f?g+"left":r,o.removeClass(c).addClass(r)}switch(r){case"bottom":l={top:i.top+i.height,left:i.left+i.width/2-s/2};break;case"top":l={top:i.top-n,left:i.left+i.width/2-s/2};break;case"left":l={top:i.top+i.height/2-n/2,left:i.left-s};break;case"right":l={top:i.top+i.height/2-n/2,left:i.left+i.width};break;case"bottom-left":l={top:i.top+i.height,left:i.left};break;case"bottom-right":l={top:i.top+i.height,left:i.left+i.width-s};break;case"top-left":l={top:i.top-n,left:i.left};break;case"top-right":l={top:i.top-n,left:i.left+i.width-s}}this.applyPlacement(l,r),"3"===e&&this.newArrow(r,s,f),this.$element.trigger("shown")}},newArrow:function(t,e,o){var i=this.tip().find(".tooltip-arrow"),s=parseInt(i.css("width"),10),n=parseInt(i.css("height"),10),r=t.replace(/bottom-|top-/g,"")||"",l=t.replace(/left|right/g,"")||"";l&&"left"==r&&!o&&i.css("left",s/2),l&&"left"==r&&o&&i.css("right",e-s-s/2),l&&"right"==r&&i.css("left",e-s-s/2),"bottom-"==l&&i.css("top",n),"top-"==l&&i.css("bottom",n)}});var s=t.fn.tooltip;t.fn.tooltip=t.extend(function(e){return this.each(function(){var o=t(this),s=o.data("tooltip"),n=t.extend({},i.defaults,o.data(),"object"==typeof e&&e);s||o.data("tooltip",s=new i(this,n)),"string"==typeof e&&s[e]()})},t.fn.tooltip),t.fn.tooltip.noConflict=function(){return t.fn.tooltip=s,this}}(window.jQuery);