Popup.js
var Popup = function (mask) {
// Class to wrap jQuery UI dialog for common use.
// Create the dialog.
var form = $(mask);
form.dialog({ autoOpen: false, modal: true, resizable: false });
var closing = false; // Hack to disable dialog X close without using CSS hack.
function options(handlers, option) {
// Tie in event hanlders and merge other options.
return $.extend(
{
buttons: [{
text: Popup.Strings.OK,
click: function () {
if (handlers.ok) handlers.ok();
close();
}
},
{
text: Popup.Strings.Cancel,
click: function () {
if (handlers.cancel) handlers.cancel();
close();
}
}],
beforeClose: function () {
return closing;
}
}, option);
};
function show(handlers, option) {
// Setup dialog and open it.
// Other items like title can be passed in the option parameter.
closing = false;
form.dialog("option", options(handlers, option));
form.dialog("open");
};
function close() {
// Close dialog.
closing = true;
form.dialog("close");
};
// Return this interface.
return {
show: show,
close: close
};
};
Popup.Strings = { New: "New", Edit: "Edit", OK: "OK", Cancel: "Cancel" };