﻿(function (a) { a.prompt = function (p, q) { q = a.extend({}, a.prompt.defaults, q); a.prompt.currentPrefix = q.prefix; var e = (a.browser.msie && a.browser.version < 7); var g = a(document.body); var c = a(window); q.classes = a.trim(q.classes); if (q.classes != "") { q.classes = " " + q.classes } var b = '<div class="' + q.prefix + "box" + q.classes + '" id="' + q.prefix + 'box">'; if (q.useiframe && ((a("object, applet").length > 0) || e)) { b += '<iframe src="javascript:false;" style="display:block;position:absolute;z-index:-1;" class="' + q.prefix + 'fade" id="' + q.prefix + 'fade"></iframe>' } else { if (e) { a("select").css("visibility", "hidden") } b += '<div class="' + q.prefix + 'fade" id="' + q.prefix + 'fade"></div>' } b += '<div class="' + q.prefix + '" id="' + q.prefix + '"><div class="' + q.prefix + 'container"><div class="'; b += q.prefix + 'close">X</div>'; b += '<div class="' + q.prefix + 'top_curve"></div><div id="' + q.prefix + 'states"></div><div class="' + q.prefix + 'bottom_curve"></div>'; b += "</div></div></div>"; var o = a(b).appendTo(g); var l = o.children("#" + q.prefix); var m = o.children("#" + q.prefix + "fade"); if (p.constructor == String) { p = { state0: { html: p, buttons: q.buttons, focus: q.focus, submit: q.submit}} } var n = ""; a.each(p, function (s, r) { r = a.extend({}, a.prompt.defaults.state, r); p[s] = r; n += '<div id="' + q.prefix + "_state_" + s + '" class="' + q.prefix + '_state" style="display:none;"><div class="' + q.prefix + 'message">' + r.html + '</div><div class="' + q.prefix + 'buttons">'; a.each(r.buttons, function (u, t) { if (typeof t == "object") { n += '<button name="' + q.prefix + "_" + s + "_button" + t.title.replace(/[^a-z0-9]+/gi, "") + '" id="' + q.prefix + "_" + s + "_button" + t.title.replace(/[^a-z0-9]+/gi, "") + '" value="' + t.value + '">' + t.title + "</button>" } else { n += '<button name="' + q.prefix + "_" + s + "_button" + u + '" id="' + q.prefix + "_" + s + "_button" + u + '" value="' + t + '">' + u + "</button>" } }); n += "</div></div>" }); l.find("#" + q.prefix + "states").html(n).children("." + q.prefix + "_state:first").css("display", "block"); l.find("." + q.prefix + "buttons:empty").css("display", "none"); a.each(p, function (t, s) { var r = l.find("#" + q.prefix + "_state_" + t); r.children("." + q.prefix + "buttons").children("button").click(function () { var x = r.children("." + q.prefix + "message"); var v = s.buttons[a(this).text()]; if (v == undefined) { for (var u in s.buttons) { if (s.buttons[u].title == a(this).text()) { v = s.buttons[u].value } } } if (typeof v == "object") { v = v.value } var y = {}; a.each(l.find("#" + q.prefix + "states :input").serializeArray(), function (z, A) { if (y[A.name] === undefined) { y[A.name] = A.value } else { if (typeof y[A.name] == Array || typeof y[A.name] == "object") { y[A.name].push(A.value) } else { y[A.name] = [y[A.name], A.value] } } }); var w = s.submit(v, x, y); if (w === undefined || w) { d(true, v, x, y) } }); r.find("." + q.prefix + "buttons button:eq(" + s.focus + ")").addClass(q.prefix + "defaultbutton") }); var f = function () { o.css({ top: c.scrollTop() }) }; var j = function () { if (q.persistent) { var s = 0; o.addClass(q.prefix + "warning"); var r = setInterval(function () { o.toggleClass(q.prefix + "warning"); if (s++ > 1) { clearInterval(r); o.removeClass(q.prefix + "warning") } }, 100) } else { d() } }; var h = function (u) { var t = (window.event) ? event.keyCode : u.keyCode; if (t == 27) { j() } if (t == 9) { var v = a(":input:enabled:visible", o); var s = !u.shiftKey && u.target == v[v.length - 1]; var r = u.shiftKey && u.target == v[0]; if (s || r) { setTimeout(function () { if (!v) { return } var w = v[r === true ? v.length - 1 : 0]; if (w) { w.focus() } }, 10); return false } } }; var i = function () { o.css({ position: (e) ? "absolute" : "fixed", height: c.height(), width: "100%", top: (e) ? c.scrollTop() : 0, left: 0, right: 0, bottom: 0 }); m.css({ position: "absolute", height: c.height(), width: "100%", top: 0, left: 0, right: 0, bottom: 0 }); l.css({ position: "absolute", top: q.top, left: "50%", marginLeft: ((l.outerWidth() / 2) * -1) }) }; var k = function () { m.css({ zIndex: q.zIndex, display: "none", opacity: q.opacity }); l.css({ zIndex: q.zIndex + 1, display: "none" }); o.css({ zIndex: q.zIndex }) }; var d = function (t, s, u, r) { l.remove(); if (e) { g.unbind("scroll", f) } c.unbind("resize", i); m.fadeOut(q.overlayspeed, function () { m.unbind("click", j); m.remove(); if (t) { q.callback(s, u, r) } o.unbind("keypress", h); o.remove(); if (e && !q.useiframe) { a("select").css("visibility", "visible") } }) }; i(); k(); if (e) { c.scroll(f) } m.click(j); c.resize(i); o.bind("keydown keypress", h); l.find("." + q.prefix + "close").click(d); m.fadeIn(q.overlayspeed); l[q.show](q.promptspeed, q.loaded); l.find("#" + q.prefix + "states ." + q.prefix + "_state:first ." + q.prefix + "defaultbutton").focus(); if (q.timeout > 0) { setTimeout(a.prompt.close, q.timeout) } return o }; a.prompt.defaults = { prefix: "jqi", classes: "", buttons: { Ok: true }, loaded: function () { }, submit: function () { return true }, callback: function () { }, opacity: 0.6, zIndex: 999, overlayspeed: "slow", promptspeed: "fast", show: "fadeIn", focus: 0, useiframe: false, top: "1%", persistent: true, timeout: 0, state: { html: "", buttons: { Ok: true }, focus: 0, submit: function () { return true } } }; a.prompt.currentPrefix = a.prompt.defaults.prefix; a.prompt.setDefaults = function (b) { a.prompt.defaults = a.extend({}, a.prompt.defaults, b) }; a.prompt.setStateDefaults = function (b) { a.prompt.defaults.state = a.extend({}, a.prompt.defaults.state, b) }; a.prompt.getStateContent = function (b) { return a("#" + a.prompt.currentPrefix + "_state_" + b) }; a.prompt.getCurrentState = function () { return a("." + a.prompt.currentPrefix + "_state:visible") }; a.prompt.getCurrentStateName = function () { var b = a.prompt.getCurrentState().attr("id"); return b.replace(a.prompt.currentPrefix + "_state_", "") }; a.prompt.goToState = function (b, c) { a("." + a.prompt.currentPrefix + "_state").slideUp("slow"); a("#" + a.prompt.currentPrefix + "_state_" + b).slideDown("slow", function () { a(this).find("." + a.prompt.currentPrefix + "defaultbutton").focus(); if (typeof c == "function") { c() } }) }; a.prompt.nextState = function (c) { var b = a("." + a.prompt.currentPrefix + "_state:visible").next(); a("." + a.prompt.currentPrefix + "_state").slideUp("slow"); b.slideDown("slow", function () { b.find("." + a.prompt.currentPrefix + "defaultbutton").focus(); if (typeof c == "function") { c() } }) }; a.prompt.prevState = function (c) { var b = a("." + a.prompt.currentPrefix + "_state:visible").prev(); a("." + a.prompt.currentPrefix + "_state").slideUp("slow"); b.slideDown("slow", function () { b.find("." + a.prompt.currentPrefix + "defaultbutton").focus(); if (typeof c == "function") { c() } }) }; a.prompt.close = function () { a("#" + a.prompt.currentPrefix + "box").fadeOut("fast", function () { a(this).remove() }) }; a.fn.prompt = function (b) { if (b == undefined) { b = {} } if (b.withDataAndEvents == undefined) { b.withDataAndEvents = false } a.prompt(a(this).clone(b.withDataAndEvents).html(), b) } })(jQuery);
