/*! * 主 题:《页面弹出窗口》 * 说 明:用于子页面弹出时的窗口。 * 功能描述: * 1、生成弹出窗口,窗口内包括iframe控件,用于加载实际控制页面; * 2、窗口弹出时,生成背景遮罩; * 3、窗口最小为宽高100,小于等于100时,宽高值默认为浏览器窗口的百分比; * * * 作 者:宋雷鸣 * 开发时间: 2016年12月28日 */ (function () { function pagebox(title, page, width, height, id, patwin) { this.Init(title, page, width, height, id, patwin); } pagebox.version = "1.1"; //版本号 pagebox.prototype.Parent = null; //上级窗体 pagebox.prototype.IsDrag = false; //是否允许拖动 pagebox.prototype.CloseEvent = null; //窗口关闭时的事件 pagebox.prototype.FullScreenEvent = function () { $("html").css("overflow", "hidden"); }; pagebox.prototype.WinScreenEvent = function (box) { if (Number(box.attr("wdper")) == 100 && Number(box.attr("hgper")) == 100) $("html").css("overflow", "auto"); }; //初始化参数 pagebox.prototype.Init = function (title, page, width, height, winid, patwin) { if (width == 100 & height == 100) { if (this.FullScreenEvent != null) this.FullScreenEvent(); } //屏幕的宽高 var hg = $(window).height(); var wd = $(window).width(); this.Title = title != null && title != "" ? title : " "; //如果为空,则为浏览器窗口一半宽高 width = width != null && width != 0 && width != "" ? Number(width) : wd / 2; height = height != null && height != 0 && height != "" ? Number(height) : hg / 2; //如果宽高小于100,则默认为浏览器窗口的百分比 this.Wdper = width > 100 ? width / wd * 100 : width; //宽度百分比 this.Hgper = height > 100 ? height / hg * 100 : height; //宽度百分比 this.Width = width > 100 ? Number(width) : Math.floor(wd * Number(width) / 100); this.Height = height > 100 ? Number(height) : Math.floor(hg * Number(height) / 100); this.WinId = winid != null ? winid : new Date().getTime() + "_" + Math.floor(Math.random() * 1000 + 1); this.Page = pagebox.getCurrPath(patwin, page); //上级窗体 if (patwin != null) this.Parent = pagebox.getParent(patwin); } //获取父窗口(iframe对象) pagebox.getParent = function (winname) { var winbox = $(".PageBox[winid=" + winname + "]", window.top.document); return winbox; } //获取当前窗体对象 //winname:当前iframe名称,如果为空值,则取最上层的活动窗口 pagebox.getPagebox = function (winname) { if (winname != null) { var box = $(".PageBox[winid=" + winname + "]"); return box; } //取最上层的活动窗口 var boxs = $(".PageBox[winid]"); if (boxs.size() < 1) return null; var topbox = boxs.first(); boxs.each(function (box) { var zindex = Number($(this).css("z-index")); var tindex = Number(topbox.css("z-index")); if (zindex > tindex) topbox = $(this); }) return topbox; } //设置窗口位置 //box:窗口对象 pagebox.setPostion = function (box, left, top) { if (left == null) left = ($(window).width() - box.outerWidth()) / 2; if (top == null) top = ($(window).height() - box.outerHeight()) / 2; left = left < 0 ? 0 : left; top = top < 0 ? 0 : top; box.css({ top: top, left: left }); //如果有父窗口 var parent = $(".PageBox[winid='" + window.name + "']"); if (parent != null && parent.size() > 0) { box.attr({ "parent": parent.attr("winid") }); if (!(parent.attr("wdper") == "100" && parent.attr("hgper") == "100")) { var off = parent.offset(); box.css({ top: off.top + 50, left: off.left + 50 }); } } //计算位置信息,并记录到窗体上 pagebox.coordinate(box); } //获取父窗口的window对象 //winname:当前窗体的名称 pagebox.parentWindow = function (winname) { var box = pagebox.getParent(winname); if (box.size() > 0) box = pagebox.getParent(box.attr("parent")); var iframe = box.find("iframe"); var win = null if (iframe.size() > 0) win = iframe.get(0).contentWindow; return win; } //获取父路径 pagebox.getParentPath = function (winname) { if (winname == null || winname == "") return ""; var winbox = $(".PageBox[winid=" + winname + "]", window.top.document); var iframe = null; if (winbox.size() > 0) { iframe = winbox.find("iframe"); } else { iframe = $("iframe[name=" + winname + "]"); } var path = ""; if (iframe.size() > 0) { path = iframe.get(0).contentWindow.location.href; } else { path = window.top.location.href; } path = path.indexOf("?") ? path.substring(0, path.lastIndexOf("?") + 1) : ""; path = path.indexOf("/") ? path.substring(0, path.lastIndexOf("/") + 1) : ""; return path; } //获取当前要打开的路径 pagebox.getCurrPath = function (winname, page) { if (winname == null || winname == "") return page; var patpath = pagebox.getParentPath(winname); if ($.trim(patpath) == "") return page; var path = page; if (new RegExp("[a-zA-z]+://[^\s]*").exec(page)) return page; if (new RegExp("^[{\\\/\#]").exec(page)) return page; return patpath + path; } //创建窗口,并打开 pagebox.prototype.Open = function (title, page, width, height, winId) { //生成窗口 this.maskOpen(); //打开遮罩层 this.buildFrame(); //创建窗体 pagebox.coordinate(this.WinId); //计算坐标相对窗体的比例 //设置拖动 if (this.IsDrag && !(this.Wdper == 100 && this.Hgper)) { var box = $(".PageBox[winid='" + this.WinId + "']"); if (box.size() > 0) { try { box.easydrag().setHandler(".PageBoxTitle") .ondrag(function () { $(".PageBoxIframeMask").show().width(box.width()).height(box.height() - 60); }).ondrop(function (d) { $(".PageBoxIframeMask").hide(); var winid = $(d.target).parents(".PageBox").attr("winid"); var position = pagebox.coordinate(winid); //当窗体移出可视化区域,设置到屏幕中央 if ((position.left > position.winwd || position.left + box.width() <= 0) || (position.top > position.winhg || position.top <= 0)) { pagebox.setPostion(position.box); } //alert("top:" + position.top + ",left:" + position.left+",win_wd:"+position.winwd) }); } catch (e) { } } } //关闭事件,全屏事件 if (this.CloseEvent != null) pagebox.events.add(this.WinId + "_CloseEvent", this.CloseEvent); if (this.FullScreenEvent != null) pagebox.events.add(this.WinId + "_FullScreenEvent", this.FullScreenEvent); if (this.WinScreenEvent != null) pagebox.events.add(this.WinId + "_WinScreenEvent", this.WinScreenEvent); //$("html").css("overflow", "hidden"); } //生成窗体外框 pagebox.prototype.buildFrame = function () { //屏幕的宽高 var hg = $(window).height(); var wd = $(window).width(); $("body").append("
"); var boxframe = $(".PageBox[winid=" + this.WinId + "]"); boxframe.attr({ "wdper": this.Wdper, "hgper": this.Hgper }); var border = parseInt(boxframe.css("border-width")); //窗体边线宽度 border = !isNaN(border) ? border : 0; boxframe.css({ position: "fixed", "width": this.Width - 8, "height": this.Height - 8 }); pagebox.setPostion(boxframe); //设置窗口的位置 //如果有父窗口 if (this.Parent != null && this.Parent.size() > 0) { boxframe.attr({ "parent": this.Parent.attr("winid") }); if (!(this.Parent.attr("wdper") == "100" && this.Parent.attr("hgper") == "100")) { var off = this.Parent.offset(); boxframe.css({ top: off.top + 50, left: off.left + 50 }); } } //设置层深 var index = parseInt($(".screenMask[winid=" + this.WinId + "]").css("z-index")); boxframe.css({ "z-index": index + 1 }); //设置标题 boxframe.append(""); var titbox = boxframe.find(".PageBoxTitle"); titbox.append("