1
|
(function(a){if(typeof module!=="undefined"&&typeof exports=="object"){if(typeof window!="undefined"){module.exports=a()}else{module.exports=a}}else{window.Popover=a()}})(function(){var d=function(g,h){h=h||{};this.isIE=(new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})").exec(navigator.userAgent)!=null)?parseFloat(RegExp.$1):false;this.link=typeof g==="object"?g:document.querySelector(g);this.title=this.link.getAttribute("data-title")||null;this.content=this.link.getAttribute("data-content")||null;this.popover=null;this.options={};this.options.template=h.template?h.template:null;this.options.trigger=h.trigger?h.trigger:"hover";this.options.animation=h.animation&&h.animation!=="true"?h.animation:"true";this.options.placement=h.placement?h.placement:"top";this.options.delay=parseInt(h.delay)||100;this.options.dismiss=h.dismiss&&h.dismiss==="true"?true:false;this.duration=150;this.options.duration=(this.isIE&&this.isIE<10)?0:(h.duration||this.duration);this.options.container=document.body;if(this.content||this.options.template){this.init()}this.timer=0;this.rect=null};d.prototype={init:function(){this.actions();var g=("onmouseleave" in this.link)?["mouseenter","mouseleave"]:["mouseover","mouseout"];if(this.options.trigger==="hover"){this.link.addEventListener(g[0],this.open,false);if(!this.options.dismiss){this.link.addEventListener(g[1],this.close,false)}}else{if(this.options.trigger==="click"){this.link.addEventListener("click",this.toggle,false);if(!this.options.dismiss){this.link.addEventListener("blur",this.close,false)}}else{if(this.options.trigger==="focus"){this.link.addEventListener("focus",this.toggle,false);if(!this.options.dismiss){this.link.addEventListener("blur",this.close,false)}}}}if(this.options.dismiss){document.addEventListener("click",this.dismiss,false)}if(!(this.isIE&&this.isIE<9)){window.addEventListener("resize",this.close,false)}},actions:function(){var g=this;this.toggle=function(h){if(g.popover===null){g.open()}else{g.close()}},this.open=function(h){clearTimeout(g.link.getAttribute("data-timer"));g.timer=setTimeout(function(){if(g.popover===null){g.createPopover();g.stylePopover();g.updatePopover()}},g.options.duration);g.link.setAttribute("data-timer",g.timer)},this.dismiss=function(h){if(g.popover&&h.target===g.popover.querySelector(".close")){g.close()}},this.close=function(h){clearTimeout(g.link.getAttribute("data-timer"));g.timer=setTimeout(function(){if(g.popover&&g.popover!==null&&/in/.test(g.popover.className)){g.popover.className=g.popover.className.replace(" in","");setTimeout(function(){g.removePopover()},g.options.duration)}},g.options.delay+g.options.duration);g.link.setAttribute("data-timer",g.timer)},this.removePopover=function(){this.popover&&this.options.container.removeChild(this.popover);this.popover=null;this.timer=null},this.createPopover=function(){this.popover=document.createElement("div");if(this.content!==null&&this.options.template===null){this.popover.setAttribute("role","tooltip");var h=document.createElement("div");h.setAttribute("class","arrow");if(this.title!==null){var j=document.createElement("h3");j.setAttribute("class","popover-title");if(this.options.dismiss){j.innerHTML=this.title+'<button type="button" class="close">×</button>'}else{j.innerHTML=this.title}this.popover.appendChild(j)}var i=document.createElement("div");i.setAttribute("class","popover-content");this.popover.appendChild(h);this.popover.appendChild(i);if(this.options.dismiss&&this.title===null){i.innerHTML=this.content+'<button type="button" class="close">×</button>'}else{i.innerHTML=this.content}}else{var k=document.createElement("div");k.innerHTML=this.options.template;this.popover.innerHTML=k.firstChild.innerHTML}this.options.container.appendChild(this.popover);this.popover.style.display="block"},this.stylePopover=function(l){this.rect=this.getRect();var k=l||this.options.placement;var h=this.options.animation==="true"?"fade":"";this.popover.setAttribute("class","popover "+k+" "+h);var i={w:this.link.offsetWidth,h:this.link.offsetHeight};var j=this.popoverDimensions(this.popover);var o={w:j.w,h:j.h};var n=this.getScroll().y;var m=this.getScroll().x;if(/top/.test(k)){this.popover.style.top=this.rect.top+n-o.h+"px";this.popover.style.left=this.rect.left+m-o.w/2+i.w/2+"px"}else{if(/bottom/.test(k)){this.popover.style.top=this.rect.top+n+i.h+"px";this.popover.style.left=this.rect.left+m-o.w/2+i.w/2+"px"}else{if(/left/.test(k)){this.popover.style.top=this.rect.top+n-o.h/2+i.h/2+"px";this.popover.style.left=this.rect.left+m-o.w+"px"}else{if(/right/.test(k)){this.popover.style.top=this.rect.top+n-o.h/2+i.h/2+"px";this.popover.style.left=this.rect.left+m+i.w+"px"}}}}},this.updatePopover=function(){var h=null;if(!g.isElementInViewport(g.popover)){h=g.updatePlacement()}else{h=g.options.placement}g.stylePopover(h);g.popover.className+=" in"},this.updatePlacement=function(){var h=this.options.placement;if(/top/.test(h)){return"bottom"}else{if(/bottom/.test(h)){return"top"}else{if(/left/.test(h)){return"right"}else{if(/right/.test(h)){return"left"}}}}},this.getRect=function(){return this.link.getBoundingClientRect()},this.getScroll=function(){return{y:window.pageYOffset||document.documentElement.scrollTop,x:window.pageXOffset||document.documentElement.scrollLeft}},this.popoverDimensions=function(h){return{w:h.offsetWidth,h:h.offsetHeight}},this.isElementInViewport=function(i){var h=i.getBoundingClientRect();return(h.top>=0&&h.left>=0&&h.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&h.right<=(window.innerWidth||document.documentElement.clientWidth))}}};var e=document.querySelectorAll("[data-toggle=popover]"),a=0,f=e.length;for(a;a<f;a++){var b=e[a],c={};c.trigger=b.getAttribute("data-trigger");c.animation=b.getAttribute("data-animation");c.duration=b.getAttribute("data-duration");c.placement=b.getAttribute("data-placement");c.dismiss=b.getAttribute("data-dismiss");c.delay=b.getAttribute("data-delay");new d(b,c)}return d});
|