您的位置:无忧脚本 » Brull与无忧同在 » 日志
仿真windows窗口类Jwindow
查看( 2025 ) /
评论( 11 )
正考虑做一个web聊天的东东,打算用它做客户端容器
V1O5U6l+o7u[*m0部分代码参考DronFw里的代码,大家批批无忧脚本7e? {IY!n&A*C
只能应用在XHTML下,没有考虑HTML4.0的兼容性,感兴趣的只要稍作修改就能用在HTML4.0下无忧脚本&jxS4M#t!S'^#rg9p Y
转载的朋友请保留作者信息
V1O5U6l+o7u[*m0部分代码参考DronFw里的代码,大家批批无忧脚本7e? {IY!n&A*C
只能应用在XHTML下,没有考虑HTML4.0的兼容性,感兴趣的只要稍作修改就能用在HTML4.0下无忧脚本&jxS4M#t!S'^#rg9p Y
转载的朋友请保留作者信息
CODE:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">无忧脚本wiy`2s#qk
<html xmlns="http://www.w3.org/1999/xhtml">
PlN$r#QI(F:A$qY*[0<head>无忧脚本 c8g}&pi
}E
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
)zye@#h'H;d,[0<meta name="author" content="brull@163.com,brull">无忧脚本 t4p8_0| bJ[TT
<scrīpt type="text/javascrīpt">无忧脚本k3W?zC|jKx
/**
;|pd+Ng dl0*JWindow,Jchat窗口类无忧脚本A+O:q!dz8||@
*version 1.0无忧脚本o0tS\
wv5h
*@author brull无忧脚本A){'H(|wd]
*@email brull@163.com无忧脚本)T;U!ezED0c
*@date 2007-01-31无忧脚本[(W,lwU#a
*/无忧脚本`
@/r*z'i^Y1[C~4C}
:mBbZ3Il|0/*无忧脚本1\]3MD;F!IC
*新建一个窗口视图,并显示在浏览器容器里无忧脚本cPx
u2mZ%}q
*类里有实例方法,min、changeStatus、close、drag无忧脚本2U`H G1P6c:[p:_
*/无忧脚本1@?x"A&E7A%HlM7VE
JWindow = function (win_obj)无忧脚本W }mEp}o
{
5F3W(h^.ax0 /*
"w nY
Q+S8GY
__0 窗口存在判断无忧脚本2t$L%RE
c
如果窗口存在则只是显示它,并将它置为当前窗口无忧脚本:h4aW%K_P
*/无忧脚本\:K_P)qM1P5V DO
if(document.getElementById(win_obj.id)){//窗口已存在无忧脚本DT'KT$pj
var existWin = document.getElementById(win_obj.id).quote;//存在窗口的引用
cLv/c6N!n| RU0 if (JWindow.curWindow != win_obj.id){//窗口不是当前窗口无忧脚本R9N2y7i;Y$Z _@
if (existWin.contain.style.display == "none"){//窗口是隐藏的(MIN,CLOSE),窗口隐藏时标题活动样式不变
|aG
{ yI0 existWin.status = existWin.oldStatus;//还原原来状态
6d5{k1]+w
nY+V0 existWin.contain.style.display = "";//显示窗口
zc
n S)GP
l+m0 JWindow.curWindow = win_obj.id;//设置为当前窗口
CR0n5oeb6M+Kfj
r0 me.previous = JWindow.curWindow;
3PSD*plJ0 }
u's&SP
q^#?0H0 else {
1B
X0GD7DN,w i0 document.getElementById(JWindow.curWindow + "_caption").className = "win_caption_deactive";//设置当前窗口为非活动窗口样式
Yx$a]Y!G-v U |k,w0 document.getElementById(JWindow.curWindow + "_task").className = "task_button_deactive";//设置任务栏按钮为非活动按钮样式无忧脚本2M(G3mLd:u6?p"Q#k
JWindow.curWindow = win_obj.id;//设置为当前窗口无忧脚本*p.M"I)kO?"h1uof
document.getElementById(win_obj.id + "_caption").className = "win_caption_active";//设置窗口为活动窗口样式
mY'mD1h6n0 document.getElementById(win_obj.id + "_task").className = "task_button_active";//设置任务栏按钮为活动按钮样式无忧脚本i;HuF.F.K6v)^0M
}无忧脚本"N5nNdc*m V&mW*sC
existWin.contain.zIndex = JWindow.zIndex++;//窗口上移到层最顶端
mg,g"Z[4w0 }
y#Rs&kK6H3t0 return;无忧脚本'P5rC;e]0Eqn9CK9Kq
R
}
-Fs
\c'L}0无忧脚本R mV? @Q/fX
/**********创建窗口******************/无忧脚本\4w5Lv$U
var win = win_obj;//包含窗口属性的原生对象无忧脚本xF7g2P~
var isIe = /msie/i.test(navigator.userAgent);//是否是IE浏览器
2`!t9G avuc0 this.contain = document.createElement("div");//窗口容器
&R1O,CVrF0 this.id= win.id;//win_obj没有默认值,初始化时win_obj必须有id属性
{.nz)sj6G;fY0 this.width = win.width?win.width:420;//窗口宽,默认为420无忧脚本v
ZY)AV
this.height = win.height?win.height:360;//窗口关,默认为360无忧脚本2af*bh:ou0bK4b
this.left = win.left?win.left:(document.documentElement.clientWidth-this.width)/2;//窗口左上角距离浏览器左边框距离,默认居中
*v:]2v)i6i}0 this.top = win.top?win.top:(document.documentElement.clientHeight-this.height)/2;//窗口左上角距离浏览器上边框距离,默认居中
CElx:TZ0 this.oldLeft = this.left;//记录窗口最大化时窗口左上角距离浏览器左边框距离
@.H!i$I E
EL,s0 this.oldTop = this.top;//记录窗口最大化时窗口左上角距离浏览器顶边框距离无忧脚本3MT#B#h8O t9U&{u
this.title = win.title?win.title:" ";//标题,默认为空无忧脚本2Am y.`R
this.content = win.content ? win.content : "";//窗口内容,默认为空无忧脚本5d2yrt@
aI)j
this.icon = win.icon ? win.icon : "http://www.51js.com/attachments/2007/03/35270_200703102258421.gif";//窗口图标无忧脚本6h;~tD0B9x ^/M!gV
this.minButton = (win.minButton == false) ? false:true;//是否显示最小化按钮,默认显示
UM~OF0 this.maxButton = (win.maxButton == false) ? false:true;//是否显示最大化按钮,默认显示无忧脚本3T3b1[
Se!y7C0f0q b
this.closeButton = (win.closeButton==false) ? false:true;//是否显示关闭按钮,默认显示
-~C|4d-KNBx0 this.status = "NORMAL";//窗口状态,包括MAX,MIN,NORMAL,CLOSE
+[h:Pa U"\
I0 this.previous = JWindow.curWindow ? JWindow.curWindow : null;//上个当前窗口,在窗口关闭和最小化时有用
7tU2IfB2b0 win = null;//释放对象
Y%rd?'s9]B8I0 var me = this;//对象引用,方便类内部引用无忧脚本:A O/h nIf Z([R
无忧脚本e.O(DX9h
K
/*************生成窗口视图******************/
F8e7WDV%Uhr*G_0 me.contain.id = this.id;
:@5q}F_+x0 me.contain.quote = this;//对象引用,方便应用页面引用无忧脚本*d/U(Cjt F
me.contain.className="win_contain";
5N:` o7P
N.W0 with(me.contain.style){
^+Hx'I8W {Z2W0 position = "absolute";无忧脚本7z:d%j-R%zW
left = this.left + "px";
&e.g&v8^b&@0 top = this.top + "px";无忧脚本i;VzH/R%y7Uya
width =this.width + "px";无忧脚本B2X:j%oka7YN
I"tC
height =this.height + "px";
iE0K |
L/hR9WId8o8O0 zIndex = JWindow.zIndex++;
qU(h;z&n$T0 }
4XM&[I}a0 me.contain.innerHTML = "\无忧脚本6d8zD$o R.{TT
<div class=\"win_caption_active\" id=\"" + this.id + "_caption\"" + " ōndblclick=\"document.getElementById('" + this.id + "').quote.changeStatus('" + this.id + "')\">\
/Aa
T1Mf0 <img src=\"" + this.icon + "\" class=\"win_icon\" /><span class=\"win_title\">" + this.title + "</span>\
*Ff i#zqo"`3EF`0 <div class=\"win_button_div\">"无忧脚本0jm'Rb3y)`c7W
+(this.minButton ? "<input class=\"win_min\" type=\"button\" title=\"最小化\" ōnclick=\"document.getElementById('" + this.id + "').quote.min();\" />":"")无忧脚本AD+r,[A(E/g]7Pn${
+(this.maxButton ? "<input class=\"win_max\" id=\"" + this.id + "_maxbutton\" type=\"button\" ōnmouseover=\"this.title=(document.getElementById('" + this.id + "').quote.status=='MAX')?'还原':'最大化'\" ōnclick=\"this.blur();document.getElementById('" + this.id + "').quote.changeStatus();\" />":"")
VL&m/ae+GW0 +(this.closeButton ? "<input class=\"win_close\" type=\"button\" title=\"关闭\" ōnclick=\"document.getElementById(\'" + this.id + "\').quote.close();\"/>":"")
V X-e'Q3ipLB
H-m$~0 + "</div>\无忧脚本M.jD"cP_]sSUh
</div>\无忧脚本?(Z^ iR
<div class=\"win_body\" id=\"" + this.id + "_body" + "\">" + this.content + "</div>\无忧脚本!I-\Mc#Lu,J*sc
";
$t"X3_H;HlAAp(}v0
-|kF ~P} AW,K0 /***************注册窗口事件************************/无忧脚本\WHgM8~]
me.contain.onmousedown = function (e)无忧脚本;WZ1[BB-V
{无忧脚本5lUVw3@{5?
n
e = e || window.event;无忧脚本X|,]5Q7d\
var srcElement = isIe ? e.srcElement : e.target;无忧脚本K
r C;b1F9h-` _
if(JWindow.curWindow != me.id){无忧脚本(XEyE'R/n
me.contain.style.zIndex = JWindow.zIndex++;
Dww}ec3p_4y0 document.getElementById(JWindow.curWindow + "_caption").className = "win_caption_deactive";无忧脚本?.a:I#_{h%C#k+tUzf-k
document.getElementById(JWindow.curWindow + "_task").className = "task_button_deactive";
0at {XoO1Ha0 me.previous = JWindow.curWindow;无忧脚本F$n+Q]*Q
JWindow.curWindow = me.id;//设置为当前窗口无忧脚本1@:Qz8{x_A*cy
document.getElementById(JWindow.curWindow + "_caption").className = "win_caption_active";无忧脚本,hz\Fus
document.getElementById(JWindow.curWindow + "_task").className = "task_button_active";
9oK%BMy%\4`W/r0 }无忧脚本Mby7U;Kp
if (me.id + "_caption" ==srcElement.id && me.status == "NORMAL") me.drag(e);无忧脚本4r/r"@C#Rx3WbPe
}无忧脚本D8dF^
^1V
ip$H2` @z Zm9i0 /***********添加任务栏按钮**********/无忧脚本E$gk2s|/Cd
var task = document.createElement("button");无忧脚本:MLpVmn
task.id = me.id + "_task";
"VeV J\k cZ0 task.title = me.title;无忧脚本1HCpF(cEB.u
task.className = "task_button_active";
H0o(M;G0c0 task.innerHTML = "<img src=\"" + me.icon + "\" class=\"task_icon\" /><span class=\"task_font\">" + me.title + "</span>";
z+]R-xR0 task.onclick = function () {无忧脚本y JY-f)a"C%ks.Io'ag
task.blur();//丢掉讨厌的虚线框无忧脚本Bt$}?+x
if(JWindow.curWindow != me.id){无忧脚本Y@q0jf2l#a$e(C\6v
me.contain.style.zIndex = JWindow.zIndex++;
v|aMK`0{ j
c0 document.getElementById(JWindow.curWindow + "_caption").className = "win_caption_deactive";
+z
[
y r5KDZ5M0 document.getElementById(JWindow.curWindow + "_task").className = "task_button_deactive";无忧脚本Kyn$F&]5\Ox
me.previous = JWindow.curWindow;
