Source: widgets/player/buttons/record.js

define('application/widgets/player/buttons/record', [
    'application/widgets/pointerfocusablebutton',
    'rofl/widgets/label',
    'rofl/lib/l10n'
], function (
    Button,
    Label,
    L10n
) {
    'use strict';

    var RECORD_CLASS = 'icon-record-new',
        RECORDING_CLASS = 'icon-recording',
        STATES = {
            RECORD: 'record',
            RECORDING: 'recording'
        },
        l10n = L10n.getInstance(),
        RecordButton;

    RecordButton = Button.extend({

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

            this._state = STATES.RECORD;
            this.addClass(['control', 'record']);
            this._build();
        },

        /**
         * Builds the widget.
         *
         * @private
         */
        _build: function () {
            var icon = this._icon = new Label({ text: '', classNames: ['v-align-target', 'icon', RECORD_CLASS] }),
                helper = new Label({ text: '', classNames: ['v-align-helper'] }),
                recordingText = new Label({ text: l10n.get('player.buttons.record'), classNames: ['recording-text', 'v-align-helper'] });

            this.appendChildWidget(helper);
            this.appendChildWidget(icon);
            this.appendChildWidget(recordingText);
        },

        /**
         * Sets the state.
         *
         * @param {string} state - The state.
         */
        setState: function (state) {
            var oldClass = this._state === STATES.RECORDING ? RECORDING_CLASS : RECORD_CLASS,
                newClass = state === STATES.RECORDING ? RECORDING_CLASS : RECORD_CLASS,
                icon = this._icon;

            if (oldClass === newClass) {
                return;
            }

            this._state = state;
            icon.removeClass(oldClass);
            icon.addClass(newClass);
        }
    });

    RecordButton.STATES = STATES;

    return RecordButton;
});