﻿(function (a, b) { a.widget("mobile.simpledialog", a.mobile.widget, { options: { pickPageTheme: "b", pickPageInputTheme: "e", pickPageButtonTheme: "a", disabled: false, zindex: "500", prompt: "Are you sure?", mode: "bool", allowReopen: true, useModal: true, forceInput: true, isOpen: false, blankMode: false, fullHTML: null, inputPassword: false, useDialogForceTrue: false, useDialogForceFalse: false, useDialog: false, isInit: false, sawOnce: false, enterToTrigger: 0, escToTrigger: 1, butObj: [], debug: false }, open: function () { if (this.options.isOpen) { return true } var j = this, c = this.options, d = a(document).width(), e = a(window).scrollTop(), g = a(window).height(), k = j.pickerContent.outerHeight(), h = j.pickerContent.innerWidth(), f = e + (g / 2) - (k / 2), i = (d / 2) - (h / 2); if ((k + f) > a(document).height()) { f = a(document).height() - (k + 2) } if (f < 45) { f = 45 } if (c.prompt !== false) { j.pickerHeader.html(c.prompt); j.pickPage.find(".ui-header").find(".ui-title").text(c.prompt) } j.pickerContent.find(".ui-btn-active").removeClass("ui-btn-active"); if (!c.disabled) { if ((d > 400 && !c.useDialogForceTrue) || c.useDialogForceFalse) { c.useDialog = false; if (c.useModal) { j.screen.fadeIn("slow") } else { j.screen.removeClass("ui-simpledialog-hidden") } j.pickerContent.addClass("ui-overlay-shadow").css("zIndex", j.options.zindex); j.pickerHeader.show(); j.pickerContent.css({ position: "absolute", top: f, left: i }).addClass("ui-overlay-shadow in").removeClass("ui-simpledialog-hidden") } else { c.useDialog = true; j.pickPageContent.append(j.pickerContent); j.pickerHeader.hide(); j.pickerContent.removeClass("ui-overlay-shadow ui-simpledialog-hidden").css({ top: "auto", left: "auto", marginLeft: "auto", marginRight: "auto" }).css("zIndex", j.options.zindex); a.mobile.changePage(j.pickPage, { transition: "pop" }) } this.options.isOpen = true } }, close: function () { var c = this; if (c.options.useDialog) { a(c.pickPage).dialog("close"); c.pickerContent.addClass("ui-simpledialog-hidden").removeAttr("style").css("zIndex", c.options.zindex); c.thisPage.append(c.pickerContent) } else { if (c.options.useModal) { c.screen.fadeOut("slow") } else { c.screen.addClass("ui-simpledialog-hidden") } c.pickerContent.addClass("ui-simpledialog-hidden").removeClass("in").removeAttr("style").css("zIndex", c.options.zindex) } c.caller.removeClass("ui-btn-active"); c.options.isOpen = false }, _create: function () { var d = this, h = a.extend(this.options, this.element.data("options")), e = this.element; if (h.isInit && h.allowReopen) { d.open() } else { var g = a(".ui-page-active"), c = a("<div data-role='dialog' class='ui-simpledialog-dialog' data-theme='" + h.pickPageTheme + "' ><div data-role='header' data-backbtn='false' data-theme='a'><div class='ui-title'>" + h.prompt + "</div></div><div data-role='content'>" + ((h.mode === "blank") ? ("<div class='ui-simpledialog-container ui-overlay-shadow ui-corner-all ui-simpledialog-hidden pop ui-body-" + h.pickPageTheme + "'>" + h.fullHTML + "</div>") : "") + "</div></div>").appendTo(a.mobile.pageContainer).page().css("minHeight", "0px").css("zIndex", h.zindex).addClass("pop"), f = c.find(".ui-content"); c.find(".ui-header a").bind("vclick", function (i) { i.preventDefault(); i.stopImmediatePropagation(); d.close(); return false }); if (h.prompt === false) { c.find(".ui-header").find(".ui-title").html("&nbsp;") } a.extend(d, { pickPage: c, thisPage: g, pickPageContent: f, screen: screen, caller: e }); d._buildPage(); d.options.isInit = true } }, refresh: function () { if (!this.options.mode === "blank") { return false } else { this.pickerContent.html(this.options.fullHTML); this.pickerContent.trigger("create") } }, _init: function () { if (!this.options.sawOnce || this.options.allowReopen) { this.options.sawOnce = true; this.open() } }, _buildPage: function () { var e = this, g = e.options, f, d, c, i = a("<div>", { "class": "ui-simpledialog-container ui-overlay-shadow ui-corner-all ui-simpledialog-hidden pop ui-body-" + g.pickPageTheme }).css("zIndex", g.zindex), h = a("<div class='ui-simpledialog-header'><h4></h4></div>").appendTo(i).find("h4"); if (g.mode !== "blank") { if (g.prompt !== false) { h.html(g.prompt) } else { h.parent().html() } if (g.mode === "string") { f = a("<div class='ui-simpledialog-controls'><input class='ui-simpledialog-input ui-input-text ui-shadow-inset ui-corner-all ui-body-" + g.pickPageInputTheme + "' type='" + ((g.inputPassword === true) ? "password" : "text") + "' name='pickin' /></div>").bind("keyup", function (j) { if (j.keyCode === 13 && g.enterToTrigger !== false) { g.butObj[g.enterToTrigger].trigger("vclick") } if (j.keyCode === 27 && g.escToTrigger !== false) { g.butObj[g.escToTrigger].trigger("vclick") } }).appendTo(i) } d = a("<div>", { "class": "ui-simpledialog-controls" }).appendTo(i); a.each(g.buttons, function (j, k) { k = a.isFunction(k) ? { click: k} : k; k = a.extend({ text: j, theme: g.pickPageButtonTheme, icon: "check", iconpos: "left" }, k); g.butObj.push(a("<a href='#'>" + j + "</a>").appendTo(d).buttonMarkup({ theme: k.theme, icon: k.icon, iconpos: k.iconpos, corners: true, shadow: true }).unbind("vclick").unbind("click").bind("vclick", function () { if (g.mode === "string") { e.caller.attr("data-string", f.find("input").val()) } k.click.apply(e.element[0], arguments); e.close() })) }) } else { i = e.pickPageContent.contents() } i.appendTo(e.thisPage); c = a("<div>", { "class": "ui-simpledialog-screen ui-simpledialog-hidden" }).css({ "z-index": g.zindex - 1 }).appendTo(e.thisPage).bind("vclick", function (j) { if (!g.forceInput) { e.close() } j.preventDefault() }); if (g.useModal) { c.addClass("ui-simpledialog-screen-modal") } a.extend(e, { pickerContent: i, pickerHeader: h, screen: c }) }, disable: function () { this.options.disabled = true }, enable: function () { this.options.disabled = false } }) })(jQuery);
