Changeset 17902 for misc/runpugs

Show
Ignore:
Timestamp:
09/18/07 14:00:53 (14 months ago)
Author:
moritz
Message:

[runpugs] attempt to fix German keyboard weirdness
(AltGr? produces a 0 byte)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • misc/runpugs/htdocs/runpugs/runpugs.js

    r17899 r17902  
    44var reldev=0; 
    55 
     6 
    67var curpos=0; 
     8 
    79var cmd = ""; 
     10 
    811var prompt = "pugs> "; 
     12 
    913var cmds = new Array(); 
     14 
    1015var theme = "wb_theme"; 
     16 
    1117var fixedCharWidth; 
     18 
     19 
    1220 
    1321//show the cursor 
    1422function showCursor() { 
     23 
    1524    var cmdLen = cmds.length; 
     25 
    1626    var cursorEl = (cmdLen == 0) ? "#d0" : "#d" + (cmdLen - 1); 
     27 
    1728    $(cursorEl).toggleClass('cursorOff'); 
     29 
    1830    $(cursorEl).toggleClass('cursorOn'); 
     31 
    1932    setTimeout('showCursor()',1000); 
    20 } 
     33 
     34} 
     35 
     36 
    2137 
    2238//move the cursor by css 
     39 
    2340function moveCursor() { 
     41 
    2442    var left = -(cmd.length-curpos) * fixedCharWidth; 
     43 
    2544    var cursorEl = "#d" + (cmds.length - 1); 
     45 
    2646    $(cursorEl).css('left',left + "px"); 
    27 } 
     47 
     48} 
     49 
     50 
    2851 
    2952//show last command on console 
     53 
    3054function showCmd() { 
     55 
    3156    var cmdEl = "#c" + (cmds.length - 1); 
     57 
    3258    $(cmdEl).text(prompt + cmd); 
    33 } 
     59 
     60} 
     61 
     62 
    3463 
    3564//update the console 
     65 
    3666function updateConsole() { 
     67 
    3768    $.each(cmds,function(i,n) { 
     69 
    3870        if(i == 0) { 
     71 
    3972            //clear only on first usage... 
     73 
    4074            $("#tt").empty(); 
    41         } 
     75 
     76        } 
     77 
    4278        var l = (n == "") ? " " : n; 
     79 
    4380        var tr = "<tr><td><pre id='c" + i +  
     81 
    4482            "' class='"+ theme +"'>" + l + "</pre>"; 
     83 
    4584        if(i == cmds.length - 1) { 
     85 
    4686            tr += "<span id='d" + i +  
     87 
    4788            "' class='cursorOff'>&nbsp;</span>"; 
     89 
    4890        }  
     91 
    4992        $("#tt").append(tr + "</td></tr>"); 
     93 
    5094    }); 
     95 
    5196    var scrollHeight = $("#termwin")[0].scrollHeight; 
     97 
    5298    $("#termwin").animate({ scrollTop: scrollHeight }, "fast") 
    53 } 
     99 
     100} 
     101 
     102 
    54103 
    55104//wait for when the document is ready 
     105 
    56106$(document).ready( function() { 
     107 
    57108    //display waiting msg and try to calculate width of  
     109 
    58110    //a single fixed character... 
     111 
    59112    var msg = "Please wait while Pugs starts up..."; 
     113 
    60114    $("#tt").empty(); 
     115 
    61116    $("#tt").append("<tr><td><pre id='c0' class='wb_theme'>" + msg + 
     117 
    62118    "</pre><span id='d0' class='cursorOff'>&nbsp;</span></td></tr>"); 
     119 
    63120    fixedCharWidth = ($("#c0")[0]) ?  
     121 
    64122        $("#c0")[0].offsetWidth / msg.length : 8; 
    65123 
     124 
     125 
    66126    //apply theme and animate logo 
     127 
    67128    $("#theme").change(function() { 
     129 
    68130        $("pre").toggleClass(theme); 
     131 
    69132        theme = $("#theme").val(); 
     133 
    70134        $("pre").toggleClass(theme); 
     135 
    71136    }); 
     137 
    72138    $("#logo").slideDown(2000); 
    73139 
     140 
     141 
    74142    //repaint & start showing the cursor... 
     143 
    75144    showCursor(); 
    76145 
     146 
    77147    //attach keyboard listeners... 
     148 
    78149    $(document).keydown(function(event) { 
     150 
    79151        return onKeyDown(event); 
     152 
    80153    }); 
     154 
    81155    $(document).keypress(function(event) {     
     156 
    82157        return onKeyPress(event); 
     158 
    83159    }); 
    84160 
     161 
     162 
    85163    //attach pugs cleanup listener... 
     164 
    86165    $(window).unload(function() { 
     166 
    87167        //send :q to pugs on onload 
     168 
    88169        $.ajax({ 
     170 
    89171            url: "/perl/runpugs.pl?" + "sessionid=" + sessionid +  
     172 
    90173            "&reldev=1&ia=1&cmd=%3Aq", 
     174 
    91175            async: true 
     176 
    92177        }); 
     178 
    93179    }); 
    94180 
     181 
     182 
    95183    //start loading pugs session after page has loaded... 
     184 
    96185    $("#hidden_iframe").append( 
     186 
    97187        '<iframe src="/perl/runpugs.pl" id="scratch" name="scratch" ' + 
     188 
    98189        'style="visibility:hidden" width="700px" height="1px" ' + 
     190 
    99191        'onLoad="getreply()"></iframe>'); 
     192 
    100193}); 
    101194 
     195 
     196 
    102197//insert character 'ch' at index 'pos' in string str  
     198 
    103199//and return the result 
     200 
    104201function insert(str,ch,pos) { 
     202 
    105203    var s = str.substring(0,pos); 
     204 
    106205    var t = str.substring(pos,str.length); 
     206 
    107207    return s + ch + t; 
    108 } 
     208 
     209} 
     210 
     211 
    109212 
    110213//focus on last command very hard ;-) 
     214 
    111215function focusOnCmd(e) { 
     216 
    112217    $(e).focus(); 
     218 
    113219    var scrollHeight = $("#termwin")[0].scrollHeight; 
     220 
    114221    $("#termwin").animate({ scrollTop: scrollHeight }, "fast"); 
    115 } 
     222 
     223} 
     224 
     225 
    116226 
    117227//$.keydown 
    118228function onKeyDown(event) { 
     229 
    119230    if(event.ctrlKey || event.altKey || event.shiftKey) { 
     231 
    120232        //ignore ctrl and alt modifiers 
     233 
    121234        return true; 
    122     } 
     235 
     236    } 
     237 
     238 
    123239 
    124240    var keyCode = event.keyCode; 
    125241 
     242        if (keyCode == 0){ 
     243                return true; 
     244        } 
     245 
     246 
    126247    focusOnCmd("#status"); 
     248 
    127249     
     250 
    128251    if(keyCode == 13) { 
     252 
    129253        //enter 
     254 
    130255        var sessCmds=document.terminal.cmd.value + cmd; 
     256 
    131257        var tmpCmds=sessCmds.split(prompt); 
     258 
    132259        var tmpCmd=tmpCmds[tmpCmds.length-1]; 
     260 
    133261        if($.trim(tmpCmd) != "") { 
     262 
    134263            histlist.push(tmpCmd); 
    135         } 
     264 
     265        } 
     266 
    136267        frames['scratch'].document.getElementById("cmd").value=sessCmds; 
     268 
    137269        frames['scratch'].document.terminal.submit();  
     270 
    138271        cmd = ""; 
    139         return false; 
     272 
     273        return false; 
     274 
    140275         
     276 
    141277    } else if(keyCode == 8) { 
     278 
    142279        //backspace 
     280 
    143281        if(curpos > 0) { 
     282 
    144283            curpos -=1 
     284 
    145285            var newCmd = ""; 
     286 
    146287            for(var i = 0; i < cmd.length; i++) { 
     288 
    147289                if(i != curpos) { 
     290 
    148291                    newCmd += cmd.charAt(i); 
     292 
    149293                } 
     294 
    150295            } 
     296 
    151297            cmd = newCmd; 
     298 
    152299            showCmd(); 
    153         } 
    154         return false; 
     300 
     301        } 
     302 
     303        return false; 
     304 
    155305         
     306 
    156307    } else if(keyCode == 38) { 
     308 
    157309        //up 
     310 
    158311        hist_next(); 
    159         return false; 
     312 
     313        return false; 
     314 
    160315         
     316 
    161317    } else if(keyCode == 40) { 
     318 
    162319        //down 
     320 
    163321        hist_prev(); 
    164         return false; 
     322 
     323        return false; 
     324 
    165325         
     326 
    166327    } else if(keyCode == 37) { 
     328 
    167329        //left 
     330 
    168331        if(curpos > 0) { 
     332 
    169333            curpos--; 
     334 
    170335            moveCursor(); 
    171         } 
    172         return false; 
     336 
     337        } 
     338 
     339        return false; 
     340 
    173341         
     342 
    174343    } else if(keyCode == 39) { 
     344 
    175345        //right 
     346 
    176347        if(curpos < cmd.length) { 
     348 
    177349            curpos++; 
     350 
    178351            moveCursor(); 
    179         } 
    180         return false; 
     352 
     353        } 
     354 
     355        return false; 
     356 
    181357    } else if(keyCode == 36) { 
     358 
    182359        //home 
     360 
    183361        curpos = 0; 
     362 
    184363        moveCursor(); 
    185         return false; 
     364 
     365        return false; 
     366 
    186367     
     368 
    187369    } else if(keyCode == 35) { 
     370 
    188371        //end 
     372 
    189373        curpos = cmd.length; 
     374 
    190375        moveCursor(); 
    191         return false; 
     376 
     377        return false; 
     378 
    192379   
     380 
    193381    } else if(keyCode == 46) { 
     382 
    194383        //del 
     384 
    195385        if(curpos >= 0){ 
     386 
    196387            var newCmd = ""; 
     388 
    197389            for(var i = 0; i < cmd.length; i++) { 
     390 
    198391                if(i != curpos) { 
     392 
    199393                    newCmd += cmd.charAt(i); 
     394 
    200395                } 
     396 
    201397            } 
     398 
    202399            cmd = newCmd; 
     400 
    203401            showCmd(); 
     402 
    204403            moveCursor(); 
    205         } 
    206         return false; 
    207     } 
     404 
     405        } 
     406 
     407        return false; 
     408 
     409    } 
     410 
    208411    return true; 
    209 } 
     412 
     413} 
     414 
     415 
    210416 
    211417//$.keypress 
     418 
    212419function onKeyPress(event) { 
    213420 
     421 
     422 
    214423    if(event.ctrlKey || event.altKey) { 
     424 
    215425        //ignore ctrl and alt modifiers 
     426 
    216427        return; 
    217     } 
     428 
     429    } 
     430 
     431 
    218432 
    219433    focusOnCmd("#status"); 
    220434 
     435 
     436 
    221437    var keyCode = event.keyCode; 
     438 
    222439    if($.browser.msie || $.browser.opera || $.browser.safari) { 
     440 
    223441        var key = String.fromCharCode(keyCode); 
     442 
    224443        if(key >= ' ') { 
     444 
    225445            if(($.browser.opera && (keyCode < 35 || keyCode > 40)) || $.browser.msie || $.browser.safari) { 
     446 
    226447                //insert key at curpos 
     448 
    227449                cmd = insert(cmd,key,curpos); 
     450 
    228451                showCmd(); 
     452 
    229453                curpos++; 
     454 
    230455            } 
    231         } 
    232         return false; 
     456 
     457        } 
     458 
     459        return false; 
     460 
    233461    } else if($.browser.mozilla && keyCode == 0) { 
     462 
    234463        var key = String.fromCharCode(event.charCode ? event.charCode : event.keyCode); 
     464 
    235465        //insert key at curpos 
     466 
    236467        cmd = insert(cmd,key,curpos); 
     468 
    237469        showCmd(); 
     470 
    238471        curpos++; 
    239         return false; 
    240     } 
     472 
     473        return false; 
     474 
     475    } 
     476 
    241477    return true; 
    242 } 
     478 
     479} 
     480 
    243481 
    244482//called by textarea: TODO should be removed when textarea  
     483 
    245484//is replaced by async $.ajax  
    246485function getreply () { 
     
    250489    sessionid=scratchpad.terminal.sessionid.value; 
    251490    document.terminal.cmd.value=reply; 
     491 
    252492     
     493 
    253494    if(scratchpad.terminal.prompt) { 
     495 
    254496        //safely assign prompt... 
     497 
    255498        var val = scratchpad.terminal.prompt.value; 
     499 
    256500        if(val && val.length == 'pugs> '.length) { 
     501 
    257502            prompt = val; 
    258         } 
    259     } 
     503 
     504        } 
     505 
     506    } 
     507 
    260508     
     509 
    261510    //escape html from whitespace and html entities 
     511 
    262512    //and then split lines 
     513 
    263514        cmds =  
     515 
    264516        reply.replace(/&/g,'&amp;') 
     517 
    265518        .replace(/ /g,'&nbsp;') 
     519 
    266520        .replace(/</g,'&lt;') 
     521 
    267522        .replace(/>/g,'&gt;') 
     523 
    268524        .replace(/"/g,'&quot;') 
     525 
    269526        .split(/\r\n|\n|\r/g); 
     527 
    270528    updateConsole(); 
     529 
    271530    cmd = ""; 
     531 
    272532    curpos=0; 
     533 
    273534    showCmd(); 
    274 } 
     535 
     536} 
     537 
    275538 
    276539//next in history (triggered by DOWN) 
     
    279542        histentry--; 
    280543        cmd=histlist[histentry]; 
     544 
    281545        curpos=cmd.length; 
     546 
    282547        showCmd(); 
     548 
    283549        moveCursor(); 
     550 
    284551    } 
    285552    return false; 
    286553} 
     554 
    287555 
    288556//previous in history (triggered by UP) 
     
    291559        histentry++; 
    292560        cmd=histlist[histentry]; 
     561 
    293562        curpos=cmd.length; 
     563 
    294564        showCmd(); 
     565 
    295566        moveCursor(); 
    296     } 
    297 } 
     567 
     568    } 
     569} 
     570 
    298571 
    299572//triggered by user selecting release/development version 
     
    307580        frames['scratch'].document.terminal.reldev[1].checked=true; 
    308581    } 
     582 
    309583    frames['scratch'].document.terminal.submit(); 
    310584 
     585 
     586 
    311587    focusOnCmd("#tt"); 
    312588}