<commit_before>/*
 * cmdrjs
 * Version 1.0.0-alpha
 * Copyright 2014 Shaftware.
 * All Rights Reserved.  
 * Use, reproduction, distribution, and modification of this code is subject to the terms and 
 * conditions of the MIT license, available at http://www.opensource.org/licenses/mit-license.php
 *
 * Project: https://github.com/shaftware/cmdrjs
 */

; (function (define) {
    define(['jquery'], function($) {

        var version = '1.0.0-alpha',
            commands = {},
            activated = false,
            template = '<div class="cmdr" style="display: none"><div class="input"><textarea spellcheck="false" /></div><div class="output"></div></div>',
            container,
            input,
            textarea,
            output,
            outputLine,
            history = [],
            historyIndex = -1,
            config = {
                autoOpen: false,
                openKey: 96,
                closeKey: 27,
                echo: true
            };

        var cmdr = {
            activate: activate,
            deactivate: deactivate,
            reactivate: reactivate,
            open: open,
            close: close,
            write: write,
            writeLine: writeLine,
            clear: clear,
            execute: execute,
            setup: setup,
            commands: commands,
            config: config,
            version: version
        };

        cmdr.setup('CLS', function () {
            this.clear();
        });

        cmdr.setup('EXIT', function () {
            this.close();
        });

        cmdr.setup('ECHO', function (arg) {
            var toggle = arg.toUpperCase();
            if (toggle === 'ON') {
                this.config.echo = true;
            } else if (toggle === 'OFF') {
                this.config.echo = false;
            } else {
                this.writeLine(arg);
            }
        }, { parse: false });

        return cmdr;

        function activate() {
            if (activated) return;

            container = $(template).appendTo('body');
            input = $('.input', container);
            textarea = $('textarea', container);
            output = $('.output', container);

            $(document).on('keypress.cmdr', function (event) {
                if (!isOpen() && !$(event.target).is('input, textarea, select') && checkKey(event, config.openKey)) {
                    event.preventDefault();
                    open();
                } else if (isOpen() && checkKey(event, config.closeKey)) {
                    close();
                }
            });
            
            textarea.on('keydown', function (event) {
                switch(event.keyCode) {
                    case 13:
                        var command = textarea.val();
                        if (command) {
                            historyAdd(command);
                            execute(command);
                        }
                        return false;
                    case 38:
                        historyBack();
                        return false;
                    case 40:
                        historyForward();
                        return false;
                    case 9:
                        return false;
                }
                return true;
            });

            container.on('click', function(event) {
                if (!$(event.target).is('.textarea textarea, .output *')) {
                    textarea.focus();
                }
            });
            
            activated = true;

            if (config.autoOpen) {
                open();
            }
        }
<commit_msg>click selector fix<commit_after>/*
 * cmdrjs
 * Version 1.0.0-alpha
 * Copyright 2014 Shaftware.
 * All Rights Reserved.  
 * Use, reproduction, distribution, and modification of this code is subject to the terms and 
 * conditions of the MIT license, available at http://www.opensource.org/licenses/mit-license.php
 *
 * Project: https://github.com/shaftware/cmdrjs
 */

; (function (define) {
    define(['jquery'], function($) {

        var version = '1.0.0-alpha',
            commands = {},
            activated = false,
            template = '<div class="cmdr" style="display: none"><div class="input"><textarea spellcheck="false" /></div><div class="output"></div></div>',
            container,
            input,
            textarea,
            output,
            outputLine,
            history = [],
            historyIndex = -1,
            config = {
                autoOpen: false,
                openKey: 96,
                closeKey: 27,
                echo: true
            };

        var cmdr = {
            activate: activate,
            deactivate: deactivate,
            reactivate: reactivate,
            open: open,
            close: close,
            write: write,
            writeLine: writeLine,
            clear: clear,
            execute: execute,
            setup: setup,
            commands: commands,
            config: config,
            version: version
        };

        cmdr.setup('CLS', function () {
            this.clear();
        });

        cmdr.setup('EXIT', function () {
            this.close();
        });

        cmdr.setup('ECHO', function (arg) {
            var toggle = arg.toUpperCase();
            if (toggle === 'ON') {
                this.config.echo = true;
            } else if (toggle === 'OFF') {
                this.config.echo = false;
            } else {
                this.writeLine(arg);
            }
        }, { parse: false });

        return cmdr;

        function activate() {
            if (activated) return;

            container = $(template).appendTo('body');
            input = $('.input', container);
            textarea = $('textarea', container);
            output = $('.output', container);

            $(document).on('keypress.cmdr', function (event) {
                if (!isOpen() && !$(event.target).is('input, textarea, select') && checkKey(event, config.openKey)) {
                    event.preventDefault();
                    open();
                } else if (isOpen() && checkKey(event, config.closeKey)) {
                    close();
                }
            });
            
            textarea.on('keydown', function (event) {
                switch(event.keyCode) {
                    case 13:
                        var command = textarea.val();
                        if (command) {
                            historyAdd(command);
                            execute(command);
                        }
                        return false;
                    case 38:
                        historyBack();
                        return false;
                    case 40:
                        historyForward();
                        return false;
                    case 9:
                        return false;
                }
                return true;
            });

            container.on('click', function(event) {
                if (!$(event.target).is('.input textarea, .output *')) {
                    textarea.focus();
                }
            });
            
            activated = true;

            if (config.autoOpen) {
                open();
            }
        }

{'fraction_non_alphanumeric': 0.11926855895196506, 'fraction_numerical': 0.006004366812227074, 'mean_word_length': 1.1163730869188564, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '267080', 'n_tokens_mistral': 1822, 'n_tokens_neox': 1676, 'n_words': 410}