<commit_before>/**
  * LzKeyboardKernel.js
  *
  * @copyright Copyright 2007,2008 Laszlo Systems, Inc.  All Rights Reserved.
  *            Use is subject to license terms.
  *
  * @topic Kernel
  * @subtopic DHTML
  * @author <NAME> &lt;<EMAIL>&gt;
  */

// Receives keyboard events from the runtime
var LzKeyboardKernel = { 
    __downKeysHash: {alt: false, control: false, shift: false}
    ,__keyboardEvent: function ( e ){   
        if (!e) e = window.event;
        var delta = {};
        var dirty = false;
        var k = e['keyCode'];
        var t = e.type; 
        var dh = LzKeyboardKernel.__downKeysHash;
        // TODO: really, all control characters should be skipped...
        // skip shift, ctrl, option keys to prevent duplicate sending - see LPP-4267
        if (k >= 0 && k != 16 && k != 17 && k != 18) {
            // TODO: add mapping to flash character codes?
            var s = String.fromCharCode(k).toLowerCase();
            if (t == 'keyup') {
                if (dh[s] != false) {
                    delta[s] = false;
                    dirty = true;
                }    
                dh[s] = false;
            } else if (t == 'keydown') {
                if (dh[s] != true) {
                    delta[s] = true;    
                    dirty = true;
                }    
                dh[s] = true;
            }    
        }    
        if (dh['alt'] != e['altKey']) {
            delta['alt'] = e['altKey'];
            dirty = true;
            if (LzSprite.prototype.quirks['alt_key_sends_control']) {
                delta['control'] = delta['alt'];
            }
        }    
        if (dh['control'] != e['ctrlKey']) {
            delta['control'] = e['ctrlKey'];
            dirty = true;
        }    
        if (dh['shift'] != e['shiftKey']) {
            delta['shift'] = e['shiftKey'];
            dirty = true;
        }    

        dh['alt'] = e['altKey'] 
        dh['control'] = e['ctrlKey'] 
        dh['shift'] = e['shiftKey']
        if (dirty && LzKeyboardKernel.__scope && LzKeyboardKernel.__scope[LzKeyboardKernel.__callback]) {
            LzKeyboardKernel.__scope[LzKeyboardKernel.__callback](delta, k, 'on' + t);
        } 
        
        // cancel bubbling
        if (k >= 0) {
            if (k == 9) {
                //Debug.write('canceling tab');
                e.cancelBubble = true;
                e.returnValue = false;
                return false;
            } else if (LzKeyboardKernel.__cancelKeys && (k == 13 || k == 0 || k == 37 || k == 38 || k == 39 || k == 40) ) {
                //Debug.write('canceling key', k, t);
                // cancel event bubbling for enter, space(scroll) and arrow keys
                e.cancelBubble = true;
                e.returnValue = false;
                return false;
            }    
        }    
        //Debug.write('downKeysHash', t, k, dh, delta);
    }

    ,__callback: null
    ,__scope: null
    ,__cancelKeys: true
    ,setCallback: function (scope, keyboardcallback) {
        this.__scope = scope;
        this.__callback = keyboardcallback;
        this.setKeyboardControl(true);
    }    
    ,setKeyboardControl: function (dhtmlKeyboardControl) {
        var kc = null;
        var ck = (lz && lz.embed && lz.embed.options && lz.embed.options.cancelkeyboardcontrol != true) || true;
        if (ck && dhtmlKeyboardControl) {
            //console.log('setKeyboardControl' + dhtmlKeyboardControl);
            kc = LzKeyboardKernel.__keyboardEvent;
        }
        // can't use lz.embed.attachEventHandler because we need to cancel events selectively
        if (LzSprite.prototype.quirks.keyboardlistentotop) {
            var doc = window.top.document;
        } else {
            var doc = document;
        }
        doc.onkeydown = kc;
        doc.onkeyup = kc;
        doc.onkeypress = kc;
    }
    // Called by lz.Keys when the last focusable element was reached.
    ,gotLastFocus: function () {
        //console.log('gotLastFocus', canvas.sprite.__LZdiv.mouseisover);
        if (! canvas.sprite.__LZdiv.mouseisover) LzKeyboardKernel.setKeyboardControl(false);
    }<commit_msg>Change 20080616-maxcarlson-R by maxcarlson@Roboto on 2008-06-16 15:27:14 PDT     in /Users/maxcarlson/openlaszlo/trunk-clean     for http://svn.openlaszlo.org/openlaszlo/trunk<commit_after>/**
  * LzKeyboardKernel.js
  *
  * @copyright Copyright 2007,2008 Laszlo Systems, Inc.  All Rights Reserved.
  *            Use is subject to license terms.
  *
  * @topic Kernel
  * @subtopic DHTML
  * @author <NAME> &lt;<EMAIL>&gt;
  */

// Receives keyboard events from the runtime
var LzKeyboardKernel = { 
    __downKeysHash: {alt: false, control: false, shift: false}
    ,__keyboardEvent: function ( e ){   
        if (!e) e = window.event;
        var delta = {};
        var dirty = false;
        var k = e['keyCode'];
        var t = e.type; 
        var dh = LzKeyboardKernel.__downKeysHash;
        // TODO: really, all control characters should be skipped...
        // skip shift, ctrl, option keys to prevent duplicate sending - see LPP-4267
        if (k >= 0 && k != 16 && k != 17 && k != 18) {
            // TODO: add mapping to flash character codes?
            var s = String.fromCharCode(k).toLowerCase();
            if (t == 'keyup') {
                if (dh[s] != false) {
                    delta[s] = false;
                    dirty = true;
                }    
                dh[s] = false;
            } else if (t == 'keydown') {
                if (dh[s] != true) {
                    delta[s] = true;    
                    dirty = true;
                }    
                dh[s] = true;
            }    
        }    
        if (dh['alt'] != e['altKey']) {
            delta['alt'] = e['altKey'];
            dirty = true;
            if (LzSprite.prototype.quirks['alt_key_sends_control']) {
                delta['control'] = delta['alt'];
            }
        }    
        if (dh['control'] != e['ctrlKey']) {
            delta['control'] = e['ctrlKey'];
            dirty = true;
        }    
        if (dh['shift'] != e['shiftKey']) {
            delta['shift'] = e['shiftKey'];
            dirty = true;
        }    

        dh['alt'] = e['altKey'] 
        dh['control'] = e['ctrlKey'] 
        dh['shift'] = e['shiftKey']
        if (dirty && LzKeyboardKernel.__scope && LzKeyboardKernel.__scope[LzKeyboardKernel.__callback]) {
            LzKeyboardKernel.__scope[LzKeyboardKernel.__callback](delta, k, 'on' + t);
        } 
        
        // cancel bubbling
        if (k >= 0) {
            if (k == 9) {
                //Debug.write('canceling tab');
                e.cancelBubble = true;
                e.returnValue = false;
                return false;
            } else if (LzKeyboardKernel.__cancelKeys && (k == 13 || k == 0 || k == 37 || k == 38 || k == 39 || k == 40) ) {
                //Debug.write('canceling key', k, t);
                // cancel event bubbling for enter, space(scroll) and arrow keys
                e.cancelBubble = true;
                e.returnValue = false;
                return false;
            }    
        }    
        //Debug.write('downKeysHash', t, k, dh, delta);
    }

    ,__callback: null
    ,__scope: null
    ,__cancelKeys: true
    ,setCallback: function (scope, keyboardcallback) {
        this.__scope = scope;
        this.__callback = keyboardcallback;
        this.setKeyboardControl(true);
    }    
    ,setKeyboardControl: function (dhtmlKeyboardControl) {
        var handler = null;
        var setcontrol = (lz && lz.embed && lz.embed.options && lz.embed.options.cancelkeyboardcontrol != true) || true;
        if (setcontrol && dhtmlKeyboardControl) {
            //console.log('setKeyboardControl' + dhtmlKeyboardControl);
            handler = LzKeyboardKernel.__keyboardEvent;
        }
        if ( LzInputTextSprite.prototype.__focusedSprite ) {
            // hide any focused inputtexts
            LzInputTextSprite.prototype.__focusedSprite.__hide();
        }
        // can't use lz.embed.attachEventHandler because we need to cancel events selectively
        if (LzSprite.prototype.quirks.keyboardlistentotop) {
            var doc = window.top.document;
        } else {
            var doc = document;
        }
        doc.onkeydown = handler;
        doc.onkeyup = handler;
        doc.onkeypress = handler;
    }
    // Called by lz.Keys when the last focusable element was reached.
    ,gotLastFocus: function () {
        //console.log('gotLastFocus', canvas.sprite.__LZdiv.mouseisover);
        if (! canvas.sprite.__LZdiv.mouseisover) LzKeyboardKernel.setKeyboardControl(false);
    }
{'fraction_non_alphanumeric': 0.1293331797765749, 'fraction_numerical': 0.009904410917885523, 'mean_word_length': 1.662170447578173, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3099963', 'n_tokens_mistral': 2637, 'n_tokens_neox': 2537, 'n_words': 608}