Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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