Sha256: e0f3d552cbd0f2acb787a9e00f5406afceaa3d9212d727d447abf0a6df880294

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

/*
---

script: Group.js

name: Group

description: Class for monitoring collections of events

license: MIT-style license

authors:
  - Valerio Proietti

requires:
  - Core/Events
  - /MooTools.More

provides: [Group]

...
*/

(function(){

this.Group = new Class({

	initialize: function(){
		this.instances = Array.flatten(arguments);
		this.events = {};
		this.checker = {};
	},

	addEvent: function(type, fn){
		this.checker[type] = this.checker[type] || {};
		this.events[type] = this.events[type] || [];
		if (this.events[type].contains(fn)) return false;
		else this.events[type].push(fn);
		this.instances.each(function(instance, i){
			instance.addEvent(type, this.check.pass([type, instance, i], this));
		}, this);
		return this;
	},

	check: function(type, instance, i){
		this.checker[type][i] = true;
		var every = this.instances.every(function(current, j){
			return this.checker[type][j] || false;
		}, this);
		if (!every) return;
		this.checker[type] = {};
		this.events[type].each(function(event){
			event.call(this, this.instances, instance);
		}, this);
	}

});

})();

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lsd_rails-0.1.4 Packages/mootools-more/Source/Utilities/Group.js
lsd_rails-0.1.3 Packages/mootools-more/Source/Utilities/Group.js
lsd_rails-0.1.2 Packages/mootools-more/Source/Utilities/Group.js
lsd_rails-0.1.1 Packages/mootools-more/Source/Utilities/Group.js
lsd_rails-0.1 Packages/mootools-more/Source/Utilities/Group.js