Sha256: cd9e13c61e6776e5cbd92d9c54644d97af28b008b5874f63523542d7aeaa8ee7

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

/*
---
 
script: Label.js
 
description: A label for a form field
 
license: Public domain (http://unlicense.org).

authors: Yaroslaff Fedin
 
requires:
  - LSD/LSD.Widget

provides: 
  - LSD.Widget.Label
 
...
*/

LSD.Widget.Label = new Class({
  options: {
    tag: 'label',
    has: {
      one: {
        control: {
          expectation: function() {
            return {combinator: ' ', tag: '*', pseudos: [{key: 'form-associated'}]}
          },
          collection: 'labels',
          states: {
            get: {
              invalid: 'invalid'
            }
          }
        }
      }
    },
    expects: {
      '[for]': function(widget, state) {
        widget[state ? 'addRelation' : 'removeRelation']('control', {
          expectation: function() {
            var id = this.attributes['for'];
            if (id) return {id: id, combinator: ' ', tag: '*'};
          },
          target: 'root'
        });
      }
    },
    pseudos: Array.fast('form-associated', 'clickable', 'command', 'value'),
    states: Array.fast('invalid'),
    chain: {
      focusControl: function() {
        if (this.control) return {
          target: this.control,
          action: this.control.pseudos.clickable ? 'submit' : 'focus'
        };
      }
    },
    events: {
      self: {
        click: 'focusControl'
      }
    }
  }
});

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lsd_rails-0.1.2 Packages/lsd-widgets/Source/Label.js
lsd_rails-0.1.1 Packages/lsd-widgets/Source/Label.js
lsd_rails-0.1 Packages/lsd-widgets/Source/Label.js