Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
 
11
dojo.require("dojo.event.common");
12
dojo.provide("dojo.event.topic");
13
dojo.event.topic = new function () {
14
	this.topics = {};
15
	this.getTopic = function (topic) {
16
		if (!this.topics[topic]) {
17
			this.topics[topic] = new this.TopicImpl(topic);
18
		}
19
		return this.topics[topic];
20
	};
21
	this.registerPublisher = function (topic, obj, funcName) {
22
		var topic = this.getTopic(topic);
23
		topic.registerPublisher(obj, funcName);
24
	};
25
	this.subscribe = function (topic, obj, funcName) {
26
		var topic = this.getTopic(topic);
27
		topic.subscribe(obj, funcName);
28
	};
29
	this.unsubscribe = function (topic, obj, funcName) {
30
		var topic = this.getTopic(topic);
31
		topic.unsubscribe(obj, funcName);
32
	};
33
	this.destroy = function (topic) {
34
		this.getTopic(topic).destroy();
35
		delete this.topics[topic];
36
	};
37
	this.publishApply = function (topic, args) {
38
		var topic = this.getTopic(topic);
39
		topic.sendMessage.apply(topic, args);
40
	};
41
	this.publish = function (topic, message) {
42
		var topic = this.getTopic(topic);
43
		var args = [];
44
		for (var x = 1; x < arguments.length; x++) {
45
			args.push(arguments[x]);
46
		}
47
		topic.sendMessage.apply(topic, args);
48
	};
49
};
50
dojo.event.topic.TopicImpl = function (topicName) {
51
	this.topicName = topicName;
52
	this.subscribe = function (listenerObject, listenerMethod) {
53
		var tf = listenerMethod || listenerObject;
54
		var to = (!listenerMethod) ? dj_global : listenerObject;
55
		return dojo.event.kwConnect({srcObj:this, srcFunc:"sendMessage", adviceObj:to, adviceFunc:tf});
56
	};
57
	this.unsubscribe = function (listenerObject, listenerMethod) {
58
		var tf = (!listenerMethod) ? listenerObject : listenerMethod;
59
		var to = (!listenerMethod) ? null : listenerObject;
60
		return dojo.event.kwDisconnect({srcObj:this, srcFunc:"sendMessage", adviceObj:to, adviceFunc:tf});
61
	};
62
	this._getJoinPoint = function () {
63
		return dojo.event.MethodJoinPoint.getForMethod(this, "sendMessage");
64
	};
65
	this.setSquelch = function (shouldSquelch) {
66
		this._getJoinPoint().squelch = shouldSquelch;
67
	};
68
	this.destroy = function () {
69
		this._getJoinPoint().disconnect();
70
	};
71
	this.registerPublisher = function (publisherObject, publisherMethod) {
72
		dojo.event.connect(publisherObject, publisherMethod, this, "sendMessage");
73
	};
74
	this.sendMessage = function (message) {
75
	};
76
};
77