Dexiang's profile脚印PhotosBlogListsMore Tools Help

Blog


    February 22

    DTML:窗口函数集

    //常用函数
    //伍德祥
    //2005-12-12 OpenWindow函数增加新的参数
    //2005-12-3 增加新的函数
    //2005-11-25

    //2005-12-3
    //最大化窗口
    function Maximize(){
            HHControl("Maximize");
    }
    //最小化窗口
    function Minimize(){
            HHControl("Minimize");
    }
    //关闭窗口
    function MinimizeWindow(){
            HHControl("Close");
    }
    //利用HTML Help ActiveX Control 对窗口进行控制
    function HHControl(sCommand){
            if(sCommand==null){
                    sCommand="Maximize";
            }
            var oCmd=document.getElementById("Cmd"+sCommand);
            if(oCmd==null){
                    oCmd=document.createElement("div");
                    oCmd.innerHTML="<object id=Cmd"+sCommand+" classid=\"clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11\"><param name=\"Command\" value=\""+sCommand+"\"></object>";
                    document.body.appendChild(oCmd);
                    oCmd=document.getElementById("Cmd"+sCommand);
            }
            oCmd.Click();
    }
    var oNewWindowID;
    var bStarted=false;
    var oSFCTimeout=null;
    function ScanForClose(bFirst){
            if(bFirst==true&&bStarted==true){
                    return;
            }
            else{
                    bStarted=true;
                    try{
                            if(oNewWindowID.closed==true){
                                    window.top.resizeTo(window.screen.width,window.screen.height);
                                    window.top.moveTo(0,0);
                                    window.top.resizeTo(window.screen.width,window.screen.height);
                                    bStarted=false;
                            }
                            else{
                                    oSFCTimeout=window.setTimeout("ScanForClose(false);",100);
                            }
                    }
                    catch(err){
                    }
            }
    }
    function TryClose(){
            if(oNewWindowID.closed!=true){
                    oNewWindowID.close();
            }
            window.top.resizeTo(window.screen.width,window.screen.height);
            window.top.moveTo(0,0);
            window.top.resizeTo(window.screen.width,window.screen.height);
    }
    function TryFocus(){
            if(oNewWindowID.closed!=true){
                    try{
                            oNewWindowID.focus();
                            window.focus();
                            window.top.resizeTo(iWinWidth,iWinHeight);
                            window.top.moveTo(iWinLeft,iWinTop);
                            window.top.resizeTo(iWinWidth,iWinHeight);
                    }
                    catch(err){
                    }
            }
    }

    //2005-11-25

    //打开一个新的窗口,不包含多余的浏览器按钮
    //sUrl:需要打开的文件的位置
    //iStyle:窗口样式,1:window,2:ModalDialogue,4:ModelessDialogue,8:调整父窗口位置和大小使之和子窗口刚好站满全部屏幕,16:当子窗口关闭时,父窗口恢复到满屏,32:当父窗口获得焦点时,字窗口也获得焦点,64:父窗口重新装载时关闭子窗口
    //sName:窗口名称
    //iPosition:相关参数参考WinPosition对象
    //oArguments:要传递的参数 对使用Open方法打开的窗口无效
    //bScroll:是否允许滚动条 默认为no
    //bFullScreen:是否全屏 默认为no

    var iWinLeft,iWinTop,iWinHeight,iWinWidth;
    function OpenWindow(sUrl,iStyle,sName,iPosition,iLeft,iTop,iWidth,iHeight,oArguments,bScroll,bFullScreen){
            if(bScroll!="yes"&&bScroll!=1&&bScroll!=true){
                    bScroll="no";
            }
            if(bFullScreen!="yes"&&bFullScreen!=1&&bFullScreen!=true){
                    bFullScreen="no";
            }
            var oPosition=new WinPosition(iPosition,iLeft,iTop,iWidth,iHeight);
            if(oArguments==null)
            {
                    oArguments="";
            }
            var oNewWin;
            if((iStyle&8)==8){
                    if((iPosition&4)==4&&oPosition.Height>window.screen.height*0.5&&oPosition.Left<window.screen.width*0.5){//子窗口靠近左侧
                            iTop=oPosition.Top;
                            iLeft=oPosition.Width+10;
                            iWidth=window.screen.width-oPosition.Width-10;
                            iHeight=oPosition.Height;
                    }
                    if((iPosition&64)==64&&oPosition.Height>window.screen.height*0.5&&oPosition.Left>window.screen.width*0.5){//子窗口靠近右侧
                            iTop=oPosition.Top;
                            iLeft=0;
                            iWidth=window.screen.width-oPosition.Width-10;
                            iHeight=oPosition.Height;
                    }
                    if((iPosition&8)==8&&oPosition.Top+oPosition.Height<window.screen.height*0.5&&oPosition.Width>window.screen.width*0.5){//子窗口靠近顶部
                            iTop=oPosition.Top+oPosition.Height+10;
                            iLeft=oPosition.Left;
                            iWidth=oPosition.Width;
                            iHeight=window.screen.height-oPosition.Height-10;
                    }
                    if((iPosition&128)==128&&oPosition.Top>window.screen.height*0.5&&oPosition.Width>window.screen.width*0.5){//子窗口靠近底部
                            iTop=0;
                            iLeft=oPosition.Left;
                            iWidth=oPosition.Width;
                            iHeight=window.screen.height-oPosition.Height-10;
                    }
                    window.top.resizeTo(iWidth,iHeight);
                    window.top.moveTo(iLeft,iTop);
                    window.top.resizeTo(iWidth,iHeight);
                    iWinLeft=iLeft;
                    iWinTop=iTop;
                    iWinWidth=iWidth;
                    iWinHeight=iHeight;
            }
            if((iStyle&1)==1){
                    oNewWin=window.open(sUrl,sName,"left="+oPosition.Left+",top="+oPosition.Top+",width="+oPosition.Width+",height="+oPosition.Height+",scrollbars="+bScroll+",menubar=no,status=no,resizable=no,titlebar=no,toolbar=no,fullscreen="+bFullScreen,true);
            }
            else if((iStyle&2)==2){
                    oNewWin=window.showModalDialog(sUrl,oArguments,"dialogHeight: "+oPosition.Height+"px; dialogWidth: "+oPosition.Width+"px; dialogTop: "+oPosition.Top+"px; dialogLeft: "+oPosition.Left+"px; edge: Sunken; center: Yes; help: No; resizable: No; status: No;");
            }
            else if((iStyle&4)==4){
                    oNewWin=window.showModelessDialog(sUrl,oArguments,"dialogHeight: "+oPosition.Height+"px; dialogWidth: "+oPosition.Width+"px; dialogTop: "+oPosition.Top+"px; dialogLeft: "+oPosition.Left+"px; edge: Sunken; center: Yes; help: No; resizable: No; status: No;");
            }
            if((iStyle&16)==16){
                    oNewWindowID=oNewWin;
                    ScanForClose(true);
            }
            if((iStyle&32)==32){
                    window.onfocus=TryFocus;
            }
            else{
                    bStarted=false;
                    window.clearTimeout(oSFCTimeout);
            }
            if((iStyle&64)==64){
                    oNewWindowID=oNewWin;
                    window.onunload=TryClose;
            }
            return oNewWin;
    }

    //显示Popup
    //sText:Popup的内容
    //sStyle:样式,不能使用CSS类
    //iPosition及相关参数参考WinPosition对象
    //iRenderStyle参考PopUp对象

    var oPopUp;
    function OpenPopup(sText,sStyle,iPosition,iLeft,iTop,iWidth,iHeight,iRenderStyle){
            var oPosition=new WinPosition(iPosition,iLeft,iTop,iWidth,iHeight);
            oPopUp=new PopUp(sText,sStyle,oPosition,iRenderStyle);
            RenderPopUp(true);
    }
    function RenderPopUp(bFirstRender){
            var oPopup=window.createPopup();
            var oPopupBody=oPopup.document.body;
            oPopupBody.innerHTML=oPopUp.Text;
            oPopupBody.runtimeStyle.cssText=oPopUp.Class+"filter:progid:DXImageTransform.Microsoft.Alpha(opacity="+oPopUp.Alpha+");";
            var bRenderIt=0;
            if(bFirstRender==true){
                    bRenderIt=1;
            }
            if(oPopUp.CurLeft>oPopUp.Left+2){
                    oPopUp.CurLeft-=2;
                    bRenderIt=1;
            }
            else if(oPopUp.CurLeft>oPopUp.Left){
                    oPopUp.CurLeft=oPopUp.Left;
            }
            if(oPopUp.CurLeft<oPopUp.Left-2){
                    oPopUp.CurLeft+=2;
                    bRenderIt=1;
            }
            else if(oPopUp.CurLeft<oPopUp.Left){
                    oPopUp.CurLeft=oPopUp.Left;
            }
            if(oPopUp.CurTop>oPopUp.Top+2){
                    oPopUp.CurTop-=2;
                    bRenderIt=1;
            }
            else if(oPopUp.CurTop>oPopUp.Top){
                    oPopUp.CurTop=oPopUp.Top;
            }
            if(oPopUp.CurTop<oPopUp.Top-2){
                    oPopUp.CurTop+=2;
                    bRenderIt=1;
            }
            else if(oPopUp.CurTop<oPopUp.Top){
                    oPopUp.CurTop=oPopUp.Top;
            }
            if(oPopUp.CurWidth<oPopUp.Width-2){
                    oPopUp.CurWidth+=2;
                    bRenderIt=1;
            }
            else if(oPopUp.CurWidth<oPopUp.Width){
                    oPopUp.CurWidth=oPopUp.Width;
            }
            if(oPopUp.CurHeight<oPopUp.Height-2){
                    oPopUp.CurHeight+=2;
                    bRenderIt=1;
            }
            else if(oPopUp.CurHeight<oPopUp.Height){
                    oPopUp.CurHeight=oPopUp.Height;
            }
            if((oPopUp.RenderStyle&16)==16&&oPopUp.CurWidth<oPopUp.Width-2){
                    oPopUp.CurWidth+=2;
            }
            else if((oPopUp.RenderStyle&16)==16&&oPopUp.CurWidth<oPopUp.Width){
                    oPopUp.CurWidth=oPopUp.Width;
            }
            if((oPopUp.RenderStyle&32)==32&&oPopUp.CurHeight<oPopUp.Height-2){
                    oPopUp.CurHeight+=2;
            }
            else if((oPopUp.RenderStyle&32)==32&&oPopUp.CurHeight<oPopUp.Height){
                    oPopUp.CurHeight=oPopUp.Height;
            }
            if(oPopUp.Alpha<100){
                    oPopUp.Alpha+=2;
                    bRenderIt=1;
            }
            if(bRenderIt==1){
                    oPopup.show(oPopUp.CurLeft,oPopUp.CurTop,oPopUp.CurWidth,oPopUp.CurHeight,document.body);
                    if(oPopUp.RenderStyle>0)
                    {
                            window.setTimeout("RenderPopUp()",10);
                    }
            }
            else if(oPopUp.RenderTime<80){
                    oPopUp.RenderTime++;
                    oPopup.show(oPopUp.CurLeft,oPopUp.CurTop,oPopUp.CurWidth,oPopUp.CurHeight,document.body);
                    window.setTimeout("RenderPopUp()",10);
            }
    }
    //PopUp对象,用于描述需要打开的PopUp
    //iRenderStyle:控制呈现方式
    //                0:静态展示
    //                1:横向向右扩展
    //                2:纵向向下扩展
    //                4:横向向左扩展
    //                8:纵向向上扩展
    //                16:宽度从0向指定宽度扩展
    //                32:高度从0向指定高度扩展
    //                64:透明度从0扩展到100

    function PopUp(sText,sClass,oPosition,iRenderStyle){
            this.Text=sText;
            this.Class=sClass;
            this.RenderStyle=iRenderStyle;
            this.CurLeft=oPosition.Left;
            this.CurTop=oPosition.Top;
            this.CurWidth=oPosition.Width;
            this.CurHeight=oPosition.Height;
            this.Left=oPosition.Left;
            this.Top=oPosition.Top;
            this.Width=oPosition.Width;
            this.Height=oPosition.Height;
            this.Alpha=100;
            if((iRenderStyle&1)==1){
                    this.CurLeft-=this.CurWidth;
                    this.CurWidth=0;
            }
            if((iRenderStyle&2)==2){
                    this.CurTop-=this.CurHeight;
                    this.CurHeight=0;
            }
            if((iRenderStyle&4)==4){
                    this.CurLeft+=this.CurWidth;
                    this.CurWidth=0;
            }
            if((iRenderStyle&8)==8){
                    this.CurTop+=this.CurHeight;
                    this.CurHeight=0;
            }
            if((iRenderStyle&16)==16){
                    this.CurLeft+=parseInt(this.CurWidth)/2;
                    this.CurWidth=0;
            }
            if((iRenderStyle&32)==32){
                    this.CurTop+=parseInt(this.CurHeight)/2;
                    this.CurHeight=0;
            }
            if((iRenderStyle&64)==64){
                    this.Alpha=0;
            }
            this.RenderTime=0;
    }
    //WinPosition对象,用于描述需要打开的窗口的位置
    //iPosition:控制Popup或者Window的位置
    //                0:绝对位置
    //                1:X相对于鼠标位置
    //                2:Y相对于鼠标位置
    //                4:X=窗口左侧
    //                8:Y=窗口顶部
    //                16:X=窗口横向中间
    //                32:Y=窗口纵向中间
    //                64:X=窗口右侧
    //                128:Y=窗口底部
    //                256:按照窗口百分比计算宽度
    //                512:按照窗口百分比计算高度
    //                有用的组合,3:相对于鼠标位置,48:中心位置,12:左上角,72:右上角,192:右下角,132:左下角

    function WinPosition(iPosition,iLeft,iTop,iWidth,iHeight){
            this.ErrorMesg="";
            iLeft=iLeft==null?0:iLeft;
            iTop=iTop==null?0:iTop;
            iWidth=iWidth==null?window.screen.width/4:iWidth;
            iHeight=iHeight==null?window.screen.height/4:iHeight;
            iWidth=iWidth>window.screen.width?window.screen.width:iWidth;
            iHeight=iHeight>window.screen.height?window.screen.height:iHeight;
            if((iPosition&256)==256){
                    iWidth=parseInt(window.screen.width*(iWidth%101)/100);
            }
            if((iPosition&512)==512){
                    iHeight=parseInt(window.screen.height*(iHeight%101)/100);
            }
            if((iPosition&1)==1){
                    try{
                            iLeft=window.event.clientX+iLeft;
                    }
                    catch(err){
                            this.ErrorMesg=err.description;
                    }
            }
            if((iPosition&2)==2){
                    try{
                            iTop=window.event.clientY+iTop;
                    }
                    catch(err){
                            this.ErrorMesg=err.description;
                    }
            }
            if((iPosition&4)==4){
                    iLeft=0;
            }
            if((iPosition&8)==8){
                    iTop=0;
            }
            if((iPosition&16)==16){
                    iLeft=parseInt((window.screen.availWidth-iWidth)/2);
            }
            if((iPosition&32)==32){
                    iTop=parseInt((window.screen.availHeight)/2-iHeight);
            }
            if((iPosition&64)==64){
                    iLeft=window.screen.availWidth-iWidth;
            }
            if((iPosition&128)==128){
                    iTop=window.screen.availHeight-iHeight;
            }
            this.Left=iLeft;
            this.Top=iTop;
            this.Width=iWidth;
            this.Height=iHeight;
    }

    May 11

    开张大吉

    开张大吉