%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/shaban/laviva/wp-content/themes/levelup/assets/js/app/tools/
Upload File :
Create Path :
Current File : /var/www/html/shaban/laviva/wp-content/themes/levelup/assets/js/app/tools/keyboard.class.js

(function() {
    'use strict';

    APP.TOOLS.Keyboard = APP.CORE.Event_Emitter.extend({
        options: {
            keycode_names: {
                91: 'cmd',
                17: 'ctrl',
                32: 'space',
                16: 'shift',
                18: 'alt',
                20: 'caps',
                9: 'tab',
                // 13: 'enter',
                8: 'backspace',
                38: 'up',
                39: 'right',
                40: 'down',
                37: 'left',
                27: 'esc'
            }
        },

        static_instantiate: function () {
            if (APP.TOOLS.Keyboard.prototype.instance === null)
                return null;
            else
                return APP.TOOLS.Keyboard.prototype.instance;
        },

        init: function (options) {
            this._super(options);

            this.browser = new APP.TOOLS.Browser();
            this.downs = [];

            this.init_events();

            APP.TOOLS.Keyboard.prototype.instance = this;
        },

        init_events: function () {
            var that = this;

            window.onkeydown = function (e) {
                var character = that.keycode_to_character(e.keyCode);

                if (that.downs.indexOf(character) === -1)
                    that.downs.push(character);

                if (that.trigger('down', [e.keyCode, character]) === false) {
                    e.preventDefault();
                }
            };

            /*window.onkeyup = function (e) {
                var character = that.keycode_to_character(e.keyCode);

                if (that.downs.indexOf(character) !== -1)
                    that.downs.splice(that.downs.indexOf(character), 1);

                that.trigger('up', [e.keyCode, character]);
            };*/
        },

        keycode_to_character: function (keycode) {
            var character = this.options.keycode_names[keycode];

            if (!character)
                character = String.fromCharCode(keycode).toLowerCase();

            return character;
        },

        are_down: function (keys) {
            var down = true;

            for (var i = 0; i < keys.length; i++) {
                var key = keys[i];

                if (typeof key === 'number')
                    key = this.keycode_to_character(key);

                if (this.downs.indexOf(key) === -1)
                    down = false;
            }

            return down;
        },

        is_down: function (key) {
            return this.are_down([key]);
        }
    });
})();

Zerion Mini Shell 1.0