var msgBoxDummyBoxContent = '
' +
'' +
' | ' +
'Namn och ikon här | ' +
' | ' +
'
' +
'' +
' | ' +
' | ' +
' | ' +
'
' +
'' +
' | ' +
' | ' +
' | ' +
'
' +
'
';
MessageBoxOptions = {
NOSHADE : 1,
PERSISTANT : 2,
NOBLUR : 4,
FULLSCREEN : 8
}
MessageBoxButtons = {
OK : 1,
YES : 2,
NO : 4,
CANCEL : 8,
CLOSE : 16,
PREVIEW : 32,
NOIMG : 64
}
DialogResult = {
OK : 1,
YES : 2,
NO : 4,
CANCEL : 8,
CLOSE : 16,
PREVIEW : 32,
NOIMG : 64
}
MessageBoxIcons = {
PREVIEW : 1
}
MessageBox = Class.create();
var filterShade = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/shadebg.png',sizingmethod='scale')";
var movedMsgBox = null;
var msgBoxes = new Array();
MessageBox.prototype = {
box : null,
shade : null,
onDialogReturn : null,
onBeforeDialogReturn : null,
moving : false,
offsetX : 0,
offsetY : 0,
buttonBox : null,
causedBlur : false,
options : 0,
userData : null,
initialize : function(caption, message, buttons, icons, options)
{
var bodySize = getBodySize();
var scrollOffset = getScrollOffset();
this.options = options;
this.box = document.createElement("DIV");
this.box.innerHTML = msgBoxDummyBoxContent;
this.box.style.position = "absolute";
var msgBoxContent = this.getElementById(this.box, "messageboxcontent");
var boxTitle = this.getElementById(this.box, "messageboxtitle");
boxTitle.style.cursor = "move";
boxTitle.innerHTML = caption;
boxTitle.msgBox = this;
boxTitle.onmousedown = function(event)
{
if(!event) var event = window.event;
this.msgBox.moving = true;
this.msgBox.offsetX = event.offsetX;
this.msgBox.offsetY = event.offsetY - getScrollOffset();
movedMsgBox = this.msgBox;
}
message = message.replace("", (bodySize.height - 80) + "px");
message = message.replace("", (bodySize.width - 64) + "px");
var boxMessage = document.createElement("DIV");
boxMessage.style.fontSize = "12px";
boxMessage.innerHTML = message;
msgBoxContent.appendChild(boxMessage);
this.contentBox = boxMessage;
var btnbox = document.createElement("DIV");
btnbox.style.textAlign = "right";
msgBoxContent.appendChild(btnbox);
this.buttonBox = btnbox;
if((options & MessageBoxOptions.FULLSCREEN) == MessageBoxOptions.FULLSCREEN)
{
$(msgBoxContent).setStyle({
width : (bodySize.width - 64) + 'px',
height : (bodySize.height - 64) + 'px'
});
}
// cancel button
if((buttons & MessageBoxButtons.CANCEL)==MessageBoxButtons.CANCEL)
{
var btn = document.createElement("A");
btn.href = "javascript:void(0)";
btn.dialogResult = DialogResult.CANCEL;
btn.onclick = this.onBtnClick;
btn.msgBox = this;
btn.className = "ebutton ebabort";
this.box.cancelButton = btn;
btnbox.appendChild(btn);
}
// close button
if((buttons & MessageBoxButtons.CLOSE)==MessageBoxButtons.CLOSE)
{
var btn = document.createElement("A");
btn.href = "javascript:void(0)";
btn.dialogResult = DialogResult.CLOSE;
btn.onclick = this.onBtnClick;
btn.msgBox = this;
btn.className = "ebutton ebclose";
this.box.noButton = btn;
btnbox.appendChild(btn);
}
// ok button
if((buttons & MessageBoxButtons.OK)==MessageBoxButtons.OK)
{
var btn = document.createElement("A");
btn.href = "javascript:void(0)";
btn.dialogResult = DialogResult.OK;
btn.onclick = this.onBtnClick;
btn.msgBox = this;
btn.className = "ebutton ebok";
this.box.okButton = btn;
btnbox.appendChild(btn);
}
// no button
if((buttons & MessageBoxButtons.NO)==MessageBoxButtons.NO)
{
var btn = document.createElement("A");
btn.href = "javascript:void(0)";
btn.dialogResult = DialogResult.NO;
btn.onclick = this.onBtnClick;
btn.msgBox = this;
btn.className = "ebutton ebno";
this.box.noButton = btn;
btnbox.appendChild(btn);
}
// yes button
if((buttons & MessageBoxButtons.YES)==MessageBoxButtons.YES)
{
var btn = document.createElement("A");
btn.href = "javascript:void(0)";
btn.dialogResult = DialogResult.YES;
btn.onclick = this.onBtnClick;
btn.msgBox = this;
btn.className = "ebutton ebyes";
this.box.yesButton = btn;
btnbox.appendChild(btn);
}
// noimg button
if((buttons & MessageBoxButtons.NOIMG)==MessageBoxButtons.NOIMG)
{
var btn = document.createElement("A");
btn.href = "javascript:void(0)";
btn.dialogResult = DialogResult.NOIMG;
btn.onclick = this.onBtnClick;
btn.msgBox = this;
btn.className = "ebutton ebnopic";
this.box.noButton = btn;
btnbox.appendChild(btn);
}
// preview button
if((buttons & MessageBoxButtons.PREVIEW)==MessageBoxButtons.PREVIEW)
{
var btn = document.createElement("A");
btn.href = "javascript:void(0)";
btn.dialogResult = DialogResult.PREVIEW;
btn.onclick = this.onBtnClick;
btn.msgBox = this;
btn.className = "ebutton ebpreview";
this.box.noButton = btn;
btnbox.appendChild(btn);
}
// shade
this.shade = document.createElement("div");
this.shade.style.width = bodySize.width + "px";
this.shade.style.height = bodySize.height + "px";
this.shade.style.left = "0px";
this.shade.style.top = scrollOffset + "px";
this.shade.style.position = "absolute";
if(isSafari || isGecko)
this.shade.style.background = "url('/images/shadebg.png')";
else
this.shade.style.filter = (options & MessageBoxOptions.NOSHADE) == MessageBoxOptions.NOSHADE ? "none" : filterShade;
document.body.appendChild(this.shade);
document.body.appendChild(this.box);
boxMessage.style.width = Math.max(boxMessage.scrollWidth, 250) + "px";
boxMessage.style.height = Math.max(Math.min(bodySize.height, boxMessage.clientHeight) + 20, 50) + "px";
this.box.style.left = ((bodySize.width - this.box.clientWidth) / 2) + "px";
this.box.style.top = Math.max(getScrollOffset(), (((bodySize.height - this.box.clientHeight) / 2) + scrollOffset)) + "px";
var h = Math.min(bodySize.height - 80, Math.max(parseInt(boxMessage.style.height) , boxMessage.scrollHeight));
boxMessage.style.width = (parseInt(boxMessage.style.width)) + "px";
boxMessage.style.height = "auto";
boxMessage.style.overflow = "auto";
if((this.options & MessageBoxOptions.PERSISTANT) != MessageBoxOptions.PERSISTANT)
msgBoxes.push(this);
this.shade.style.zIndex = MessageBoxHelper.getNextZIndex();
this.box.style.zIndex = MessageBoxHelper.getNextZIndex();
// handle blur here
if((this.options & MessageBoxOptions.NOBLUR) != MessageBoxOptions.NOBLUR)
{
var causeBlur = false;
if($('body'))
causeBlur = !$('body').style.filter.match(/enabled=true/);
else if($('madmin'))
causeBlur = !$('madmin').style.filter.match(/enabled=true/);
if(causeBlur)
{
this.causedBlur = true;
try
{
if($('body'))
$('body').style.filter = "progid:DXImageTransform.Microsoft.Blur(pixelradius=3,enabled=false)";
else if($('madmin'))
$('madmin').style.filter = "progid:DXImageTransform.Microsoft.Blur(pixelradius=3,enabled=false)";
}
catch(e)
{
alert(e);
}
}
}
}
,
onBtnClick : function(event)
{
if(!event) var event = window.event;
var o = event.srcElement;
o.msgBox.onDialogReturn_(event.srcElement, event.srcElement.dialogResult);
}
,
onDialogClose_ : function()
{
if(this.onDialogClose)
{
try
{
return this.onDialogClose();
}
catch(e)
{
alert('onDialogClose: ' + e);
return true;
}
}
return true;
}
,
onBeforeDialogReturn_ : function(sender,result)
{
if(this.onBeforeDialogReturn)
{
try
{
return this.onBeforeDialogReturn(sender, result, this);
}
catch(e)
{
alert('onBeforeDialogReturn: ' + e);
return true;
}
}
return true;
}
,
onDialogReturn_ : function(sender, result)
{
if(!this.onBeforeDialogReturn_(event.srcElement, event.srcElement.dialogResult)) return;
this.Hide();
if(this.onDialogReturn)
{
try
{
this.onDialogReturn(sender, result, this);
}
catch(e)
{
alert('onDialogReturn: ' + e);
}
}
this.Close();
}
,
FixBlur : function()
{
if(this.causedBlur)
{
try
{
if($('body'))
$('body').style.filter = "none";
else if($('madmin'))
$('madmin').style.filter = "none";
}
catch(e) { }
}
}
,
Hide : function()
{
this.shade.style.display = "none";
this.box.style.display = "none";
this.FixBlur();
}
,
Show : function()
{
this.shade.style.display = "block";
this.box.style.display = "block";
if((this.options & MessageBoxOptions.PERSISTANT) == MessageBoxOptions.PERSISTANT)
{
var bodySize = getBodySize();
var scrollOffset = getScrollOffset();
this.shade.style.left = "0px";
this.shade.style.top = scrollOffset + "px";
this.box.style.left = ((bodySize.width - this.box.clientWidth) / 2) + "px";
this.box.style.top = (((bodySize.height - this.box.clientHeight) / 2) + scrollOffset) + "px";
this.shade.style.zIndex = MessageBoxHelper.getNextZIndex();
this.box.style.zIndex = MessageBoxHelper.getNextZIndex();
}
this.Reposition();
}
,
Reposition : function()
{
var bodySize = getBodySize();
var scrollOffset = getScrollOffset();
this.shade.style.left = "0px";
this.shade.style.top = scrollOffset + "px";
this.box.style.left = ((bodySize.width - this.box.clientWidth) / 2) + "px";
this.box.style.top = (((bodySize.height - this.box.clientHeight) / 2) + scrollOffset) + "px";
this.shade.style.zIndex = MessageBoxHelper.getNextZIndex();
this.box.style.zIndex = MessageBoxHelper.getNextZIndex();
}
,
Resize : function()
{
var bodySize = getBodySize();
this.contentBox.style.height = this.contentBox.scrollHeight + "px";
this.contentBox.style.width = this.contentBox.scrollWidth + "px";
}
,
Close : function()
{
if(!this.onDialogClose_())
{
this.Show();
return;
}
this.FixBlur();
if((this.options & MessageBoxOptions.PERSISTANT) == MessageBoxOptions.PERSISTANT)
{
this.Hide();
return;
}
this.shade.removeNode(true);
this.box.removeNode(true);
msgBoxes.pop(this);
}
,
FocusObject : function(elementId)
{
var elm = this.getElement(elementId);
if(elm)
{
try { elm.focus(); } catch(e) { }
}
}
,
getElement : function(id)
{
var root = this.contentBox;
var all = root.getElementsByTagName("*");
for(var i=0;i0)
{
try { msgBoxes[msgBoxes.length-1].onDialogReturn_(null,DialogResult.CANCEL); } catch(e) { }
return true;
}
return false;
}
,
HasVisibleBoxes : function()
{
for(var i=0;i getBodySize().width)
{
movedMsgBox.box.style.left = (getBodySize().width - movedMsgBox.box.scrollWidth) + "px";
}
else
{
movedMsgBox.box.style.left = newPosX + "px";
}
if((newPosY + movedMsgBox.box.scrollHeight) > getBodySize().height)
{
movedMsgBox.box.style.top = (getBodySize().height - movedMsgBox.box.scrollHeight) + "px";
}
else
{
movedMsgBox.box.style.top = newPosY + "px";
}
getSelection().clear();
}
if(event.button == 0)
{
boxTitleMouseUp();
}
}
}
function boxTitleMouseUp()
{
if(movedMsgBox!=null)
{
movedMsgBox.moving = true;
movedMsgBox = null;
}
}
function showPreviewBox()
{
var mb = new MessageBox('Förhandsgranska', "Tryck OK för att återgå", MessageBoxButtons.OK, 0, MessageBoxOptions.NOSHADE);
}