MooTools Controllers class Revision ad2c90ade9e4 (Tue Dec 16 2008 at 16:59) - Diff Link to this snippet: https://friendpaste.com/2d93AykCSlJ05AVYE37SJ4 Embed: manni perldoc borland colorful default murphy trac fruity autumn bw emacs pastie friendly Show line numbers Wrap lines 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970/*Class: ControllersThis is a namespace for all the classes that control interactive behavior on thepage. It also manages event messaging so that controllers can communicate witheach other.*/var Controllers = new Class({ Implements: Events, initialize: function(cssPrefix) { this.cssPrefix = cssPrefix; this.controllers = []; this.countdown = 2; window.addEvent('domready', this.onReady.bind(this)); this.addEvent('onReady', this.onReady.bind(this)); }, onReady: function() { // In order to initialize controllers safely, wait to make sure that both // the DOM is ready and that the 'onReady' custom event has been fired. // Firing 'onReady' indicates that all controllers have been added. this.countdown--; if (this.countdown == 0) { this.initializeControllers(); } }, initializeControllers: function() { // After the page loads, search for elements with particular CSS classes // that correspond to JavaScript behavior controllers. for (property in this) { if ($type(this[property]) != 'class') { continue; } $$('.' + this.cssPrefix + property).each(function(el) { try { var controller = this[property]; this.controllers.push(new controller(el, this)); } catch(e) { dbug.log(e.message); } }.bind(this)); } // Notify any listeners that all controllers are done initializing. Also, // set a top-level CSS class to allow for progressive enhancement. this.fireEvent('onInitialize'); $(document.body).addClass(this.cssPrefix + 'enabled'); } });dbug.enable();var MoMA = new Controllers('JS_');MoMA.Calendar = new Class({ /* ... */ });MoMA.Promotions = new Class({ /* ... */ });// Plus a bunch moreMoMA.fireEvent('onReady');