UNPKG

magix-components

Version:
1 lines 4.74 kB
define("mx-dialog/index",["magix","$","./alert","./confirm"],function(i,o,t){var e=i("magix");i("./alert"),i("./confirm"),e.applyStyle("i",".bE{position:absolute}.bF{position:relative;background-color:#fff;border-radius:4px;border:1px solid #e6e6e6}.bG{position:absolute;-webkit-appearance:none;-moz-appearance:none;appearance:none;padding:0;margin:13px 15px 0 0;cursor:pointer;background:transparent;border:0;float:right;font-size:21px;font-weight:700;line-height:1;color:#000;text-shadow:0 1px 0 #fff;filter:alpha(opacity=20);opacity:.2;z-index:1041;top:16px;right:10px;margin:0}.bG:focus,.bG:hover{color:#000;text-decoration:none;cursor:pointer;filter:alpha(opacity=50);opacity:.5}.bH{font-size:22px;font-weight:400}.bI{position:fixed;top:0;right:0;left:0;bottom:0;background-color:#000;filter:alpha(opacity=50);opacity:.5;display:none;z-index:1039}.bJ{-webkit-filter:blur(3px);filter:blur(3px)}.bK{-webkit-animation:b .3s;animation:b .3s;-webkit-animation-fill-mode:forwards;animation-fill-mode:forwards}.bL{position:absolute;right:10px;top:0;width:1px;height:0}.bM{padding:80px 0}@-webkit-keyframes b{0%{opacity:0}to{opacity:.5}}@keyframes b{0%{opacity:0}to{opacity:.5}}.bN{-webkit-animation:c .2s;animation:c .2s;-webkit-animation-fill-mode:forwards;animation-fill-mode:forwards}@-webkit-keyframes c{0%{opacity:.5}to{opacity:0}}@keyframes c{0%{opacity:.5}to{opacity:0}}.bO{margin-bottom:50px;min-height:60px}.bP{position:fixed;width:100%;height:100%;overflow:auto;left:0;top:0}.bQ{-webkit-animation:d .3s;animation:d .3s;-webkit-animation-fill-mode:forwards;animation-fill-mode:forwards}@-webkit-keyframes d{0%{margin-top:-50px;opacity:0}to{margin-top:0;opacity:1}}@keyframes d{0%{margin-top:-50px;opacity:0}to{margin-top:0;opacity:1}}.bR{-webkit-animation:e .2s;animation:e .2s;-webkit-animation-fill-mode:forwards;animation-fill-mode:forwards}@-webkit-keyframes e{0%{margin-top:0;opacity:1}to{margin-top:-50px;opacity:0}}@keyframes e{0%{margin-top:0;opacity:1}to{margin-top:-50px;opacity:0}}");var a=i("$"),n=a(window),r=500,d=[],s=function(i){for(var o=d.length-1;o>=0;o--)if(d[o].id==i.id){d.splice(o,1);break}};t.exports=e.View.extend({tmpl:{html:'<div class="bI bK" style="display: block;z-index:<%=$$.zIndex-1%>" id="mask_<%=$$.viewId%>"></div><div class="bP" style="z-index:<%=$$.zIndex%>"><div class="bE bQ" data-spm-protocol="i" id="body_<%=$$.viewId%>" style="left:<%=$$.left%>px;top:<%=$$.top%>px;width:<%=$$.width%>px"><input id="focus_<%=$$.viewId%>" class="bL"><button type="button" mx-click="__am()" class="bG <%=$$.closable?\'\':\'af\'%>"><span class="_ bH">&#xe67f;</span></button><div class="bF bO" id="cnt_<%=$$.viewId%>"><div class="aA bM"><span class="aB"></span></div></div></div></div>',subs:[]},init:function(i){var o=this,t=a("#app");o.on("destroy",function(){s(o),500==(r-=2)&&t.removeClass("bJ"),a("#"+o.id).trigger("close").remove()}),e.has(i,"closable")||(i.closable=!0),o.updater.set(i),500==r&&t.addClass("bJ"),r+=2,d.push(o)},render:function(){var i=this,o=i.updater,t=o.get();o.set({zIndex:r,viewId:i.id}).digest(),a("#"+i.id).show(),a("#focus_"+i.id).focus(),i.owner.mountVframe("cnt_"+i.id,t.view,t),setTimeout(i.wrapAsync(function(){a("#body_"+i.id).removeClass("bQ"),a("#mask_"+i.id).removeClass("bK")}),300)},__al:function(i){e.Vframe.get("cnt_"+this.id).invoke("fire",["unload",i])},"__am<click>":function(){a("#"+this.id).trigger("dlg_close")},"$doc<keyup>":function(i){if(27==i.keyCode){var o=d[d.length-1];o==this&&o.updater.get("closable")&&a("#"+o.id).trigger("dlg_close")}}},{__an:function(i,o){var t=e.guid("dlg_");a(document.body).append('<div id="'+t+'" style="display:none" />');var n,r=i.owner.mountVframe(t,"mx-dialog/index",o),d=a("#"+t);return d.on("dlg_close",function(){if(!d.data("closing")&&!n){var o=function(){d.data("closing",1),a("#body_"+t).addClass("bR"),a("#mask_"+t).addClass("bN"),setTimeout(function(){i.owner&&i.owner.unmountVframe(t)},200)},e={prevent:function(){n=1},resolve:function(){e.p=1,n=0,o()},reject:function(){e.p=1,n=0}};r.invoke("__al",e),n||e.p||o()}})},alert:function(i,o,t){this.confirm(i,o,null,t,"alert")},confirm:function(i,o,t,e,a){this.mxDialog("mx-dialog/"+(a||"confirm"),{body:i,cancelCallback:t,enterCallback:o,title:e,modal:!0,width:400,closable:!1,left:(n.width()-400)/2,top:Math.max((n.height()-220)/2,0)})},mxDialog:function(i,o){var t,a,r=this,d={view:i};return e.use(i,r.wrapAsync(function(s){var l="$dlg_"+i;r[l]||(r[l]=1,e.mix(d,s.dialogOptions),e.mix(d,o),d.width||(d.width=500),d.left||(d.left=(n.width()-d.width)/2),d.top||(d.top=100),d.dialog={close:function(){t&&t.trigger("dlg_close")}},(t=r.__an(r,d)).on("close",function(){delete r[l],a&&a()}))})),{close:function(){t&&t.trigger("dlg_close")},whenClose:function(i){a=i}}}})});