/********弹出框************/
/* var btn = [{ name: "确定", action: function () { createdialog({ type: "success", title: "成功", con: "我成功了", width: 500 }, [{ name: "成功", action: function () { createdialog({ type: "warn", title: "警告", con: "我警告你了" }, [{ name: "关闭所有", action: function () { closedialog("all") } }, { name: "关闭自己", action: function () {closedialog("self") } }]) } }, { name: "取消", action: function () { closedialog("self") } }]) } }, { name: "取消", action: function () { closedialog("all"); } }]
createdialog({ type: "warn", title: "标题", con: "这是弹出框的类容" ,height:500}, btn); */
function createdialog(wz,btn) {
//var dialogcount = $(".systemdialog").length;
var dialogcount=bndialog.searchdialog();
var id = "systemdialog" + dialogcount;
var shadeid="systemdialogshade"+dialogcount;
var style = "";
var html = "";
var str="onmousedown=dragdialog($(this),event) onmouseleave=dragdialogstop()";
if(wz.sign) //用于删除指定弹出框是用
html += "
";
else
html += "
";
if(wz.head&&wz.head=="no")//是否需要头部,默认是有头部的,no 无头部
html+="";
else
html += "
";
//html += "
";
if (wz.type == "success")
html += "
" + wz.con + "
";
else if (wz.type == "error")
html += "
" + wz.con + "
";
else if (wz.type == "warn")
html += "
" + wz.con + "
";
else if(wz.type=="edit")
html+=wz.con
else if (wz.type=="show")
html += "
" + wz.con + "
";
if(!btn||btn.length==0)
html+="";
else{
html += "";
html += "
";
}
html += "
";
if($(".systemdialogshade").length>0)
$(".systemdialogshade").remove();
//html += "
";
var broww = $(window).width();
var browh = $(window).height();
$("body").append(html);
if(wz.type!="edit"){
if (wz.width)
$("#" + id).width(wz.width);
if (wz.height)
$("#" + id).height(wz.height);
}
else if(wz.type=="edit"){
var conw=$("#"+id+" .systemdialogcontent").outerwidth()+20;
var conh=$("#"+id+" .systemdialogcontent").outerheight();
$("#"+id).outerwidth(conw);
$("#"+id).outerheight(conh);
}
var dialogw = $("#" + id).outerwidth();
var dialogh = $("#" + id).outerheight();
var left= (broww - dialogw) / 2+$(document).scrollleft();
var top = (browh - dialogh) / 2+$(document).scrolltop();
var zindex = 1000 + dialogcount+2;
var documenth = $(document).height();
//$("#"+shadeid).css({ "opacity": 0.5, "z-index": zindex-1,"height":documenth}).fadein(bndialog.showtime);
$("#" + id).css({ "left": left + "px", "top": top + "px", "z-index": zindex }).fadein(bndialog.showtime);
bndialog.createshade($("#" + id)).fadein(bndialog.showtime);
}
function closedialog (who) {
var obj = "";var n=0;
if (who == "self") {//删除自己
obj = $(".systemdialog:last");
}
else if (who == "all"||!who)//删除所有
{
obj = $(".systemdialog");
}
else{//删除指定弹出框,但是此时的遮罩不会消失
obj=who;n++;
}
if(n==0){//正常删除弹出款
bndialog.removedialog(obj,who);
//bndialog.closeshade(who);
}
else//删除指定弹出款后
obj.remove();
};
var bndialog = {
hidetime: 1000,
showtime: 1000,
createshade:function(obj){ //obj是弹出款
var idnum=obj.attr("idnum");
if(typeof idnum=="undefined"){
bndialog.removebj();return "stop";
}
var id="systemdialogshade"+idnum;
if($(".systemdialogshade").length==0);
$("body").append("
");
var zindex=parseint(obj.css("z-index")-1);
var documenth = $(document).height();
$(".systemdialogshade").css({"opacity": 0.5,"z-index":zindex,"height":documenth}).attr("id",id);;
return $("#"+id);
},
closeshade: function (who) {
var obj=$(".systemdialog:last");
bndialog.createshade(obj);
},
removebj: function () { $(".systemdialogshade").fadeout(bndialog.hidetime, function () { $(this).remove() }) },
removedialog: function (obj,who) {
if($(".systemdialog").length>1){
if(who=="self"){
obj.remove();
var obj=bndialog.createshade($(".systemdialog:last"));
if(obj=="stop")return;
else obj.show();
}
else if(who=="all"){
obj.fadeout(bndialog.hidetime, function () { $(this).remove() });
bndialog.removebj();
}
}
else if($(".systemdialog").length==1){
obj.fadeout(bndialog.hidetime, function () { $(this).remove() });
bndialog.removebj();
}
},
searchdialog:function(){
var n=0;
$(".systemdialog").each(function(index) {
var zindex=1000+index;
$(this).attr({"id":"systemdialog"+index,"idnum":index}).css("z-index",zindex);
n=index;
});
return n+1;
}
};
function systemdialogbtn(m) {
m();
}
function dragdialog(obj,e,dt){
var box=obj.closest(".systemdialog");
var divleft=parsefloat(box.offset().left);//div的left
var divtop=parsefloat(box.offset().top);//div的top
var px=parsefloat(e.clientx);//鼠标坐标x
var py=parsefloat(e.clienty);//鼠标坐标y
var mdx=px-divleft;//鼠标到div做边框的距离
var mdy=py-divtop;//鼠标到div顶部的距离
var divw=box.width();//div的宽度
var divh=box.height();//div的高度
var scrolltop=$(document).scrolltop();
var scrollleft=$(document).scrollleft();
var documenth=$(document).height();
var documentw=$(document).width();
var winw=$(window).width();
var winh=$(window).height();
$(document).bind("mousemove",function(e){
var x=parsefloat(e.clientx);//鼠标x
var y=parsefloat(e.clienty);//鼠标y
var bjh=$("#dialogbodybj").height();
var bjw=$("#dialogbodybj").width();
var divr=divw-mdx+x;//div右边的x坐标
var divb=divh-mdy+y;//div底部的y坐标
var scrolltopm=$(document).scrolltop();
var scrollleftm=$(document).scrollleft();
var newx=x-mdx-(scrollleft-scrollleftm);
var newy=y-mdy-(scrolltop-scrolltopm);
box.css({"top":newy,"left":newx});
});
}
function dragdialogstop()
{$(document).unbind("mousemove");}
$(document).mouseup(function(){$(this).unbind("mousemove");});