Sha256: bc551934ea4dbe71d5c06c61456bac608434044f8af6cec1939efad0b1a0604f

Contents?: true

Size: 1.71 KB

Versions: 7

Compression:

Stored size: 1.71 KB

Contents

/*
---
 
script: Actions.js
 
description: Assign functions asyncronously to any widget
 
license: Public domain (http://unlicense.org).

authors: Yaroslaff Fedin

requires:
  - LSD.Module
  - LSD.Action

provides: 
  - LSD.Module.Actions
 
...
*/

LSD.Module.Actions = new Class({
  options: {
    actions: {}
  },
  
  constructors: {
    actions: function() {
      this.actions = {}
    }
  },
  
  addAction: function() {
    this.getAction.apply(this, arguments).attach(this);
  },
  
  removeAction: function() {
    this.getAction.apply(this, arguments).detach(this);
  },
  
  getAction: function(name, action) {
    return this.actions[name] || (this.actions[name] = new (LSD.Action[LSD.capitalize(name)] || LSD.Action)(action, name))
  },
  
  getActionState: function(action, args, state, revert) {
    if (state == null) {
      if (action.options.getState) state = action.options.getState.apply(action, args);
      else state = true; //enable things by default
    }
    return !!((state && state.call ? state.apply(this, args) : state) ^ revert);
  }
});

LSD.Module.Actions.attach = function(doc) {
  LSD.Mixin.each(function(mixin, name) {
    var selector = mixin.prototype.behaviour;
    if (!selector) return;
    var attached = {};
    var watcher = function (widget, state) {
      if (state) {
        if (attached[widget.lsd]) return;
        else attached[widget.lsd] = true;
        widget.mixin(mixin, true);
      } else if (attached[widget.lsd]) {
        delete attached[widget.lsd];
        widget.unmix(mixin, true);
      }
    };
    selector.split(/\s*,\s*/).each(function(bit) {
      doc.watch(bit, watcher)
    })
  });
};

LSD.Options.actions = {
  add: 'addAction',
  remove: 'removeAction',
  iterate: true
};

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
lsd_rails-0.1.6 Packages/lsd/Source/Module/Accessories/Actions.js
lsd_rails-0.1.5 Packages/lsd/Source/Module/Accessories/Actions.js
lsd_rails-0.1.4 Packages/lsd/Source/Module/Accessories/Actions.js
lsd_rails-0.1.3 Packages/lsd/Source/Module/Accessories/Actions.js
lsd_rails-0.1.2 Packages/lsd/Source/Module/Accessories/Actions.js
lsd_rails-0.1.1 Packages/lsd/Source/Module/Accessories/Actions.js
lsd_rails-0.1 Packages/lsd/Source/Module/Accessories/Actions.js