Sha256: 180a4f9e94f9176a0b6262b9a60edf23f9def03b4509e462dc29a958550d3af3
Contents?: true
Size: 1.75 KB
Versions: 7
Compression:
Stored size: 1.75 KB
Contents
/* --- script: Behavior.js description: Defines global selectors that mix the mixins in license: Public domain (http://unlicense.org). authors: Yaroslaff Fedin requires: - LSD - Slick/Slick.Parser provides: - LSD.Behavior ... */ LSD.Behavior = function() { this.attached = []; this.expectations = {}; this.parsed = {}; } LSD.Behavior.prototype = { define: function(selector, behavior) { selector.split(/\s*,\s*/).each(function(bit) { var group = this.expectations[bit]; if (!group) group = this.expectations[bit] = []; group.push(behavior); this.attached.each(function(object) { this.expect(object, bit, behavior) }, this); }, this); }, expect: function(object, selector, behavior) { var proto = object.prototype, type = typeOf(behavior); var watcher = function(widget, state) { if (type == 'object') widget[state ? 'setOptions' : 'unsetOptions'](behavior); else widget[state ? 'mixin' : 'unmix'](behavior, true); } if (proto.expect) { //var parsed// = this.parsed[selector]; //if (!parsed) { var parsed = this.parsed[selector] = Object.clone(Slick.parse(selector).expressions[0][0]); delete parsed.combinator; //} proto.expect(parsed, watcher); } else { //var options = proto.options, expectations = options.expectations; //if (!expectations) expectations = options.expecations = {}; //expectations[selector] = watcher; } }, attach: function(object) { this.attached.push(object); for (var expectation in this.expectations) for (var exps = this.expectations[expectation], i = 0, exp; exp = exps[i++];) this.expect(object, expectation, exp); } }; LSD.Behavior = new LSD.Behavior;
Version data entries
7 entries across 7 versions & 1 rubygems