Sha256: 07c492dceb090f2f4e0070e4a2d7a7e913aa115537e5ecc2a6c6c70c3a0bff1e

Contents?: true

Size: 1.3 KB

Versions: 4

Compression:

Stored size: 1.3 KB

Contents

/*
---
 
script: Choice.js
 
description: Mixin that adds List. Allows one item to be chosen and one selected (think navigating to a menu item to select)
 
license: Public domain (http://unlicense.org).
 
requires:
  - LSD.Mixin.List
 
provides: 
  - LSD.Mixin.Choice
 
...
*/


LSD.Mixin.Choice = new Class({
  options: {
    has: {
      many: {
        items: {
          states: {
            add: Array.object('chosen')
          }
        }
      }
    }
  },
  
  chooseItem: function(item, temp) {
    if (!(item = this.getItem(item)) && this.options.list.force) return false;
    var chosen = this.chosenItem;
    this.setSelectedItem(item, 'chosen');
    this.fireEvent('choose', [item, this.getItemIndex()]);
    if (item.choose() && chosen) chosen.forget();
    return item;
  },
  
  forgetChosenItem: function(item) {
    item = this.getItem(item) || this.chosenItem;
    if (item) item.forget();
    this.unsetSelectedItem(item, 'chosen');
  },
  
  selectChosenItem: function() {
    return this.selectItem(this.chosenItem)
  },

  getChosenItems: function() {
    return this.chosenItem || (this.chosenItems ? this.chosenItems.getLast() : null);
  },
  
  getChosenItems: function(type) {
    return this.chosenItems || (this.chosenItem && [this.chosenItem]);
  }
});


LSD.Behavior.define(':choice', 'choice');

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lsd_rails-0.1.6 Packages/lsd/Source/Mixin/Choice.js
lsd_rails-0.1.5 Packages/lsd/Source/Mixin/Choice.js
lsd_rails-0.1.4 Packages/lsd/Source/Mixin/Choice.js
lsd_rails-0.1.3 Packages/lsd/Source/Mixin/Choice.js