all files / montage/ui/base/ abstract-control.js

76.92% Statements 10/13
25% Branches 1/4
60% Functions 3/5
76.92% Lines 10/13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92                                                            39×                                                                       39×     39× 39× 39×                              
/*global require, exports, document, Error*/
 
/**
 * @module montage/ui/base/abstract-control
 * @requires montage/ui/component
 * @requires collections/map
 */
var Component = require("../component").Component,
    Map = require("collections/map");
 
/**
 * @class AbstractControl
 * @classdesc A basis for common behavior of control components.
 * @extends Component
 */
exports.AbstractControl = Component.specialize( /** @lends AbstractControl.prototype # */ {
 
    /**
     * Dispatched when the button is activated through a mouse click, finger
     * tap, or when focused and the spacebar is pressed.
     *
     * @event AbstractControl#action
     * @type {Event}
     * @property {Map} detail - pass custom data in this property
     */
 
    /**
     * @function
     * @fires AbstractControl#action
     */
    dispatchActionEvent: {
        value: function () {
            return this.dispatchEvent(this.createActionEvent());
        }
    },
 
    /**
     * @private
     * @property {Map} value
     * @default null
     */
    _detail: {
        value: null
    },
 
    /**
     * The data property of the action event.
     *
     * Example to toggle the complete class: `"detail.get('selectedItem')" : {
     * "<-" : "@repetition:iteration.object"}`
     *
     * @returns {Map}
     */
    detail: {
        get: function () {
            Eif (this._detail == null) {
                this._detail = new Map();
            }
            return this._detail;
        }
    },
 
    /**
     * Overrides {@link Component#createActionEvent}
     * by adding {@link AbstractControl#detail} custom data
     *
     * @function
     * @returns {AbstractControl#action}
     */
    createActionEvent: {
        value: function () {
            var actionEvent = document.createEvent("CustomEvent"),
                eventDetail;
 
            eventDetail = this._detail;
            actionEvent.initCustomEvent("action", true, true, eventDetail);
            return actionEvent;
        }
    },
 
    disabled: {
        get: function () {
            return !this.enabled;
        },
        set: function (value) {
            if (typeof value === "boolean") {
                this.enabled = !value;
            }
        }
    }
});