内建对话框-CarlZeng

用法 var a=new NLAlertDialog(‘”NLAlertDialog”‘); a.show(‘title’,’sMessage’,3) ———————————————————————- function hideAlertBox(elemId) { document.getElement…

用法 var a=new NLAlertDialog(‘”NLAlertDialog”‘);

a.show(‘title’,’sMessage’,3)

———————————————————————-

function hideAlertBox(elemId)
{
document.getElementById(elemId).style.display=’none’;
}

function getAlertBoxHtml(sTitle, sMessage, iType, width, helpUrl, helpText)
{
if (iType != NLAlertDialog.TYPE_LOWEST_PRIORITY &&
iType != NLAlertDialog.TYPE_LOW_PRIORITY &&
iType != NLAlertDialog.TYPE_MEDIUM_PRIORITY &&
iType != NLAlertDialog.TYPE_HIGH_PRIORITY)
iType = NLAlertDialog.TYPE_LOW_PRIORITY;
if(!width)
width = 600;
if (!sTitle)
{
switch (iType)
{
case NLAlertDialog.TYPE_LOWEST_PRIORITY:
sTitle = “Confirmation”;
break;
case NLAlertDialog.TYPE_LOW_PRIORITY:
sTitle = “Information”;
break;
case NLAlertDialog.TYPE_MEDIUM_PRIORITY:
sTitle = “WARNING”;
break;
case NLAlertDialog.TYPE_HIGH_PRIORITY:
default:
sTitle = “Error”;
break;
}
}

var bHelpLink = false;
if (helpUrl && helpUrl.length > 0)
{
bHelpLink = true;
if (!helpText)
helpText = “Visit this Help Topic”;
}
return “

“+

“+

“+

“+

“+
“<td bgcolor=’” + ((iType <= NLAlertDialog.TYPE_MEDIUM_PRIORITY) ? “#E5E5E5” : “#F6BFBF”) + “‘ valign=top rowspan=3>

“+

“+

“+
“<td bgcolor=’” + ((iType <= NLAlertDialog.TYPE_MEDIUM_PRIORITY) ? “#F6F6F6” : “#FAD9D9”) + “‘ height=1>

“+

“+

“+
“<td bgcolor=’” + ((iType <= NLAlertDialog.TYPE_MEDIUM_PRIORITY) ? “#E5E5E5” : “#F6BFBF”) + “‘ height=16>“+sTitle+”

“+

“+

“+

“+

“+

“+

“+

“+

“+

“+

“+

“+

“+

“+sMessage +
( (bHelpLink) ?
(“

” + helpText + “

“) :””) +

“;
}

NLAlertDialog = Class.create();

NLAlertDialog.TYPE_LOWEST_PRIORITY = 0;
NLAlertDialog.TYPE_LOW_PRIORITY = 1;
NLAlertDialog.TYPE_MEDIUM_PRIORITY = 2;
NLAlertDialog.TYPE_HIGH_PRIORITY = 3;

NLAlertDialog.prototype =
{
initialize: function(sId)
{
this.sId = sId || “NLAlertDialog”;
},

show: function(sTitle, sMessage, iType, sTargetDivId)
{
var posX = document.body.clientWidth / 2;
var posY = document.body.clientHeight / 2;

var sTitleId = this.sId + ‘_title’;
var sMessageId = this.sId + ‘_message’;

if(!iType) iType = NLAlertDialog.TYPE_LOW_PRIORITY;

if (!this.hndDialogDiv)
{
this.hndDialogDiv = document.createElement(“div”);
this.hndDialogDiv.innerHTML = getAlertBoxHtml(sTitle, sMessage, iType);
this.hndDialogDiv.style.display = “none”;
this.hndDialogDiv.style.position = “absolute”;
document.body.appendChild(this.hndDialogDiv);
}
if (sTargetDivId != null)
{
$(sTargetDivId).innerHTML = this.hndDialogDiv.innerHTML;
return;
}
if (this.hndDialogDiv.style.display == “block”)
return;
this.hndDialogDiv.style.display = “block”;
this.hndDialogDiv.style.top = posY – (this.hndDialogDiv.clientHeight / 2);
this.hndDialogDiv.style.left = posX – (this.hndDialogDiv.clientWidth / 2);
},

hide: function( sTargetDivId )
{
if (sTargetDivId != null)
$(sTargetDivId).innerHTML = “”;
else if (this.hndDialogDiv != null)
this.hndDialogDiv.style.display = “none”;
}
}


评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注