Sha256: c9e9937088f6180e7612053a467cd8187397a3cdaa8a6478ce71804fac1a52b4

Contents?: true

Size: 1.77 KB

Versions: 3

Compression:

Stored size: 1.77 KB

Contents

/**
 * Checkbox
 *
 * @author voloko
 * @name uki.view.Checkbox
 * @class
 * @extends uki.view.Button
 */
uki.view.declare('uki.view.Checkbox', uki.view.Button, function(Base) {
    
    this._backgroundPrefix = 'checkbox-';
    
    /**
     * @function
     * @name uki.view.Button#"checked-normal-background"
     */
    /**
     * @function
     * @name uki.view.Button#"checked-hover-background"
     */
    /**
     * @function
     * @name uki.view.Button#"checked-disabled-background"
     */
    uki.each(['checked-normal', 'checked-hover', 'checked-disabled'], function(i, name) {
        var property = name + '-background';
        this[property] = function(bg) {
            if (bg) this['_' + property] = bg;
            return this['_' + property] = this['_' + property] || 
                uki.theme.background(this._backgroundPrefix + name, {height: this.rect().height, view: this});
        };
    }, this);
    
    this._setup = function() {
        Base._setup.call(this);
        this._focusable = false;
    };
    
    this._updateBg = function() {
        var name = this._disabled ? 'disabled' : this._over ? 'hover' : 'normal';
        if (this._checked) name = 'checked-' + name;
        this._backgroundByName(name);
    };
    
    /**
     * @function
     * @name uki.view.Button#value
     */
     /**
      * @function
      * @name uki.view.Button#checked
      */
    this.value = this.checked = uki.newProp('_checked', function(state) {
        this._checked = !!state;
        this._updateBg();
    });
    
    this._mouseup = function(e) {
        if (!this._down) return;
        this._down = false;
        if (!this._disabled) {
            this.checked(!this.checked())
            this.trigger('change', {checked: this._checked, source: this});
        }
    };
    
});

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
uki-1.1.4 frameworks/uki/src/uki-view/view/checkbox.js
uki-1.1.3 frameworks/uki/src/uki-view/view/checkbox.js
uki-1.1.2 frameworks/uki/src/uki-view/view/checkbox.js