4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-app-EventBus'>/**
19 </span> * @class Ext.app.EventBus
22 * Class documentation for the MVC classes will be present before 4.0 final, in the mean time please refer to the MVC
25 Ext.define('Ext.app.EventBus', {
30 observable: 'Ext.util.Observable'
33 constructor: function() {
34 this.mixins.observable.constructor.call(this);
39 Ext.override(Ext.Component, {
40 fireEvent: function(ev) {
41 if (Ext.util.Observable.prototype.fireEvent.apply(this, arguments) !== false) {
42 return me.dispatch.call(me, ev, this, arguments);
49 dispatch: function(ev, target, args) {
52 selector, controllers, id, events, event, i, ln;
55 // Loop over all the selectors that are bound to this event
56 for (selector in selectors) {
57 // Check if the target matches the selector
58 if (target.is(selector)) {
59 // Loop over all the controllers that are bound to this selector
60 controllers = selectors[selector];
61 for (id in controllers) {
62 // Loop over all the events that are bound to this selector on this controller
63 events = controllers[id];
64 for (i = 0, ln = events.length; i < ln; i++) {
67 if (event.fire.apply(event, Array.prototype.slice.call(args, 1)) === false) {
77 control: function(selectors, listeners, controller) {
81 if (Ext.isString(selectors)) {
84 selectors[selector] = listeners;
85 this.control(selectors, null, controller);
89 Ext.Object.each(selectors, function(selector, listeners) {
90 Ext.Object.each(listeners, function(ev, listener) {
93 event = Ext.create('Ext.util.Event', controller, ev);
95 // Normalize the listener
96 if (Ext.isObject(listener)) {
98 listener = options.fn;
99 scope = options.scope || controller;
101 delete options.scope;
104 event.addListener(listener, scope, options);
106 // Create the bus tree if it is not there yet
107 bus[ev] = bus[ev] || {};
108 bus[ev][selector] = bus[ev][selector] || {};
109 bus[ev][selector][controller.id] = bus[ev][selector][controller.id] || [];
111 // Push our listener in our bus
112 bus[ev][selector][controller.id].push(event);