<commit_before>/*
 * Rapid Interface Builder (RIB) - A simple WYSIWYG HTML5 app creator
 * Copyright (c) 2011, Intel Corporation.
 *
 * This program is licensed under the terms and conditions of the
 * Apache License, version 2.0.  The full text of the Apache License is at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 */
"use strict";

/**
 * Global object for key handler.
 *
 */
$(function() {
    var navUtils = {
        enableKeys: function (element) {
            $(element).keyup(navUtils.shortCut);
            $(element).keydown(navUtils.tabHandler);
            $(element).keyup(navUtils.deleteHandler);
        },
        shortCut: function(e) {
            var charItem, shortKeys;
            shortKeys = {
                // "ctrl+z" for "undo"
                'z': 'undo',
                // "ctrl+y" for "redo"
                'y':'redo',
                // "ctrl+x" for "cut"
                'x':'cut',
                // "ctrl+c" for "copy"
                'c':'copy',
                // "ctrl+v" for "past"
                'v':'paste',
            };
            if (e.ctrlKey) {
                charItem = String.fromCharCode(e.which).toLowerCase();
                if (shortKeys[charItem]) {
                    $('#btn' + shortKeys[charItem] + ':visible').trigger("click");
                    return false;
                }
            }
            return true;
        },
        // for "tab"
        tabHandler: function (e) {
            var navItems = navUtils.enableFocus();
            if (e.which !== 9) {
                return true;
            }
            if (navItems.last().is(":focus")) {
                if (!e.shiftKey) {
                    e.preventDefault();
                    navItems.first().focus();
                    return false;
                }
            } else if (navItems.first().is(":focus")) {
                if (e.shiftKey) {
                    e.preventDefault();
                    navItems.last().focus();
                    return false;
                }
            }
        },
        // for "delete"
        deleteHandler: function (e) {
            if (e.which !== 46) {
                return true;
            } else {
                $('#deleteElement:visible').trigger("click");
                return false;
            }
        },
        /**
         * Enable items that wants to be focused by tab key.
         *
         * This is hard-coding, if all the views or elements can mark themself if it want key navigation,
         * such as add a class "navItem" to the elements, case will be better.
         */
        enableFocus: function () {
            var navItems, items, navPanes;
            navPanes = ['.navbar', '.pageView', '.propertyView', ".tools"];
            items = "a, button, input, select, textarea, area";
            navPanes.forEach(function (pane, index) {
                navItems = $(navItems).add($(":visible", pane).find(items));
            });
            navItems = $(navItems).add($(".treeView:visible"));
            navItems = $(navItems).add($(".pageIcon:visible"));
            navItems.attr("tabindex", 1);
            return navItems;
        }
    };

    /*******************  export pageUtils to $.rib **********************/
    $.rib = $.rib || {};
    $.rib.enableKeys = navUtils.enableKeys;
});<commit_msg>[General] Ignore shortcut keys in text area of property panel<commit_after>/*
 * Rapid Interface Builder (RIB) - A simple WYSIWYG HTML5 app creator
 * Copyright (c) 2011, Intel Corporation.
 *
 * This program is licensed under the terms and conditions of the
 * Apache License, version 2.0.  The full text of the Apache License is at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 */
"use strict";

/**
 * Global object for key handler.
 *
 */
$(function() {
    var navUtils = {
        enableKeys: function (element) {
            $(element).keyup(navUtils.shortCut);
            $(element).keydown(navUtils.tabHandler);
            $(element).keyup(navUtils.deleteHandler);
        },
        shortCut: function(e) {
            var charItem, shortKeys;
            shortKeys = {
                // "ctrl+z" for "undo"
                'z': 'undo',
                // "ctrl+y" for "redo"
                'y':'redo',
                // "ctrl+x" for "cut"
                'x':'cut',
                // "ctrl+c" for "copy"
                'c':'copy',
                // "ctrl+v" for "past"
                'v':'paste',
            };
            if (e.ctrlKey && !navUtils.ignoreText()) {
                charItem = String.fromCharCode(e.which).toLowerCase();
                if (shortKeys[charItem]) {
                    $('#btn' + shortKeys[charItem] + ':visible').trigger("click");
                    return false;
                }
            }
            return true;
        },
        // for "tab"
        tabHandler: function (e) {
            var navItems = navUtils.enableFocus();
            if (e.which !== 9) {
                return true;
            }
            if (navItems.last().is(":focus")) {
                if (!e.shiftKey) {
                    e.preventDefault();
                    navItems.first().focus();
                    return false;
                }
            } else if (navItems.first().is(":focus")) {
                if (e.shiftKey) {
                    e.preventDefault();
                    navItems.last().focus();
                    return false;
                }
            }
        },
        // for "delete"
        deleteHandler: function (e) {
            if (e.which !== 46 || navUtils.ignoreText()) {
                return true;
            } else {
                $('#deleteElement:visible').trigger("click");
                return false;
            }
        },
        /**
         * Enable items that wants to be focused by tab key.
         *
         * This is hard-coding, if all the views or elements can mark themself if it want key navigation,
         * such as add a class "navItem" to the elements, case will be better.
         */
        enableFocus: function () {
            var navItems, items, navPanes;
            navPanes = ['.navbar', '.pageView', '.propertyView', ".tools"];
            items = "a, button, input, select, textarea, area";
            navPanes.forEach(function (pane, index) {
                navItems = $(navItems).add($(":visible", pane).find(items));
            });
            navItems = $(navItems).add($(".treeView:visible"));
            navItems = $(navItems).add($(".pageIcon:visible"));
            navItems.attr("tabindex", 1);
            return navItems;
        },
        ignoreText: function () {
            return Boolean($('input[type="text"]:focus, textarea:focus',
                             '.property_content').length);
        },
    };

    /*******************  export pageUtils to $.rib **********************/
    $.rib = $.rib || {};
    $.rib.enableKeys = navUtils.enableKeys;
});
{'fraction_non_alphanumeric': 0.15023676280671544, 'fraction_numerical': 0.003730807863395035, 'mean_word_length': 1.4084312370421561, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '6572129', 'n_tokens_mistral': 1906, 'n_tokens_neox': 1813, 'n_words': 459}