PDA

View Full Version : درج در کد جاوا اسکریپت



sam166
پنج شنبه 13 اسفند 1388, 10:07 صبح
سلام
بنده این کد جاوا اسکریپتی را که میزارم برای باز کردن پنجره است
ولی من میخوام داخل پنجره از باتون و تکست باکس و... استفاده کنم در صورتی که فقط داخلش متن میشه نوشت
از سروران تقاضا دارم نگاهی بیاندازند و بگویند چه کار کنم و و اگر بخواهم مثلا یک باتون به این پنجره اضافه کنم باید کدش را کجا بنویسم



//---------------start disable selection functions

function disableselect(e){
return false
}

function disableselect(e){
return false
}
function enblselect(e){
return true
}
function keyenbl(e){
return true
}
function keyshut(e)
{
if(e.ctrlKey&&e.charCode==97)
{
return false;
}
return true;
}
function start_disable_select()
{

document.onselectstart=new Function ("return false")
//if NS6
if (window.sidebar){
document.onmousedown=disableselect;
document.onkeypress=keyshut;
}
}
function enable_select()
{
document.onselectstart=new Function ("return true")
if (window.sidebar){
document.onmousedown=enblselect;
document.onkeypress=keyenbl;
}

}
//---------------------------end------
var ft=true;
var n=(document.all||window.navigator.appName=='opera' )?0:1;
var opt=70;
function close_anim(id)
{
if(!(sid[id]||jid[id]))
{
if(n)
{
sid[id]=setInterval("if(opt>-5){document.getElementById(\""+id+"\").style.MozOpacity=(opt/100);opt-=5;}else{document.getElementById(\""+id+"\").style.visibility='hidden';clearInterval(sid['"+id+"']);sid['"+id+"']='';opt=70}",1);
}else{
sid[id]=setInterval("if(opt>-5){document.getElementById(\""+id+"\").style.filter='alpha(opacity:'+opt+')';opt-=5;}else{document.getElementById(\""+id+"\").style.visibility='hidden';clearInterval(sid['"+id+"']);sid['"+id+"']='';opt=70}",1);
}
allwin=getElementByclass("mover");
for(i=0;i<allwin.length;i++)
j=0;
a=document.getElementsByTagName('*');
for(i=0;i<a.length;i++)
{
if(a[i].className==class_name){rt[j]=document.getElementsByTagName('*')[i];j++}
}

return rt;
}
if(n){document.addEventListener('mousemove',move,t rue);}else{document.attachEvent('onmousemove',move );}

var full=new Array();
var movertag;
var onmouse_over=true;
function move(e)
{
var on_tag=null;
//alert(on_mouse[getElementByclass("mover")[0].id]);
allwin=getElementByclass("mover");
for(i=0;i<allwin.length;i++)
{
if(on_mouse[allwin[i].id])
{
on_tag=allwin[i];
break;
}
}
if(n){mx=e.pageX}else{mx=event.clientX+document.bo dy.scrollLeft}
if(n){my=e.pageY}else{my=event.clientY
}
if(on_tag&&on_mouse[on_tag.id]&&onmouse_over&&!full[on_tag.id])
{

//alert("hi")
mover=on_tag;
//if(on_mouse[on_tag.id]){ start_disable_select();}
if(ft)
{

if ( window.event )
{
e = window.event;
X = e.offsetX;
Y = e.offsetY;
}
else if ( typeof( e.pageX )!= 'undefined' )
{
X = e.pageX - on_tag.offsetLeft;
Y = e.pageY - on_tag.offsetTop;
}
ft=false;
}

if(on_tag.style!=null)
{
on_tag.style.zIndex=zindexer;
zindexer++;
mover.style.left=mx-X;

mover.style.top=my-Y;
}
}else{return ;}




/*

if(on_tag&&on_mouse[on_tag.id]&&!full[on_tag.id]&&onmouse_over)
{

mover=on_tag;
if(on_tag.style!=null)
{
on_tag.style.zIndex=zindexer;
zindexer++;
mover.style.left=x-(mover.offsetWidth/2);


mover.style.top=y-18;
}
}else{return ;}*/
}

function end_resize(x,y)
{
allwin=getElementByclass("mover");
for(i=0;i<allwin.length;i++)
{
if(resize[allwin[i].id])
{
ch_x=posi_obj.clientX-x;
ch_y=posi_obj.clientY-y;
resize[allwin[i].id]=false;
a=""
for(o in document.getElementById('title_'+allwin[i].id))
{
a+=o+" "
}
w1=allwin[i].offsetWidth
w2=document.getElementById('title_'+allwin[i].id).offsetWidth
//alert(a+document.getElementById('title_'+allwin[i].id).offsetWidth)
if(parseInt(w1+ch_x)>parseInt(95+w2))
{
resize_to(ch_x,ch_y,allwin[i].id);
}else{
resize_to(95+document.getElementById('title_'+allw in[i].id).offsetWidth-allwin[i].offsetWidth,ch_y,allwin[i].id);
}
main_tg = document.getElementsByTagName('body');
main_tg[0].style.cursor = 'auto';
//clearInterval(resize_id[allwin[i].id]);
if(n){document.removeEventListener('mousemove',mov er_hand,true);}else{document.detachEvent('onmousem ove',mover_hand);}
if(n){document.getElementById(allwin[i].id).parentNode.removeChild(tag);}else{document.ge tElementById(allwin[i].id).parentElement.removeChild(tag);}
}
}
}
function resize_to(x,y,id)
{


document.getElementById('tbl_'+id).style.width=(pa rseIseInt(document.getElementById('left_'+id).offs etHeight)>0)?y+parseInt(document.getElementById('left_'+id). offsetHeight):0;
// document.getElementById('right_'+id).style.height= (y+parseInt(document.getElementById('right_'+id).o ffsetHeight)>0)?y+parseInt(document.getElementById('right_'+id) .offsetHeight):0;
document.getElementById('tbl_'+id).style.height=(y +parseInt(document.getElementById('tbl_'+id).offse tHeight)>0)?y+parseInt(document.getElementById('tbl_'+id).o ffsetHeight):1;
document.getElementById('inner_tbl_'+id).style.hei ght=document.getElementById('tbl_'+id).style.heigh t;
document.getElementById('inner_tbl_'+id).style.wid th=document.getElementById('tbl_'+id).style.width;

}

function resize(id)
{
if(!full[id])
{
//start_disable_select();
//start_disable_select();
pos=new Array();
pos[0]=posi_obj.clientX;
pos[1]=posi_obj.clientY;
tag=document.createElement("DIV");
tag.style.background="gray";
tag.style.position="absolute";
tag.style.left=document.getElementById(id).style.l eft;
tag.style.top=document.getElementById(id).style.to p;
tag.id="resize_"+id;
proto_id="resize_"+id;
tag.style.zIndex=zindexer;
zindexer++;
tag.style.width=document.getElementById(id).offset Width;
tag.style.height=document.getElementById(id).offse tHeight;
tag_sizes[0]=tag.style.width;
tag_sizes[1]=tag.style.height;
if(n){tag.style.MozOpacity=0.2;}else{tag.style.fil ter='alpha(opacity:20)';}
if(n){document.getElementById(id).parentNode.appen dChild(tag);}else{document.getElementById(id).pare ntElement.appendChild(tag);}
//resize_id[id]=setInterval('resize_proto("resize_'+id+'")',1);
if(n){document.addEventListener('mousemove',mover_ hand,true);}else{document.attachEvent('onmousemove ',mover_hand);}

}
}
function mover_hand(e)
{
resize_proto();
}
function resize_proto()
{

id=proto_id;
ch_x=posi_obj.clientX-pos[0];
ch_y=posi_obj.clientY-pos[1];
document.getElementById(id).style.width=(parseInt( tag_sizes[0])+ch_x>0)?parseInt(tag_sizes[0])+ch_x:0;
document.getElementById(id).style.height=(parseInt (tag_sizes[1])+ch_y>0)?parseInt(tag_sizes[1])+ch_y:0;
}
var proto_id;
var tag_sizes=new Array();
var tag;
var zindexer=10;
var innerwin;
var mini=new Array();
var minsize=new Array();
var pos=new Array();
function minimize(id)
{
if(!mini[id]){

document.getElementById('inner_tbl_'+id).style.dis play='none';
mini[id]=true;
document.getElementById('tbl_'+id).style.height=1
//document.getElementById('tbl_'+id).style.width="auto"
document.getElementById('left_'+id).style.height=1 ;
document.getElementById('right_'+id).style.height= 1;

if(full[id])
{
document.getElementById('left_'+id).style.height="auto";
document.getElementById('right_'+id).style.height="auto";
}
if(n)
{
document.getElementById("max_"+id).style.MozOpacity=0.4;
}else{
document.getElementById("max_"+id).style.filter='alpha(opacity:40)';
}


}else{
document.getElementById('inner_tbl_'+id).style.dis play='inline';
mini[id]=false;
if(full[id])
{
document.getElementById('left_'+id).style.height=d ocument.getElementsByTagName('body')[0].clientHeight-(document.getElementById('bottom_'+id).offsetHeigh t+20);
document.getElementById('right_'+id).style.height= document.getElementsByTagName('body')[0].clientHeight-(document.getElementById('bottom_'+id).offsetHeigh t+20);
}
document.getElementById('left_'+id).style.height="auto";
document.getElementById('right_'+id).style.height="auto";
document.getElementById('inner_tbl_'+id).style.hei ght="auto"
if(n)
{
document.getElementById("max_"+id).style.MozOpacity=1;
}else{
document.getElementById("max_"+id).style.filter='alpha(opacity:100)';
}
}
}
var sizes=new Array();
function fullscreen(id)
{
if(!mini[id])
{
if(!full[id])
{

document.getElementById("max_"+id).style.background="url('tpls/jstheme/minimize.gif')";
//sizes['bottom_'+id]=parseInt(document.getElementById('bottom_'+id).of fsetWidth);
sizes['tbl_'+id]=document.getElementById('tbl_'+id).clientWidth
//document.getElementById('tbl_'+id).style.width=doc ument.getElementsByTagName('body')[0].clientWidth-16;
//document.getElementById('bottom_'+id).style.width= document.getElementsByTagName('body')[0].clientWidth-16;
document.getElementById('tbl_'+id).style.width=doc ument.getElementsByTagName('body')[0].clientWidth-16;
document.getElementById('left_'+id).style.height=d ocument.getElementsByTagName('body')[0].clientHeight-(document.getElementById('bottom_'+id).offsetHeigh t+20);
document.getElementById('right_'+id).style.height= document.getElementsByTagName('body')[0].clientHeight-(document.getElementById('bottom_'+id).offsetHeigh t+20);
document.getElementById(id).style.left=0;
document.getElementById(id).style.top=0;
//window.onscroll=function(){ window.scroll(0,0);}
full[id]=true;
}else{
document.getElementById("max_"+id).style.background="url('tpls/jstheme/max.gif')";
window.onscroll="";
full[id]=false;
document.getElementById('left_'+id).style.height="";
document.getElementById('right_'+id).style.height="";
document.getElementById('tbl_'+id).style.width=siz es['tbl_'+id];
//document.getElementById('bottom_'+id).style.width= sizes['bottom_'+id];
}

}
}
function make_false()
{
allwin=getElementByclass("mover");
for(i=0;i<allwin.length;i++)
{
on_mouse[allwin[i].id]=false;
resize_id[allwin[i].id]=false;
}
}
document.onmouseup=function(){ft=true;end_resize(p os[0],pos[1]);make_false();}
function make_it(innerwindow,id,title)
{
if(document.getElementById(id)==null)
{
on_mouse[id]=false;
full[id]=false;
mini[id]=false;
tag=document.createElement("DIV");
tag.style.position="absolute";
tag.innerHTML=title;
document.body.appendChild(tag);
size=tag.clientWidth+95;
document.body.removeChild(tag)
code='<div style="position: absolute;text-align:center; left=0;top=0;z-index:'+zindexer+'" id="'+id+'" class=mover>';

code+='<table border="0" style="border-collapse: collapse" onclick="if(!n){this.parentElement.style.zIndex=zindexer;zi ndexer++}else{this.parentNode.style.zIndex=zindexe r;zindexer++;}" id="jswin_'+id+'" >';
code+=' <tr >';
code+=' <td style="background-image:url(\'tpls/jstheme/left-top.gif\');cursor:move;" onmousedown="on_mouse[\''+id+'\']=true;" >&nbsp;</td>';
code+=' <td style="background-image:url(\'tpls/jstheme/bg.gif\');cursor:move;max-height:30px;width:'+size+'px" onmousedown="on_mouse[\''+id+'\']=true;" id="top_'+id+'">';
code+=' <div style="background-image:url(\'tpls/jstheme/bg.gif\');">';
code+=' <a href="javascript:close_anim(\''+id+'\');"><div onmouseover="onmouse_over=false;" onmouseout="onmouse_over=true;" style="background-image:url(\'tpls/jstheme/close.gif\');height:19px;width:24px; padding-bottom:0; padding-top:0px;padding-right:0px; float: right;" >&nbsp;</div></a>';
code+=' <a href="javascript:fullscreen(\''+id+'\');"><div onmouseover="onmouse_over=false;" onmouseout="onmouse_over=true;" id="max_'+id+'" style="background-image:url(\'tpls/jstheme/max.gif\');height:19px;width:24px; padding-bottom:0; padding-top:0px;padding-right:0px; float: right;" >&nbsp;</div></a>';
code+=' ';
code+=' <a href="javascript:minimize(\''+id+'\')"><div onmouseover="onmouse_over=false;" onmouseout="onmouse_over=true;" style="background-image:url(\'tpls/jstheme/min.gif\');height:19px;width:24px;padding-bottom:0; padding-top:0px;padding-right:0px;float:right;" >&nbsp;</div></a>';
code+='';
code+='</div><div style="float:left;" id="title_'+id+'"><b>'+title+'</b></div></td>';
code+=' <td width="8" style="cursor:move;background-image:url(\'tpls/jstheme/right-top.gif\');" onmousedown="on_mouse['+id+']=true;" onclick="if(!n){this.parentElement.parentElement.parentElem ent.style.zIndex=zindexer;zindexer++}else{this.par entNode.parentNode.parentNode.style.zIndex=zindexe r;zindexer++;}">&nbsp;</td>';
code+=' </tr></div>';
code+='';
code+=' <div style="background:white;">';
code+=' <tr >';
code+=' <td style="background-image:url(\'tpls/jstheme/left_1.gif\');" width="5" id="left_'+id+'">&nbsp;</td>';
code+=' <td style="background:#ffffff;" width="auto" id="tbl_'+id+'" >';
code+='<div id="inner_tbl_'+id+'" style="direction:ltr;float:left;position:relative;height: inherit;width:inherit;overflow:hidden;">'
code+=innerwindow;
code+=' </div></td><td style="background-image:url(\'tpls/jstheme/right.gif\');" width="5" id="right_'+id+'">&nbsp;</td>';
code+=' </tr>';
code+='</div>';


code+=' ';
code+=' <tr >';
code+=' <td style="background-image:url(\'tpls/jstheme/b_right.gif\');" width="8">&nbsp;</td>';
code+=' <td height=25 style="background-image:url(\'tpls/jstheme/down.gif\');" id="bottom_'+id+'">&nbsp;</td>';
code+=' <td onmousedown=" main_tg = document.getElementsByTagName(\'body\');main_tg[0].style.cursor = \'nw-resize\';resize(\''+id+'\');resize[\''+id+'\']=true;" style="cursor:nw-resize;background-image:url(\'tpls/jstheme/down-right.gif\');" width="8" >&nbsp;</td>';
code+=' </tr>';
code+=' </table>';

code+='</div>';
zindexer++;
if(document.getElementsByTagName('body')[0]==null)
{
setTimeout("document.getElementsByTagName('body')[0].innerHTML+=code;",1000);
}else{
document.getElementsByTagName('body')[0].innerHTML+=code;
}
}else{


if(!(jid[id]||sid[id])){

if(n)
{
jid[id]=setInterval("if(h<101){document.getElementById(\""+id+"\").style.MozOpacity=(h/100);h+=8;}else{clearInterval(jid['"+id+"']);jid['"+id+"']='';h=0}",1);

}else{
jid[id]=setInterval("if(h<101){document.getElementById(\""+id+"\").style.filter='alpha(opacity:'+h+')';h+=8;}else{c learInterval(jid['"+id+"']);jid['"+id+"']='';h=0}",1);
}
}
document.getElementById(id).style.visibility='visi ble';

document.getElementById('inner_tbl_'+id).innerHTML =innerwindow;
}
}

var h=0;
var resize_id=new Array();
var allwin=new Array();
var on_mouse=new Array();
var sid=new Array();
var jid=new Array();

sam166
جمعه 14 اسفند 1388, 21:53 عصر
بعد از کلی سرو کله زدن با این کد توانستم راهش را پیدا کنم:قهقهه::عصبانی++:



code+='<div id="inner_tbl_'+id+'" style="direction:ltr;float:left;position:relative;height: inherit;width:inherit;overflow:hidden;">'
code+=innerwindow;
code+=' </div>

شما به جای innerwindow هرچیزی بنویسی نمایش داده می شود
البته باید بین ' ' قراربگیرد