/*
jQuery.msgBox plugin
Copyright 2011, Halil İbrahim Kalyoncu
License: BSD
modified by Oliver Kopp, 2012.
* added support for configurable image paths
* a new msgBox can be shown within an existing msgBox
*/
/*
contact :
halil@ibrahimkalyoncu.com
koppdev@googlemail.com
*/
// users may change this variable to fit their needs
var msgBoxImagePath = "../Images/";
jQuery.msgBox = msg;
function msg(options) {
var isShown = false;
var typeOfValue = typeof options;
var defaults = {
content: (typeOfValue == "string" ? options : "Message"),
title: "Warning",
type: "alert",
autoClose: false,
timeOut: 0,
showButtons: true,
buttons: [{ value: "Ok"}],
inputs: [{ type: "text", name: "userName", header: "User Name" }, { type: "password", name: "password", header: "Password"}],
success: function (result) { },
beforeShow: function () { },
afterShow: function () { },
beforeClose: function () { },
afterClose: function () { },
opacity: 0.1
};
options = typeOfValue == "string" ? defaults : options;
if (options.type != null) {
switch (options.type) {
case "alert":
options.title = options.title == null ? "Warning" : options.title;
break;
case "info":
options.title = options.title == null ? "Information" : options.title;
break;
case "error":
options.title = options.title == null ? "Error" : options.title;
break;
case "confirm":
options.title = options.title == null ? "Confirmation" : options.title;
options.buttons = options.buttons == null ? [{ value: "Yes" }, { value: "No" }, { value: "Cancel"}] : options.buttons;
break;
case "prompt":
options.title = options.title == null ? "Log In" : options.title;
options.buttons = options.buttons == null ? [{ value: "Login" }, { value: "Cancel"}] : options.buttons;
break;
default:
image = "../Images/alert.png";
}
}
options.timeOut = options.timeOut == null ? (options.content == null ? 500 : options.content.length * 70) : options.timeOut;
//JD
//options = $.extend(defaults, options);
options = $.extend({}, defaults, options);
if (options.autoClose) {
setTimeout(hide, options.timeOut);
}
var image = "";
switch (options.type) {
case "alert":
image = "../Images/alert.png";
break;
case "info":
image = "../Images/info.png";
break;
case "error":
image = "../Images/error.png";
break;
case "confirm":
image = "../Images/confirm.png";
break;
default:
image = "../Images/alert.png";
}
var divId = "msgBox" + new Date().getTime();
//JD
/* i was testing with ($.browser.msie && parseInt($.browser.version, 10) === 7) but $.browser.msie is not working with jQuery 1.9.0 :S. Alternative method: */
if (navigator.userAgent.match(/msie/i) && navigator.userAgent.match(/6/)) { var divMsgBoxContentClass = "msgBoxContentIEOld"; } else { var divMsgBoxContentClass = "msgBoxContent"; }
var divMsgBoxId = divId;
var divMsgBoxContentId = divId + "Content";
var divMsgBoxImageId = divId + "Image";
var divMsgBoxButtonsId = divId + "Buttons";
var divMsgBoxBackGroundId = divId + "BackGround";
var buttons = "";
$(options.buttons).each(function (index, button) {
buttons += "";
});
var inputs = "";
$(options.inputs).each(function (index, input) {
var type = input.type;
if (type == "checkbox" || type == "radiobutton") {
inputs += "
" +
"" +
"" + input.header + "" +
"
";
}
else {
inputs += "
" +
"" + input.header + "" +
"" +
"
";
}
});
//JD
//var divBackGround = "";
var divBackGround = "";
var divTitle = "
" + options.title + "
";
var divInputs = "
" + inputs + "
";
var divContainer = "
" + options.content + "
";
var divButtons = "
" + buttons + "
";
var divMsgBox;
var divMsgBoxContent;
var divMsgBoxImage;
var divMsgBoxButtons;
var divMsgBoxBackGround;
if (options.type == "prompt") {
// $("html").append(divBackGround + "