JS代码格式化和语法着色V2

2019-06-03 18:16:39王旭

    cmdStop=document.getElementById("cmdStop");
    divJSExport=document.getElementById("divJSExport");
    selJSExport=document.getElementById("selJSExport");
    divJSExportContent=document.getElementById("divJSExportContent");

    // init window state
    maximizeWindow();

    divMain.style.width=document.body.clientWidth-4;
    divMain.style.height=document.body.clientHeight-26;

    divJSOutput.style.width=document.body.clientWidth-72;

    
    // init global events

divJSOutputLineNo.onselectstart=divJSOutputLineNo.onselect=divJSOutputPlus.onselectstart=divJSOutputPlus.onselect=cancelEvent

    divJSOutput.onscroll=divJSOutput_onscroll;

    divJSInput.onkeydown=divJSInput_keydown;
    divJSExport.onkeydown=divJSExport_keydown;

}


//------------------
// event scripts
//------------------

function cancelEvents(e){
    var e=window.event?window.event:e;
    e.returnValue=false;
    return(false);
}

function divJSInput_keydown(e){
    var e=window.event?window.event:e;
    var srcEle=e.srcElement?e.srcElement:e.target;
    var sel;
    if(e.keyCode==27)hideJSInput();
    if(e.keyCode==13&&e.ctrlKey)execJSInput();
    if(e.keyCode==9&&srcEle==txtJSInput){
        document.selection.createRange().text="t";return(false); // not support FF    
    }
}

function divJSExport_keydown(e){
    var e=window.event?window.event:e;
    var srcEle=e.srcElement?e.srcElement:e.target;
    var sel;
    if(e.keyCode==27)hideJSExport();
    if(e.keyCode==13&&e.ctrlKey)hideJSExport();
}

function divJSOutput_onscroll(){
    divJSOutputLineNo.scrollTop=divJSOutputPlus.scrollTop=divJSOutput.scrollTop;
}



//------------------
// functional scripts
//------------------

function showJSInput(){
    if(glbBusy)return;
    hideJSExport();
    with(divJSInput.style){
        display="block";
        left=(document.body.clientWidth-divJSInput.offsetWidth)/2;
        top=(document.body.clientHeight-divJSInput.offsetHeight)/2;