amiadogroup/candy — pull request #51 by patforg (2011-10-26 04:07:50+00:00)
Title: Jquery events

Here is my proposed jquery event system.

At this point this is only the proposed implementation, basic testing has been done. Of course comments and feedback are welcome.

What's left to regarding events are the events in the Observer classes.

Also would like to suggest replacing message objects of type string with an instance of Candy.Core.Message class which I created. I've created this class to register events to it (it will be clearer once you check the examples bellow). On top of allowing a place for me to register events it would allow messages to have extra properties, like message type and eventually methods. Let me know what you think.

As for the events I did not use the Event objects to bind to, instead I used the actual objects in Candy.Core. Note that the events listed bellow are not properties of the Core Objects but juste event names to bind to. I have yet to list them in the documentation, since I wanted to get your feedback before doing so.

Here is the list of events that have been ported:

Candy.Core
- connect (new event)
- disconnect
- authfail

Candy.Core.Message
- adminmessage
- beforesend
- beforeshow
- show

Candy.Core.ChatRoom
- show
- hide
- add
- close
- subjectchange
- presencechange

Candy.Core.ChatRoster
- update

Candy.Core.Message
- beforesend
- beforeshow
- aftercontextmenu
- contextmenu

Here is an example registration of an event:
$(Candy.Core.ChatRoom).bind('add', function(e, data) {
console.log('Joined a room: '+ data.roomJid);
});

Here is an example of an event being triggerd where it happened:
var evtData = {
/* ...*/
};
$(Candy.Core.ChatRoster).triggerHandler('contextmenu', [evtData]);