Sha256: 68a333d8bf7c34270ec67af74e4c3fcb42a2b43afec6a100fceaa48bb5a949bf

Contents?: true

Size: 1.65 KB

Versions: 4

Compression:

Stored size: 1.65 KB

Contents

/*
---
 
script: States.js
 
description: Define class states and methods metaprogrammatically
 
license: Public domain (http://unlicense.org).

authors: Yaroslaff Fedin
 
requires: 
  - LSD.Module
  - LSD.Object
  - Ext/States
  
provides: 
  - LSD.Module.States

...
*/

LSD.Module.States = new Class({
  Implements: States,
  
  constructors: {
    states: function() {
      this.states = (new LSD.Object.Stack).addEvent('change', function(name, value, state, old, quiet) {
        var known = LSD.States[name];
        var method = value && state ? 'add' : 'remove';
        if (known && state && (old == null || value != null)) this.addState(name);
        if (!(old == null && value == null)) {
          if (LSD.Attributes[name] != 'boolean') {
            if (quiet != 'classes') this.classes[method](LSD.States[name] ? name : 'is-' + name, true);
          } else {
            if (quiet != 'attributes') this.attributes[method](name, true);
          }
          if (quiet != 'pseudos') this.pseudos[method](name, true);
        }
        if (known) {
          this.setStateTo(name, value && state, null, false);
          if (!state) this.removeState(name);
        }
      }.bind(this))
    }
  },

  onStateChange: function(state, value, args, callback) {
    var args = Array.prototype.slice.call(arguments, 0);
    args.slice(1, 2); //state + args
    if (callback !== false) this.states[value ? 'add' : 'remove'](state);
    this.fireEvent('stateChange', [state, args]);
    return true;
  }
});

LSD.Options.states = {
  add: function(name, value) {
    this.states.set(name);
  },
  remove: function(name, value) {
    this.states.unset(name);
  },
  iterate: true
};

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lsd_rails-0.1.6 Packages/lsd/Source/Module/Accessories/States.js
lsd_rails-0.1.5 Packages/lsd/Source/Module/Accessories/States.js
lsd_rails-0.1.4 Packages/lsd/Source/Module/Accessories/States.js
lsd_rails-0.1.3 Packages/lsd/Source/Module/Accessories/States.js