all files / montage/ui/base/ abstract-text-area.js

89.29% Statements 25/28
83.33% Branches 10/12
83.33% Functions 10/12
89.29% Lines 25/28
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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119                          21×     20×                                                                                           12×                                                                    
/*global require, exports, document, Error*/
var Component = require("../component").Component,
    deprecate = require('../../core/deprecate');
 
var CLASS_PREFIX = "montage-TextArea";
 
/**
 * @class AbstractTextArea
 * @extends Component
 */
var AbstractTextArea = exports.AbstractTextArea = Component.specialize(
/** @lends AbstractTextArea# */
{
 
    constructor: {
        value: function AbstractTextArea() {
            if(this.constructor === AbstractTextArea) {
                throw new Error("AbstractTextArea cannot be instantiated.");
            }
 
            this.defineBindings({
                // classList management
                "classList.has('montage--disabled')": {
                    "<-": "!enabled"
                }
            });
        }
    },
 
    hasTemplate: {
        value: false
    },
 
    enabled: {
        value: true
    },
 
    _placeholder: {
        value: null
    },
 
    placeholderValue: {
        set: function (value) {
            deprecate.deprecationWarning("placeholderValue", "placeholder")
            this.placeholder = value;
        },
        get: function () {
            return this.placeholder;
        }
    },
 
    placeholder: {
        set: function (value) {
            this._placeholder = value;
            this.needsDraw = true;
        },
        get: function () {
            return this._placeholder;
        }
    },
 
    _value: {
        value: null
    },
 
    value: {
        set: function (value) {
            this._value = value;
            this.needsDraw = true;
        },
        get: function () {
            return this._value;
        }
    },
 
    enterDocument: {
        value: function (firstTime) {
            Eif (firstTime) {
                this.element.addEventListener("input", this, false);
                this.element.addEventListener("change", this, false);
            }
        }
    },
 
    draw: {
        value: function () {
            var value = this.value;
            this.element.value = value || false === value ? value.toString() : "";
            if (this._placeholder) {
                this.element.setAttribute("placeholder", this._placeholder);
            }
            this.element.disabled = !this.enabled;
        }
    },
 
    handleChange: {
        value: function () {
            this._updateValueFromDom();
        }
    },
 
    handleInput: {
        value: function (event) {
            this._updateValueFromDom();
        }
    },
 
    _updateValueFromDom: {
        value: function () {
            Eif (this._value !== this.element.value) {
                this._value = this.element.value;
                this.dispatchOwnPropertyChange("value", this._value);
            }
        }
    }
 
});