magix-components
Version:
1 lines • 2.04 kB
JavaScript
define("mx-popover/index",["magix","$"],function(e,t,_){var o=e("magix"),c=e("$");o.applyStyle("y",".em{border-radius:4px;padding:0;-webkit-box-shadow:0 6px 8px rgba(51,51,51,.08);box-shadow:0 6px 8px rgba(51,51,51,.08);position:absolute;border:1px solid rgba(0,0,0,.1);display:none;max-width:276px;background-color:#fff}.en{line-height:22px;padding:9px 14px}");var i;_.exports=o.View.extend({tmpl:{html:'<div class="en"><%!$$.content%></div>',subs:[]},init:function(e){var t=this;t.__I=e.placement||"right",t.__J=e.align,t.__cR=e.content||"",t.__cW=0|e.width,t.on("destroy",function(){t.__h.off("mouseenter mouseleave"),t.__cV&&t.__cV.off("mouseenter mouseleave").remove()})},render:function(){var e=this;e.endUpdate();var t=c("#"+e.id);e.__h=t,t.hover(function(){e.__cX(),e.__cY=setTimeout(e.wrapAsync(function(){e.__e()}),100)},function(){clearTimeout(e.__cY),e.__a()})},__cX:function(){var e=this;if(!e.__cV){var t="popover_"+e.id;e.__h.after('<div class="em" id="'+t+'" />'),e.updater.to(t),e.updater.digest({content:e.__cR}),e.__cV=c("#"+t),e.__cW&&e.__cV.css({"max-width":e.__cW,width:e.__cW}),e.__cV.hover(function(){clearTimeout(e.__cY)},function(){e.__a()})}},content:function(e){var t=this;if(!e)return t.__cR;t.__cV?(t.__cR=e,t.updater.digest({content:e})):t.__cR=e},__e:function(){var e=this;i&&i!=e&&i.__cZ(),i=e,clearTimeout(e.__cY);var t=e.__cV,_=e.__h,o=_.offset(),c=_.outerWidth(),a=_.outerHeight();t.css({display:"block"});var n,r,s=t.outerWidth(),p=t.outerHeight();switch(e.__I){case"top":n=o.left-(s-c)/2,r=o.top-p-10;break;case"right":n=o.left+c+10,r=o.top-(p-a)/2;break;case"bottom":n=o.left-(s-c)/2,r=o.top+a+10;break;case"left":n=o.left-s-10,r=o.top-(p-a)/2}switch(e.__J){case"top":r=o.top;break;case"left":n=o.left;break;case"right":n=o.left-s+c;break;case"bottom":r=o.top-p+a}t.offset({left:n,top:r})},__a:function(){var e=this;clearTimeout(e.__cY),e.__cY=setTimeout(e.wrapAsync(function(){e.__cV.css({display:"none"})}),50)},__cZ:function(){var e=this;clearTimeout(e.__cY),e.__cV.css({display:"none"})}})});