Fork me on GitHub
Edit on GitHub

ajax event system

As you may have seen with the ajax div template and ajax a template, the framework and Dojo provide a nice way to subscribe and notify of topics from within the browser. A benefit of using Dojo as the basis of many of these components is being able to loosely couple UI components. There are two attributes of importance: listenTopics and notifyTopics.

As well as this, you can publish and subscribe to topic names with javascript code. To publish to the topic_name topic:

dojo.event.topic.publish("topic_name", "content");

The topic_name attribute is required, the content attribute is not and most elements are triggered without having this attribute. See the ajax div template for an example of this type of interaction.

To subscribe to the topic_name topic:

function doSomethingWithEvent(data) {
...
}

dojo.event.topic.getTopic("topic_name").subscribe(null, "doSomethingWithEvent");

The subscribe method takes 2 parameters, the first is the JavaScript object variable (or null if the function is not from an object) and the second is the name of the function to call when an event is received on the topic.