battles/js/win_add.js
2018-01-28 18:40:49 +02:00

201 lines
6.8 KiB
JavaScript

isIE = document.all;
isNN = !document.all&&document.getElementById;
isN4 = document.layers;
isHot = false;
document.onmousedown = ddInit;
document.onmouseup = Function("ddEnabled=false");
function ddInit(e) {
topDog = isIE ? "BODY" : "HTML";
whichDog = isIE ? document.all.theLayer : document.getElementById("theLayer");
hotDog = isIE ? event.srcElement : e.target;
while(hotDog.id != "titleBar"&&hotDog.tagName != topDog) {
hotDog = isIE ? hotDog.parentElement : hotDog.parentNode;
}
if(hotDog.id == "titleBar") {
offsetx = isIE ? event.clientX : e.clientX;
offsety = isIE ? event.clientY : e.clientY;
nowX = parseInt(whichDog.style.left);
nowY = parseInt(whichDog.style.top);
ddEnabled = true;
document.onmousemove = dd;
}
}
function dd(e) {
if(!ddEnabled) return;
whichDog.style.left = isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx;
whichDog.style.top = isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
return false;
}
function mousePageXY(e) {
var x = 0, y = 0;
if(e.pageX || e.pageY) {
x = e.pageX;
y = e.pageY;
} else if (e.clientX || e.clientY) {
x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
}
return {"x":x, "y":y};
}
var win = {
winc:{},
wsdr:null,
scor:{},
openw:function(id, title, text, date, type, style) {
if($('#win_'+id).attr('id') == undefined) {
this.add(id, title, text, date, type, 1, '');
}
},
WstartDrag:function(id) {
$('#wupbox').css({'display':'block', 'cursor':'move'});
this.wsdr = id;
$('.w1').css({'z-index':1102});
$('#win_'+id).css({'z-index':1103});
delete cm;
},
WmoveDrag:function(e) {
var x = mousePageXY(e)['x'], y = mousePageXY(e)['y'];
if(this.scor.x == undefined) {
this.scor.x = x;
this.scor.y = y;
this.scor.x2 = unpx($('#win_'+this.wsdr).css('left'));
this.scor.y2 = unpx($('#win_'+this.wsdr).css('top'));
}
x = x-this.scor.x;
y = y-this.scor.y;
x += this.scor.x2;
y += this.scor.y2;
if(x < 9) { x = 9; }
if(x + $('#win_'+this.wsdr).width() > $(window).width() - 9) {
x = $(window).width() - 9 - $('#win_'+this.wsdr).width();
}
if(y < 35) { y = 35; }
if(y + $('#win_'+this.wsdr).height() > $(window).height() - 35) {
y = $(window).height() - 35 - $('#win_'+this.wsdr).height();
}
$('#win_'+this.wsdr).css({'top':y+'px','left':x+'px'});
},
WstopDrag:function() {
$('#wupbox').css({'display':'none', 'cursor':'move'});
this.wsdr = null;
this.scor = {};
},
add:function(id, title, text, date, type, style, css) {
var nw = '';
if($('#win_'+id).attr('id') == undefined) {
var acts = {};
if(date.usewin != undefined){
acts[0] = 'onmouseup="'+date.usewin+'"';
}
if(date.n != undefined){
text += '<div style="margin-left: 11px;">'+date.n+'</div>';
}
var kyps = ['', ''];
if(type == 0) {
nw = text;
} else if(type == 1) {
nw = text;
} else if(type == 2) {
nw = '<div>'+text+'</div><div style="padding:5px"><div style="float:left"><button onclick="'+date.a1+';win.closew(\''+id+'\');" class="btnnew" id="winyesbtnfox'+id+'" style="width:100px">Aa</button></div><div style="float:right"><button class="btnnew" onClick="'+date.a2+';win.closew(\''+id+'\')" style="width:100px">Iao</button></div><br></div>';
kyps[0] = ''+date.a1+';win.closew(\\\''+id+'\\\');win.addaction(0,\\\'\\\');';
} else if(type == 3) {
nw = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td>'+text+'</td><td width="40" align="center" valign="middle"><img style="margin-top:5px;cursor:pointer" onClick="'+date.a1+';win.closew(\''+id+'\');" src="http://img.originalcombats.com/i/b__ok.gif" width="25" height="18"><br><img onClick="win.closew(\''+id+'\')" style="cursor:pointer" src="http://img.originalcombats.com/i/b__cancel.jpg" width="25" height="18"></td></tr></table>';
kyps[0] = ''+date.a1+';win.closew(\\\''+id+'\\\');win.addaction(0,\\\'\\\');';
} else if(type == 4) {
nw = text[0];
}
if(date.d != undefined) {
nw = nw+date.d;
}
nw = '<div style="margin: 2px;'+css+'">'+nw+'</div>';
if(title != '') {
nw = '<div class="wi'+style+'s10" onselectstart="return false">'+
'<table width="100%" border="0" cellspacing="0" cellpadding="0">'+
'<tr>'+
'<td rowspan="2" style="cursor: move;" onmousedown="win.WstartDrag(\''+id+'\')" '+acts[0]+'><b>'+title+'</b></td>'+
'<td width="15" align="right"><img style="display:block" onclick="win.closew(\''+id+'\')" src="http://img.originalcombats.com/i/clear.gif" width="13" height="13"></td>'+
'</tr>'+
'</table>'+
'</div>'+nw;
}
nw = '<table onclick="win.addaction(0,\''+kyps[0]+'\')" border="0" cellspacing="0" cellpadding="0">'+
'<tr>'+
'<td class="wi'+style+'s0"></td>'+
'<td class="wi'+style+'s1"></td>'+
'<td class="wi'+style+'s2"></td>'+
'</tr>'+
'<tr>'+
'<td class="wi'+style+'s3"><img src="http://img.originalcombats.com/1x1.gif" width="5" height="1"></td>'+
'<td class="wi'+style+'s7" id="win_main_'+id+'">'+nw+'</td>'+
'<td class="wi'+style+'s4"><img src="http://img.originalcombats.com/1x1.gif" width="5" height="1"></td>'+
'</tr>'+
'<tr>'+
'<td class="wi'+style+'s5"></td>'+
'<td class="wi'+style+'s6"></td>'+
'<td class="wi'+style+'s8"><div id="win_a_'+id+'" class="wi'+style+'s9"></div></td>'+
'</tr>'+
'</table>';
nw = '<div class="w1" '+acts[0]+' id="win_'+id+'">'+nw+'</div>';
$('#windows').html($('#windows').html()+nw);
$('#win_'+id).center();
if(type == 2 || type == 3) {
if(type == 2) {
$('#winyesbtnfox'+id).focus();
}
}
}
delete nw;
},
addaction:function(nm, vl) {
key_actions[nm] = vl;
if(nm != 2) {
key_actions[2] = 1;
}
},
closew:function(id) {
$('#win_'+id).html('');
$('#win_'+id).remove();
}
}
function hideMe() {
if (isIE||isNN) {
whichDog.style.visibility = "hidden";
} else if (isN4) {
document.theLayer.visibility = "hide";
}
}
function showForm(title, text, input_name, input_value, hidden_name, hidden_value, action) {
document.getElementById('ftitle').innerHTML = title;
document.getElementById('ftext').innerHTML = text;
document.getElementById('finput').name = input_name;
document.getElementById('finput').value = input_value;
document.getElementById('fhinput').name = hidden_name;
document.getElementById('fhinput').value = hidden_value;
if(action != ""){
document.getElementById('fuse').action = action;
}
whichDog.style.left = (document.body.clientWidth - 240)/2;
if(isIE||isNN) {
whichDog.style.visibility = "visible";
} else if (isN4) {
document.theLayer.visibility = "show";
}
document.getElementById('finput').focus();
}