Repository navigation
Expand file tree
/
Copy pathbootstrap-twipsy-mod.js
More file actions
1 lines (1 loc) · 5.94 KB
/
Copy pathbootstrap-twipsy-mod.js
File metadata and controls
1 lines (1 loc) · 5.94 KB
1
!function($){"use strict";var _windowHasFocus,transitionEnd;$(window).focus(function _onWindowGainedFocus(){_windowHasFocus=!0}).blur(function _onWindowLostFocus(){_windowHasFocus=!1}),$(document).ready(function(){$.support.transition=function(){var transitionEnd=function(){var el=document.createElement("bootstrap"),transEndEventNames={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd",msTransition:"MSTransitionEnd",transition:"transitionend"},name;for(name in transEndEventNames)if(void 0!==el.style[name])return transEndEventNames[name]}();return transitionEnd&&{end:transitionEnd}}(),$.support.transition&&(transitionEnd=$.support.transition.end)});var Twipsy=function(element,options){this.$element=$(element),this.options=options,this.enabled=!0,this.autoHideTimeout=null,this.fixTitle()};function maybeCall(thing,ctx,args){return"function"==typeof thing?thing.apply(ctx,args):thing}Twipsy.prototype={show:function(){var $tip,that=this;if(this.hasContent()&&this.enabled){if($tip=this.tip(),this.setContent(),this.options.animate&&$tip.addClass("fade"),$tip.remove().css({top:0,left:0,display:"block"}).prependTo(document.body),this.updatePosition(),$(window).off("resize",this.resizeHandler),this.resizeHandler=function(e){that.updatePosition()},$(window).on("resize",this.resizeHandler),this.options.autoHideDelay){var startAutoHide=function(){window.clearTimeout(that.autoHideTimeout),that.autoHideTimeout=window.setTimeout(function(){that.hide()},that.options.autoHideDelay)};_windowHasFocus?startAutoHide():$(window).one("focus",startAutoHide)}$tip.addClass("in")}},updatePosition:function(){var pos,actualWidth,actualHeight,paddingLeft,paddingRight,surplusRight,shiftArrow,placement,$tip,$arrow,tp,that=this;switch($tip=this.tip(),pos=$.extend({},this.$element.offset(),{width:this.$element[0].offsetWidth,height:this.$element[0].offsetHeight}),paddingLeft=parseInt(this.$element.css("padding-left"),10),paddingRight=parseInt(this.$element.css("padding-right"),10),pos.left+=paddingLeft,pos.width-=paddingLeft+paddingRight,actualWidth=$tip[0].offsetWidth,actualHeight=$tip[0].offsetHeight,placement=maybeCall(this.options.placement,this,[$tip[0],this.$element[0]]),$tip.addClass(placement),placement){case"below":tp={top:pos.top+pos.height+this.options.offset,left:pos.left+pos.width/2-actualWidth/2};break;case"above":tp={top:pos.top-actualHeight-this.options.offset,left:pos.left+pos.width/2-actualWidth/2};break;case"left":tp={top:pos.top+pos.height+20-actualHeight,left:pos.left-actualWidth-this.options.offset};break;case"right":tp={top:pos.top+pos.height+20-actualHeight,left:pos.left+pos.width+this.options.offset}}shiftArrow=0,(surplusRight=tp.left+actualWidth-$(document.body).width())>0?(shiftArrow=surplusRight,tp.left-=surplusRight):tp.left<0&&(shiftArrow=tp.left,tp.left=0),surplusRight>0&&($arrow=$tip.find(".tooltip-arrow"),this.defaultMargin||(this.defaultMargin=parseInt($arrow.css("margin-left"),10)),$arrow.css("margin-left",this.defaultMargin+shiftArrow)),$tip.css(tp)},setContent:function(){var $tip=this.tip();$tip.find(".tooltip-inner")[this.options.html?"html":"text"](this.getTitle()),$tip[0].className="tooltip"},hide:function(){var that=this,$tip=this.tip();function removeElement(){$tip.remove()}$tip.removeClass("in"),$.support.transition&&this.$tip.hasClass("fade")?$tip.bind(transitionEnd,removeElement):removeElement(),window.clearTimeout(this.autoHideTimeout),$(window).off("resize",this.resizeHandler)},fixTitle:function(){var $e=this.$element;($e.attr("title")||"string"!=typeof $e.attr("data-original-title"))&&$e.attr("data-original-title",$e.attr("title")||"").removeAttr("title")},hasContent:function(){return this.getTitle()},getTitle:function(){var title,$e=this.$element,o=this.options;return this.fixTitle(),"string"==typeof o.title?title=$e.attr("title"==o.title?"data-original-title":o.title):"function"==typeof o.title&&(title=o.title.call($e[0])),(title=(""+title).replace(/(^\s*|\s*$)/,""))||o.fallback},tip:function(){return this.$tip=this.$tip||$('<div class="tooltip" />').html(this.options.template)},validate:function(){this.$element[0].parentNode||(this.hide(),this.$element=null,this.options=null)},enable:function(){this.enabled=!0},disable:function(){this.enabled=!1},toggleEnabled:function(){this.enabled=!this.enabled},toggle:function(){this[this.tip().hasClass("in")?"hide":"show"]()}},$.fn.twipsy=function(options){return $.fn.twipsy.initWith.call(this,options,Twipsy,"twipsy"),this},$.fn.twipsy.initWith=function(options,Constructor,name){var twipsy,binder,eventIn,eventOut;if(!0===options)return this.data(name);if("string"==typeof options)return(twipsy=this.data(name))&&twipsy[options](),this;function get(ele){var twipsy=$.data(ele,name);return twipsy||(twipsy=new Constructor(ele,$.fn.twipsy.elementOptions(ele,options)),$.data(ele,name,twipsy)),twipsy}function enter(){var twipsy=get(this);twipsy.hoverState="in",0==options.delayIn?twipsy.show():(twipsy.fixTitle(),setTimeout(function(){"in"==twipsy.hoverState&&twipsy.show()},options.delayIn))}function leave(){var twipsy=get(this);twipsy.hoverState="out",0==options.delayOut?twipsy.hide():setTimeout(function(){"out"==twipsy.hoverState&&twipsy.hide()},options.delayOut)}return(options=$.extend({},$.fn[name].defaults,options)).live||this.each(function(){get(this)}),"manual"!=options.trigger&&(binder=options.live?"live":"bind",eventIn="hover"==options.trigger?"mouseenter":"focus",eventOut="hover"==options.trigger?"mouseleave":"blur",this[binder](eventIn,enter)[binder](eventOut,leave)),this},$.fn.twipsy.Twipsy=Twipsy,$.fn.twipsy.defaults={animate:!0,delayIn:0,delayOut:0,fallback:"",placement:"above",html:!1,live:!1,offset:0,title:"title",trigger:"hover",template:'<div class="tooltip-arrow"></div><div class="tooltip-inner"></div>'},$.fn.twipsy.rejectAttrOptions=["title"],$.fn.twipsy.elementOptions=function(ele,options){for(var data=$(ele).data(),rejects=$.fn.twipsy.rejectAttrOptions,i=rejects.length;i--;)delete data[rejects[i]];return $.extend({},options,data)}}(window.jQuery||window.ender);