var $=require("jquery"),layer=require("./../../layer/layer.js"),layerCss=require("./../../layer/layer.css"),Util=require("./util.js"),Dialog={device:"pc",loadingOn:function(e){if(e=e||null){var t=layer.open({type:1,content:'<div style="padding:10px;height:32px;box-sizing:content-box;"><div class="layui-layer-ico16" style="display:inline-block;margin-right:10px;"></div><div style="display:inline-block;line-height:32px;vertical-align:top;font-size:13px;">'+e+"</div></div>",shade:[.3,"#000"],closeBtn:!1,title:!1,area:["auto","auto"]});$("#layui-layer"+t).attr("type","loading")}else layer.load(2)},loadingOff:function(){layer.closeAll("loading")},tipSuccess:function(e){var t=2e3;e&&e.length>10&&(t=1e3*parseInt(e.length/5)),layer.msg(e,{shade:.3,time:t,shadeClose:!0,anim:-1})},tipError:function(e){var t=2e3;e.length>10&&(t=1e3*parseInt(e.length/5)),layer.msg(e,{shade:.3,time:t,shadeClose:!0,anim:6})},tipPopoverShow:function(e,t){var i=$(e).data("popover-dialog");i&&layer.close(i),i=layer.tips(t,e,{tips:[1,"#333"]}),$(e).data("popover-dialog",i)},tipPopoverHide:function(e){var t=$(e).data("popover-dialog");t&&layer.close(t)},alertSuccess:function(e,t){layer.alert(e,{icon:1,closeBtn:0},function(e){layer.close(e),t&&t()});try{document.activeElement.blur();var i=$("#layui-layer"+index),l=i.find(".layui-layer-btn0");l.attr("tabindex",0).css({outline:"none"}).get(0).focus(),i.on("keypress",function(){l.click()})}catch(e){}},alertError:function(e,t){var i=layer.alert(e,{icon:2,closeBtn:0},function(e){layer.close(e),t&&t()});try{document.activeElement.blur();var l=$("#layui-layer"+i),n=l.find(".layui-layer-btn0");n.attr("tabindex",0).css({outline:"none"}).get(0).focus(),l.on("keypress",function(){n.click()})}catch(e){}return i},confirm:function(e,t,i,l){l=l||{icon:3,title:"提示"},t=t||!1,i=i||!1,layer.confirm(e,l,function(e){layer.close(e),t&&t()},function(e){layer.close(e),i&&i()})},dialog:function(e,t){var i=$.extend({title:null,width:"600px",height:"80%",shadeClose:!0,closeCallback:function(){}},t);return/^\d+px$/.test(i.width)&&$(window).width()<parseInt(i.width)&&(i.width="90%",i.height="90%"),layer.open({type:2,title:"正在加载...",shadeClose:i.shadeClose,shade:.5,maxmin:!1,area:[i.width,i.height],scrollbar:!1,content:e,success:function(e,t){if(null!==i.title)return void layer.title(i.title,t);try{var l=$(e).find("iframe")[0].contentWindow.document.title;layer.title(l,t)}catch(e){}},end:function(){i.closeCallback()}})},dialogContent:function(e,t){var i=$.extend({closeBtn:!0,width:"auto",height:"auto",shade:[.3,"#000"],shadeClose:!0,openCallback:function(){},closeCallback:function(){}},t);return layer.open({shade:i.shade,type:1,title:!1,zindex:2019,closeBtn:i.closeBtn,shadeClose:i.shadeClose,scrollbar:!1,content:e,area:[i.width,i.height],success:function(){i.openCallback()},end:function(){i.closeCallback()}})},dialogClose:function(e){layer.close(e)},dialogCloseAll:function(){layer.closeAll()},input:function(e,t){var i=$.extend({label:"请输入",width:"200px",height:"auto",defaultValue:""},t);/^\d+px$/.test(i.width)&&$(window).width()<parseInt(i.width)&&(i.width=$(window).width()-20+"px");var l=i.defaultValue,n=!1,a=Dialog.dialogContent(['<div id="dialog-input-box" style="width:',i.width,";height:",i.height,';background:#FFF;border-radius:3px;">','<div style="padding:10px 10px 0 10px;">',i.label,"</div>",'<div style="padding:10px;"><input type="text" style="border:1px solid #CCC;height:30px;line-height:30px;padding:0 5px;width:100%;display:block;box-sizing:border-box;outline:none;border-radius:2px;" value="',Util.specialchars(i.defaultValue),'" /></div>','<div style="cursor:pointer;padding:10px;text-align:center;color:#40AFFE;line-height:20px;border-top:1px solid #EEE;cursor:default;" class="ok">确定</div>',"</div>"].join(""),{openCallback:function(){$("#dialog-input-box").find(".ok").on("click",function(){n=!0,Dialog.dialogClose(a)}),$("#dialog-input-box").find("input").on("change",function(){l=$(this).val()})},closeCallback:function(){n&&e&&e(l)}})}};module.exports=Dialog;