Sha256: 988e55cd3269afc9303337624cf982c5eb052b1316afa834244fec16fb593c6b

Contents?: true

Size: 1.62 KB

Versions: 3

Compression:

Stored size: 1.62 KB

Contents

/*
---
 
script: Select.js
 
description: Basic selectbox
 
license: Public domain (http://unlicense.org).

authors: Yaroslaff Fedin
 
requires:
- LSD/LSD.Widget
- LSD.Widget.Menu
- LSD.Widget.Button
- LSD/LSD.Mixin.List
- LSD/LSD.Mixin.Choice
- LSD/LSD.Mixin.Focusable

provides: [LSD.Widget.Select, LSD.Widget.Select.Button, LSD.Widget.Select.Option]
 
...
*/

LSD.Widget.Select = new Class({
  options: {
    tag: 'select',
    pseudos: Array.fast('list', 'choice', 'focusable', 'value', 'form-associated'),
    events: {
      self: {
        set: function(item) {
          this.write(item.getTitle());
          this.collapse();
        }
      }
    },
    layout: Array.fast('::button'),
    has: {
      many: {
        items: {
          source: 'select-option',
          mutation: '> option, > li',
          states: {
            hover: 'chosen'
          },
          pseudos: Array.fast('clickable', 'hoverable', 'command')
        }
      },
      one: {
        menu: {
          proxy: function(widget) {
            if (!widget.pseudos.item) return;
            if (!this.getSelectedItem() || widget.pseudos.selected) this.selectItem(widget)
            return true;
          }
        },
        button: {
          selector: 'button',
          source: 'select-button'
        }
      }
    }
  }
});

LSD.Widget.Select.Button = LSD.Widget.Button;

LSD.Widget.Select.Option = new Class({
  options: {
    tag: 'option',
    pseudos: Array.fast('item')
  },
  
  getTitle: function() {
    return this.element.get('text').trim();
  },
  
  getValue: function() {
    return this.attributes.value || this.element.get('text').trim();
  }
});

Version data entries

3 entries across 3 versions & 1 rubygems

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