7 lines
6.5 KiB
JavaScript
7 lines
6.5 KiB
JavaScript
/**************************************************************************************
|
|
* jQuery MsgBox 0.8.1
|
|
* by composite (ukjinplant@msn.com)
|
|
* http://blog.hazard.kr
|
|
* This project licensed under a MIT License.
|
|
**************************************************************************************/;
|
|
!function (a) { window.console || (window.console = {}, window.console.log = a.noop); var b = "fixed", c = "div", d = "keypress", e = "resize", f = "msgbox-", g = "." + f, h = f + "-style", i = "button", j = "click", k = !1, m = function (b) { return a(document.createElement(b)) }, n = function (a, b) { if (!n.once || b) { a = a || {}; var c = n.style ? n.style : n.style = m("style").addClass(h).attr("type", "text/css"), d = []; for (var e in a) if (a[e]) { var f = a[e]; d.push(g + e), d.push("{"); for (var i in f) if (k) switch (i) { case "opacity": d.push("filter:alpha(opacity=" + (100 * +("." == f[i].substring(0, 1) ? "0" + f[i] : f[i]) || 100) + ");"); break; default: d.push(i + ":" + f[i] + ";") } else d.push(i + ":" + f[i] + ";"); d.push("}") } c.each(function () { var a = d.join(""); k ? this.styleSheet.cssText = a : this.innerHTML = a }).appendTo("head"), n.once = !0 } }; a.msgbox = function (b, l) { l = a.extend({}, a.msgbox.options, l), a(h).length || n(a.msgbox.css); var o = {}, p = f + "ok", q = f + "no", r = "password", t = (l.css || {}, !0), u = !1, v = l.input !== !1 && void 0 != l.input && null != l.input, w = !!l.confirm, x = function () { setTimeout(function () { var b = a(document.activeElement), c = [g + "input", g + i]; b.length && (b.is(c[0]) || b.is(c[1])) || z.find(c + "").eq(0).focus() }, 0) }, y = a(window), z = m(c).addClass(f + "container").append(m(c).addClass(f + "ui").addClass(f + (v ? "prompt" : w ? "confirm" : "alert"))).children(), A = m(c).addClass(f + "modal"), B = m(c).addClass(f + "msg").html(b).appendTo(z), C = v ? a("<div><input type='" + (l[r] ? r : "text") + "'/></div>").addClass(f + "inbox").children().addClass(f + "input").bind("keydown", function (a) { var b = a.which; if (9 == b && a.shiftKey) a.preventDefault(), z.find(g + i).filter(":last").focus(); else switch (b) { case 13: return a.preventDefault(), z.find(i + "." + p).trigger(j), !1; case 27: a.preventDefault(), z.find(i + "." + (v || w ? q : p)).trigger(j) } }).bind("blur", x).end().appendTo(z) : null, D = m(c).addClass(f + "buttons").appendTo(z), E = m(i).addClass(f + i).bind("keydown", function (b) { if (this == document.activeElement) { b.stopPropagation(); var e, c = b.which, d = a(this), f = b.shiftKey; switch (c) { case 9: case 39: b.preventDefault(), e = d[9 == c && f ? "prev" : "next"](i), e.length ? e.focus() : 9 == c && (e = z.find(g + "input"), e.length ? e.select() : (e = d[f ? "next" : "prev"](i), e.length && e.focus())); break; case 37: b.preventDefault(), e = d.prev(i), e.length && e.focus(); break; case 27: b.preventDefault(), z.find(i + "." + (v || w ? q : p)).trigger(j) } } }).bind("blur", x);[E.clone(t).addClass(p).text(w ? l.yes : l.ok).appendTo(D), v || w ? E.clone(t).addClass(q).text(l.no).appendTo(D) : null], z.add(A).bind("keydown", function () { }), a.extend(z[0], { container: z.parent()[0], modal: A[0], msg: B[0], inbox: C ? C[0] : null, buttons: D[0] }), v && (l.confirm = t, l.input !== !0 && C.children().val(l.input)), y.bind(e, o[e] = function () { o.firstWidth || (o.firstUnder = !0, o.firstWidth = z.outerWidth()), y.width() - 20 <= o.firstWidth, a.isFunction(l.onresize) ? l.onresize.call(z[0], o) : a.isFunction(a.msgbox.onresize) && a.msgbox.onresize.call(z[0], o) }), o.before = function (a) { a.stopPropagation(); var b = window.event ? window.event.keyCode : a.which; if ("text" == a.target.type && !b) return z.find(i + "." + (v || w ? q : p)).trigger(j), u; switch (b) { case 13: return z.find(i + ":focus").trigger("click"), u; case 27: return z.find(i + "." + (v || w ? q : p)).trigger(j), u } }; var H = a(document.documentElement || document.body).append(A).append(z.parent()).bind(d, o.before); o.after = function (b, c) { var f = a(b).hasClass(p); switch (t) { case v: l.submit.call(z[0], f ? c : null); break; case w: l.submit.call(z[0], f); break; default: l.submit.call(z[0]) } H.unbind(d, o.before), y.unbind(e, o[e]) }, z.delegate(i, j, function () { var c = function () { z.parent().add(A).remove() }, d = l.onclose || a.msgbox.onclose; o.after(this, v ? C.children().val() : null), a.isFunction(d) ? a.when(d.call(z[0], v ? I.children().val() : a(this).hasClass(p))).always(c) : c() }); var J = function () { y.trigger(e), v ? z.find("input:text").select() : z.find(i + ":eq(0)").focus(); var b = l.onopen || a.msgbox.onopen; a.isFunction(b) && b.call(z[0], l) }; return k ? setTimeout(J, 0) : J(), z }, a.extend(a.msgbox, { strings: { ok: "OK", yes: "OK", no: "Cancel" }, css: { container: { position: b, left: "50%", top: "32%", "z-index": "9001" }, ui: { border: "1px solid black", font: "9pt verdana,gulim,sans-serif", "background-color": "white", position: "relative", left: "-50%", top: "32%", overflow: "hidden", "float": "right" }, modal: { position: b, left: "0", top: "0", right: "0", bottom: "0", "background-color": "black", opacity: ".4", "z-index": "9000" }, msg: { padding: "2em 4em", overflow: "hidden", "font-family": "verdana,gulim,sans-serif", "white-space": "pre-wrap", "word-wrap": "break-word" }, buttons: { padding: "1em", "background-color": "#eee", "text-align": "right", overflow: "hidden" }, button: { width: "72px", margin: "auto .25em" }, inbox: { width: "90%", margin: "-1em auto 1em", border: "1px inset #3D7BAD" }, input: { width: "99%", display: "block", border: "0" } }, onresize: function (b) { var c = a(this), d = c.parent(); b.firstWidth || (b.firstUnder = !0, b.firstWidth = c.outerWidth()); var e = a(window).width() - 20 <= b.firstWidth; e && !b.isOver ? (b.isOver = !0, d.css({ left: "10px", right: "10px", "margin-top": ~~(.32 * -c.outerHeight()) + "px", "min-width": "" }), c.css({ position: "static" })) : (!e && b.isOver || b.firstUnder) && (b.firstUnder = !1, b.isOver = !1, d.css({ left: "", right: "", "margin-top": ~~(.32 * -c.outerHeight()) + "px", "min-width": b.firstWidth + "px" }), c.css({ position: "" })) } }), a.msgbox.options = { submit: function () { }, confirm: !1, ok: a.msgbox.strings.ok, yes: a.msgbox.strings.yes, no: a.msgbox.strings.no }, a.alert = function (b, c) { return a.msgbox(b, { submit: c }) }, a.confirm = function (b, c) { return a.msgbox(b, { confirm: !0, submit: c }) }, a.prompt = function (b, c, d, e) { var f = a.isFunction(c); return a.msgbox(b, { input: f ? !0 : c, submit: f ? c : d, password: f ? d : e }) } }(jQuery); |