Source: widgets/pointerbutton.js

define('application/widgets/pointerbutton', [
    'rofl/widgets/button',
    'rofl/events/pointerselectevent',
    'rofl/lib/utils',
    'application/decorators/buttonpress'
], function (
    Button,
    PointerSelectEvent,
    Utils,
    ButtonPressDecorator
) {
    'use strict';

    var DIRECTIONS = {
            UP: 'up',
            DOWN: 'down',
            LEFT: 'left',
            RIGHT: 'right'
        },
        PointerButton;

    PointerButton = Button.extend({

        /**
         * Initialises the pointer widget.
         *
         * @param {string} direction - The direction.
         */
        init: function init (direction) {
            init.base.call(this, direction);

            this._direction = direction;
            this._build();
            this.decorate([ButtonPressDecorator]);
            this.setDisabled(true);
        },

        /**
         * Handles the on click event.
         *
         * @param {Object} e - Event object.
         * @private
         */
        _onClickEvent: function (e) {
            var coordinates = this._getEventCoordinates(e);

            this.bubbleEvent(new PointerSelectEvent(this,
                coordinates.x,
                coordinates.y));

            this._onButtonPress();
        },

        /**
         * Builds the pointer widget.
         *
         * @private
         */
        _build: function () {
            var direction = this._direction;

            this.addClass(['pointer-button', direction]);
        },

        /**
         * Returns the direction.
         *
         * @returns {string} - The direction.
         */
        getDirection: function () {
            return this._direction;
        },

        /**
         * Disables the widget.
         */
        disable: function () {
            if (!this.hasClass('disbaled')) {
                this.addClass('disabled');
            }
        },

        /**
         * Enables the widget.
         */
        enable: function () {
            if (this.hasClass('disabled')) {
                this.removeClass('disabled');
            }
        }
    });

    PointerButton.DIRECTIONS = DIRECTIONS;

    return PointerButton;
});