1318 |
alexandre_ |
1 |
/*
|
|
|
2 |
Copyright (c) 2004-2006, The Dojo Foundation
|
|
|
3 |
All Rights Reserved.
|
|
|
4 |
|
|
|
5 |
Licensed under the Academic Free License version 2.1 or above OR the
|
|
|
6 |
modified BSD license. For more information on Dojo licensing, see:
|
|
|
7 |
|
|
|
8 |
http://dojotoolkit.org/community/licensing.shtml
|
|
|
9 |
*/
|
|
|
10 |
|
1422 |
alexandre_ |
11 |
|
|
|
12 |
|
1318 |
alexandre_ |
13 |
dojo.require("dojo.event.common");
|
|
|
14 |
dojo.provide("dojo.event.topic");
|
|
|
15 |
dojo.event.topic = new function () {
|
|
|
16 |
this.topics = {};
|
|
|
17 |
this.getTopic = function (topic) {
|
|
|
18 |
if (!this.topics[topic]) {
|
|
|
19 |
this.topics[topic] = new this.TopicImpl(topic);
|
|
|
20 |
}
|
|
|
21 |
return this.topics[topic];
|
|
|
22 |
};
|
|
|
23 |
this.registerPublisher = function (topic, obj, funcName) {
|
|
|
24 |
var topic = this.getTopic(topic);
|
|
|
25 |
topic.registerPublisher(obj, funcName);
|
|
|
26 |
};
|
|
|
27 |
this.subscribe = function (topic, obj, funcName) {
|
|
|
28 |
var topic = this.getTopic(topic);
|
|
|
29 |
topic.subscribe(obj, funcName);
|
|
|
30 |
};
|
|
|
31 |
this.unsubscribe = function (topic, obj, funcName) {
|
|
|
32 |
var topic = this.getTopic(topic);
|
|
|
33 |
topic.unsubscribe(obj, funcName);
|
|
|
34 |
};
|
|
|
35 |
this.destroy = function (topic) {
|
|
|
36 |
this.getTopic(topic).destroy();
|
|
|
37 |
delete this.topics[topic];
|
|
|
38 |
};
|
|
|
39 |
this.publishApply = function (topic, args) {
|
|
|
40 |
var topic = this.getTopic(topic);
|
|
|
41 |
topic.sendMessage.apply(topic, args);
|
|
|
42 |
};
|
|
|
43 |
this.publish = function (topic, message) {
|
|
|
44 |
var topic = this.getTopic(topic);
|
|
|
45 |
var args = [];
|
|
|
46 |
for (var x = 1; x < arguments.length; x++) {
|
|
|
47 |
args.push(arguments[x]);
|
|
|
48 |
}
|
|
|
49 |
topic.sendMessage.apply(topic, args);
|
|
|
50 |
};
|
|
|
51 |
};
|
|
|
52 |
dojo.event.topic.TopicImpl = function (topicName) {
|
|
|
53 |
this.topicName = topicName;
|
|
|
54 |
this.subscribe = function (listenerObject, listenerMethod) {
|
|
|
55 |
var tf = listenerMethod || listenerObject;
|
|
|
56 |
var to = (!listenerMethod) ? dj_global : listenerObject;
|
|
|
57 |
return dojo.event.kwConnect({srcObj:this, srcFunc:"sendMessage", adviceObj:to, adviceFunc:tf});
|
|
|
58 |
};
|
|
|
59 |
this.unsubscribe = function (listenerObject, listenerMethod) {
|
|
|
60 |
var tf = (!listenerMethod) ? listenerObject : listenerMethod;
|
|
|
61 |
var to = (!listenerMethod) ? null : listenerObject;
|
|
|
62 |
return dojo.event.kwDisconnect({srcObj:this, srcFunc:"sendMessage", adviceObj:to, adviceFunc:tf});
|
|
|
63 |
};
|
|
|
64 |
this._getJoinPoint = function () {
|
|
|
65 |
return dojo.event.MethodJoinPoint.getForMethod(this, "sendMessage");
|
|
|
66 |
};
|
|
|
67 |
this.setSquelch = function (shouldSquelch) {
|
|
|
68 |
this._getJoinPoint().squelch = shouldSquelch;
|
|
|
69 |
};
|
|
|
70 |
this.destroy = function () {
|
|
|
71 |
this._getJoinPoint().disconnect();
|
|
|
72 |
};
|
|
|
73 |
this.registerPublisher = function (publisherObject, publisherMethod) {
|
|
|
74 |
dojo.event.connect(publisherObject, publisherMethod, this, "sendMessage");
|
|
|
75 |
};
|
|
|
76 |
this.sendMessage = function (message) {
|
|
|
77 |
};
|
|
|
78 |
};
|
|
|
79 |
|