Topic: Help !!

Hello,

Im looking for a solution that allow me to display  a div like a window but in the same time disable everything behind it.
in order thet the end user cannot do anything in the element behind de window.

Someone can help me how to do that?

thanks.

Re: Help !!

( An out of xajax javascript question, I think smile )
Disabling is easy but do you want to use this script :

Code: PHP

http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/index.htm

Re: Help !!

I'm using Prototype window, it's flexible and easy to use.

To make things easy I added a Javascript wrapper, and call these functions from Xajax. It's not a plugin because I'm still using Xajax 0.2.x

Code: PHP

function showConfirmDialog(dlgTitle, dlgContent, okCall)

{

  eval('Dialog.confirm("' + dlgContent + '", {className: "dialog", buttonClass: "button", title:"' + dlgTitle + '", width: 425, height: 140, zIndex: 100, resizable: true, minimizable: false, maximizable: false, draggable: true, okLabel: "Ja", cancelLabel:"Nee", onOk:function(win){ ' + okCall + '; return true;}})');

}



function showErrorDialog(dlgTitle, dlgContent)

{

  eval('Dialog.alert("' + dlgContent + '", {className: "dialog", buttonClass: "button", title:"' + dlgTitle + '", width: 425, height: 140, zIndex: 100, resizable: true, minimizable: false, maximizable: false, draggable: true, okLabel: "Sluiten"})');

}

I also created a subclass of the xajaxResponse class, and added some of my own functions there. One of the examples is a call to the functions above.
From my server file I can do calls like this:

Code: PHP

$objResponse->showYesNoDialog('Delete contact', $txt, 'xajax_deleteContact(\'' . $id . '\', listContacts.getSelectedItem())');

(After this example the original question became a Xajax javascript question after all wink)

Re: Help !!

Code: PHP

/***************************************************************************************/

//alert panel, like alert, disable all the element

function alertPanel(id){

    this.backDiv=document.createElement('DIV');

   

    //function called when click ok/cancel

    this.funcOk=false;

    this.funcCancel=false;

   

    //resize

    this.sw=1;

    this.sh=1;

   

    this.w=0;

    this.h=0;

   

    this.fw=300;

    this.fh=200;

    this.ft=100;

    this.opened=false;

    this.openedh=false;//opened by  hangUp, can't close when press esc

   

    this.backDiv.style.cssText='filter:alpha(opacity=4);'+

                            '-moz-opacity:0.04;'+

                            'opacity:0.04;'+

                            'background-color:#000000;';

    document.body.appendChild(this.backDiv);

    this.backDiv.style.display='none';

    this.backDiv.style.position='absolute';

    this.backDiv.style.zIndex=999;

    this.backDiv.style.left='0px';

    this.backDiv.style.top='0px';

   

    if(_reportPanel){

        this.w=parseInt(_reportPanel.parentDiv.offsetLeft+_reportPanel.parentDiv.offsetWidth)+(document.all?10:0);

        this.h=parseInt(_reportPanel.parentDiv.offsetTop+_reportPanel.parentDiv.offsetHeight);

    }else{

        this.w=parseInt(window.screen.width);

        this.h=parseInt(window.screen.height);

    }

   

    this.backDiv.style.width=this.w+'px';

    this.backDiv.style.height=this.h+'px';

   

    this.foreDiv=document.createElement('DIV');

    document.body.appendChild(this.foreDiv);

    this.foreDiv.style.display='none';

    this.foreDiv.style.position='absolute';

    this.foreDiv.style.zIndex=999;

    this.foreDiv.style.background='buttonface';

   

    this.foreDiv.style.border="2px outset #000000";

    this.foreDiv.style.overflowX="auto";

   

    this.messageDiv=document.createElement('DIV');

    this.messageDiv.style.paddingTop='10px';

    this.messageDiv.style.overflowX="auto";

    this.messageDiv.style.overflowY="auto";

   

    this.buttonDiv=document.createElement('DIV');

    this.buttonDiv.style.textAlign='center';

   

    this.foreDiv.appendChild(this.messageDiv);

    this.foreDiv.appendChild(this.buttonDiv);

   

    this.buttonOk=document.createElement('INPUT');

    this.buttonOk.type='BUTTON';

    this.buttonOk.onclick=onClickAlertPanelOk;

    this.buttonOk.value='OK';

    this.buttonOk.style.marginTop='-6px';

   

    this.buttonCancel=document.createElement('INPUT');

    this.buttonCancel.type='BUTTON';

    this.buttonCancel.onclick=onClickAlertPanelCancel;

    this.buttonCancel.value='CANCEL';

    this.buttonCancel.style.marginTop='-6px';

   

    this.sline=document.createElement('HR');

    this.buttonDiv.appendChild(this.sline);

    this.buttonDiv.appendChild(this.buttonOk);

    this.buttonDiv.appendChild(this.buttonCancel);

    this.buttonCancel.style.display='none';

   

    this.showButtonCancel=function(){

        this.buttonCancel.style.display='inline';

    }

   

    this.hideButtonCancel=function(){

        this.buttonCancel.style.display='none';

    }

   

    this.disableButtonOk=function(){

        this.buttonOk.disabled=true;

    }

   

    this.activeButtonOk=function(){

        this.buttonOk.disabled=false;

    }

   

    this.onKeyDownEsc=function(){

        if(!this.openedh){

            this.onClickCancel();

        }

    }

   

    this.setFuncOk=function(func){

        this.funcOk=func;

    }

   

    this.setFuncCancel=function(func){

        this.funcCancel=func;

    }

   

    this.onClickOk=function(){

        if(this.funcOk){

            if(typeof(funcOk)=='function'){

                this.funcOk();

            }else{

                eval(this.funcOk);

            }

        }

        this.close();

    }

   

    this.onClickCancel=function(){

        if(this.funcCancel){

            if(typeof(funcCancel)=='function'){

                this.funcCancel();

            }else{

                eval(this.funcCancel);

            }

        }

        this.close();

    }

   

    this.hideButtonDiv=function(){

        this.buttonDiv.style.display='none';

        this.resetSize();

    }

   

    this.showButtonDiv=function(){

        this.buttonDiv.style.display='block';

        this.resetSize();

    }

   

    //resize

    this.setS=function(ssw,ssh){

        this.sw=ssw?ssw:1;

        this.sh=ssh?ssh:1;

    }

   

    this.resetSize=function(){

        var rsw=this.sw?this.sw:1;

        var rsh=this.sh?this.sh:1;

        var fw=this.fw*rsw;

        var fh=this.fh*rsh;

        this.foreDiv.style.left=(this.w/2-fw/2)+'px';

        this.foreDiv.style.top=(this.h/2-fh/2-this.ft)+'px';

        this.foreDiv.style.width=fw+'px';

        this.foreDiv.style.height=fh+'px';

        this.messageDiv.style.width=fw+'px';

        this.messageDiv.style.height=(fh-(this.buttonDiv.style.display=='none'?20:45))+'px';

    }

   

    this.resizeWidth=function(){

        //this.messageDiv.style.width=(parseInt(this.messageDiv.scrollWidth)+1)+'px';

        //this.foreDiv.style.width=(parseInt(this.foreDiv.scrollWidth)+1)+'px';

    }

   

   

    this.open=function(){

        this.resetSize();

        this.backDiv.style.display='block';

        this.foreDiv.style.display='block';

        if(this.buttonOk.disabled==false && this.buttonDiv.style.display!='none')this.buttonOk.focus();

        disableSelectS();

        this.resizeWidth();

        this.setFuncOk(false);

        this.setFuncCancel(false);

    }

   

    this.close=function(){

        this.backDiv.style.display='none';

        this.foreDiv.style.display='none';

        //some times, message is a div element. can not clear here for confirm used setTimeout

        //this.setMessage('');

        activeSelectS();

        this.opened=false;

        this.openedh=false;

        this.setS(1,1);

        this.showButtonDiv();

    }

   

    this.isHtmlString=function(s){

        var reg=/[<>]/;

        return reg.test(s);

    }

   

    this.tranString=function(s){

        return this.isHtmlString(s)?s:('<span style="background:yellow;">'+s+'</span>');

    }

   

    this.setMessage=function(s){

        this.messageDiv.innerHTML=this.tranString(s);

    }

   

    this.appendMessage=function(s){

        this.messageDiv.innerHTML+='<br/>'+this.tranString(s);

    }

   

    //simple alert

    this.alertMessage=function(s){

        this.activeButtonOk();

        this.hideButtonCancel();

        if(this.opened){

            this.appendMessage(s);

            this.resizeWidth();

            return true;

        }else{

            this.setMessage(s);

            this.opened=true;

            this.open();

        }

    }

   

    //hang up a message wait for server addScript to close it

    this.hangUpMessage=function(s){

        this.opened=false;

        this.hideButtonCancel();

        this.disableButtonOk();

        if(this.openedh){

            this.appendMessage(s);

            this.resizeWidth();

            return true;

        }else{

            this.setMessage(s);

            this.openedh=true;

            this.open();

        }

    }

}



function onClickAlertPanelOk(){

    if(_alertPanel)with(_alertPanel){

        onClickOk();

    }

}



function onClickAlertPanelCancel(){

    if(_alertPanel)with(_alertPanel){

        onClickCancel();

    }

}



function setAlertS(sasw,sash){

    if(_alertPanel)with(_alertPanel){

        setS(sasw,sash);

    }

}



function myAlert(s){

    if(_alertPanel)with(_alertPanel){

        alertMessage(s);

    }

}



function hangMsg(s){

    msgBox2(s);

    if(_alertPanel)with(_alertPanel){

        setS(1,0.3);

        hideButtonDiv();

        hangUpMessage(s);

    }

}



function hangClose(){

    if(_alertPanel)with(_alertPanel){

        close();

    }

}



//Because fok will be translated to string, all the variable can not be local, must be global.

//or get from global function

function myConfirm(msg,fok,fcancel){

    //not very well. myconfirm use the same alertPanel with myalert

    //so we need setTimout to wait

    var jsok='f='+fok+';'

        +'f2=function(){'

        +'    if(!_alertPanel.opened&&!_alertPanel.openedh){'

        +'        f();'

        +'    }else{'

        +'        setTimeout("f2()",100);'

        +'    }'

        +'};'

        +'f2();';

    var jscancel='f='+fcancel+';'

        +'f2=function(){'

        +'    if(!_alertPanel.opened&&!_alertPanel.openedh)'

        +'        f();'

        +'    else'

        +'        setTimeout("f2()",100);'

        +'};'

        +'f2();';

    //debug2(jsok);

    //debug2(jscancel);

    if(_alertPanel)with(_alertPanel){

        activeButtonOk();

        showButtonCancel();

        opened=true;

        open();

        setFuncOk(jsok);

        setFuncCancel(jscancel);

        setMessage(msg);

    }

}



//for ie's bug: select 's z-index

function disableSelectS(){

    var ss=document.getElementsByTagName('SELECT');

    var i,ssl=ss.length;

    for(i=0;i<ssl;i++){

        ss[i].disabled=true;

    }

}



function activeSelectS(){

    var ss=document.getElementsByTagName('SELECT');

    var i,ssl=ss.length;

    for(i=0;i<ssl;i++){

        ss[i].disabled=false;

    }

}

sample code

Code: PHP

function onClickTest(){

    myConfirm('test myConfirm function',

        function(){

            myAlert('you select ok');

        },

        function(){

            myAlert('you select cancel');

        }

    );

}

Last edited by leon (2007-09-11 9:51:28 AM)

@ @
  L______________eon.Z
   |                     |
  / \                   / \