JSDoc: Source: abstract_navigatable.js

# Source: abstract_navigatable.js

    /*************************************************************
     *
     *  Copyright (c) 2015-2016 The MathJax Consortium
     *
     *  Licensed under the Apache License, Version 2.0 (the "License");
     *  you may not use this file except in compliance with the License.
     *  You may obtain a copy of the License at
     *
     *      http://www.apache.org/licenses/LICENSE-2.0
     *
     *  Unless required by applicable law or agreed to in writing, software
     *  distributed under the License is distributed on an "AS IS" BASIS,
     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     *  See the License for the specific language governing permissions and
     *  limitations under the License.
     */
    /**
     * @fileoverview Abstract class of navigatable menu elements.
     *
     * @author volker.sorge@gmail.com (Volker Sorge)
     */
    /// <reference path="key_navigatable.ts" />
    /// <reference path="mouse_navigatable.ts" />
    var ContextMenu;
    (function (ContextMenu) {
        class AbstractNavigatable {
            /**
             * @constructor
             * @implements {KeyNavigatable}
             * @implements {MouseNavigatable}
             */
            constructor() {
                this.bubble = false;
            }
            /**
             * Bubble this key event.
             */
            bubbleKey() {
                this.bubble = true;
            }
            /**
             * @override
             */
            keydown(event) {
                switch (event.keyCode) {
                    case ContextMenu.KEY.ESCAPE:
                        this.escape(event);
                        break;
                    case ContextMenu.KEY.RIGHT:
                        this.right(event);
                        break;
                    case ContextMenu.KEY.LEFT:
                        this.left(event);
                        break;
                    case ContextMenu.KEY.UP:
                        this.up(event);
                        break;
                    case ContextMenu.KEY.DOWN:
                        this.down(event);
                        break;
                    case ContextMenu.KEY.RETURN:
                    case ContextMenu.KEY.SPACE:
                        this.space(event);
                        break;
                    default:
                        return;
                }
                this.bubble ? this.bubble = false : this.stop(event);
            }
            ;
            /**
             * @override
             */
            escape(event) { }
            ;
            /**
             * @override
             */
            space(event) { }
            ;
            /**
             * @override
             */
            left(event) { }
            ;
            /**
             * @override
             */
            right(event) { }
            ;
            /**
             * @override
             */
            up(event) { }
            ;
            /**
             * @override
             */
            down(event) { }
            ;
            /**
             * Stops event propagation and bubbling.
             * @param {Event} event The keyboard event that fired.
             */
            stop(event) {
                if (event) {
                    event.stopPropagation();
                    event.preventDefault();
                    event.cancelBubble = true;
                }
            }
            ;
            /**
             * @override
             */
            mousedown(event) {
                return this.stop(event);
            }
            /**
             * @override
             */
            mouseup(event) {
                return this.stop(event);
            }
            /**
             * @override
             */
            mouseover(event) {
                return this.stop(event);
            }
            /**
             * @override
             */
            mouseout(event) {
                return this.stop(event);
            }
            /**
             * @override
             */
            click(event) {
                return this.stop(event);
            }
            /**
             * Adds navigation events to an HTML element.
             * @param {HTMLElement} element The HTML element for navigation.
             */
            addEvents(element) {
                element.addEventListener(ContextMenu.MOUSE.DOWN, this.mousedown.bind(this));
                element.addEventListener(ContextMenu.MOUSE.UP, this.mouseup.bind(this));
                element.addEventListener(ContextMenu.MOUSE.OVER, this.mouseover.bind(this));
                element.addEventListener(ContextMenu.MOUSE.OUT, this.mouseout.bind(this));
                element.addEventListener(ContextMenu.MOUSE.CLICK, this.click.bind(this));
                element.addEventListener('keydown', this.keydown.bind(this));
                element.addEventListener('dragstart', this.stop.bind(this));
                element.addEventListener('selectstart', this.stop.bind(this));
                element.addEventListener('contextmenu', this.stop.bind(this));
                element.addEventListener('dblclick', this.stop.bind(this));
            }
        }
        ContextMenu.AbstractNavigatable = AbstractNavigatable;
    })(ContextMenu || (ContextMenu = {}));