var dlgAlert = function(msg, opts) { if (typeof opts != "object") opts = {}; var optsd = { background: "#eee", borderRadius: 5, btnCloseBR: 5, btnCloseCap: "Close", btnCloseWidth: 150, textAlign: "left", fontColor: "#000", fontSize: 14, headerBgColor: "#fff", headerFontClr: "#000", headerFontSize: 16, headerFontWeight: "bold", headerHeight: 40, headerPadX: 10, headerPadY: 0, headerTextAlign: "left", height: 200, paddingX: 10, paddingY: 10, shaderColor: "#333", shaderOpacity: 0.5, shaddow: "", title: "Alert", width: 300 }; for (var c in optsd) { if (!optsd.hasOwnProperty(c)) continue; if (typeof opts[c] == "undefined") opts[c] = optsd[c]; } /* сделать проверку входящих opts */ var d = {}; d.main = document.createElement("DIV"); d.main.style.fontSize = ("" + opts.fontSize + "px"); d.main.style.fontFamily = "Tahoma, Arial, Helvetica, 'Helvetica Neue', 'Lucida Grande', Verdana, sans-serif"; d.main.style.fontStyle = "normal"; d.main.style.fontWeight = "normal"; d.main.style.lineHeight = "normal"; d.main.style.textAlign = "left"; d.inner = document.createElement("DIV"); d.inner.style.position = "absolute"; d.inner.style.left = "0"; d.inner.style.right = "0"; d.inner.style.top = "0"; d.inner.style.bottom = "0"; d.inner.style.zIndex = 2147483500; d.inner.style.overflow = "hidden"; d.main.appendChild(d.inner); d.shad = document.createElement("DIV"); d.shad.style.position = "fixed"; d.shad.style.left = "0"; d.shad.style.right = "0"; d.shad.style.top = "0"; d.shad.style.bottom = "0"; d.shad.style.background = opts.shaderColor; d.shad.style.opacity = opts.shaderOpacity; d.shad.style.zIndex = "-1"; d.inner.appendChild(d.shad); d.cont = document.createElement("DIV"); d.cont.style.position = "fixed"; d.cont.style.width = "100%"; d.cont.style.height = "100%"; d.cont.style.textAlign = "center"; d.inner.appendChild(d.cont); d.vsp = document.createElement("DIV"); d.vsp.style.display = "inline-block"; d.vsp.style.height = "100%"; d.vsp.style.width = "0"; d.vsp.style.verticalAlign = "middle"; d.cont.appendChild(d.vsp); d.box = document.createElement("DIV"); d.box.style.display = "inline-block"; d.box.style.width = "" + opts.width + "px"; d.box.style.height = "" + opts.height + "px"; if (opts.borderRadius) { d.box.style.borderRadius = "" + opts.borderRadius + "px"; } d.box.style.verticalAlign = "middle"; d.box.style.background = opts.background; d.box.style.overflow = "hidden"; d.cont.appendChild(d.box); d.header = document.createElement("DIV"); d.header.style.height = "" + opts.headerHeight - (2 * opts.headerPadY) + "px"; d.header.style.width = "" + (opts.width - opts.headerPadX * 2) + "px"; d.header.style.padding = "" + opts.headerPadY + "px " + opts.headerPadX + "px"; d.header.style.lineHeight = d.header.style.height; d.header.style.fontSize = opts.headerFontSize; d.header.style.fontWeight = opts.headerFontWeight; d.header.style.color = opts.headerFontClr; d.header.style.background = opts.headerBgColor; d.header.style.textAlign = opts.headerTextAlign; d.header.innerHTML = opts.title; d.box.appendChild(d.header); d.body = document.createElement("DIV"); d.body.style.height = "" + opts.height - (opts.headerHeight * 2 + opts.paddingY * 2) + "px"; d.body.style.width = "" + (opts.width - opts.paddingX * 2) + "px"; d.body.style.padding = "" + opts.paddingY + "px " + opts.paddingX + "px"; d.body.style.textAlign = opts.textAlign; d.body.innerHTML = msg; d.box.appendChild(d.body); d.btnWrap = document.createElement("DIV"); d.btnWrap.style.height = "" + (opts.headerHeight - opts.paddingY) + "px"; d.btnWrap.style.width = "" + opts.width + "px"; d.btnWrap.style.padding = "0 0 " + opts.paddingY + "px 0"; d.btnWrap.style.textAlign = "center"; d.box.appendChild(d.btnWrap); d.btnClose = document.createElement("BUTTON"); d.btnClose.style.margin = "0"; d.btnClose.style.padding = "0"; d.btnClose.style.outline = "0"; d.btnClose.style.cursor = "pointer"; d.btnClose.innerHTML = opts.btnCloseCap; d.btnClose.style.border = "1px solid #bcbcbc"; if (opts.btnCloseBR) d.btnClose.style.borderRadius = "" + opts.btnCloseBR + "px"; d.btnClose.style.fontSize = "" + opts.fontSize + "px"; d.btnClose.style.width = "" + (opts.btnCloseWidth - 2) + "px"; d.btnClose.style.height = "" + (opts.headerHeight - opts.paddingY - 2) + "px"; d.btnClose.style.lineHeight = d.btnClose.style.height; d.btnClose.setAttribute("onclick", "document.body.removeChild(this.parentNode.parentNode.parentNode.parentNode.parentNode)"); d.btnWrap.appendChild(d.btnClose); document.body.appendChild(d.main); return d; };