Backbone.js erlaubt strukturiertes Javascript mit
Models
Collections
Views
ChatBox = Backbone.Modeol.extend({
initialize: function () {
this.set ({
'jid' : Strophe.getNodeFromJid(this.get('jid')),
'box_id' : this.get('id'),
'fullname' : this.get('fullname'),
});
}
});
var box = new ChatBox({'id': hex_sha1(jid), 'jid': jid, 'fullname': name});
Die offensichtlichsten Views für collective.xmpp.chat
sind definiert in collective.xmpp.chat.browser.javascripts.converse.js:
ControlBoxView
ChatRoomView
ChatBoxView
ChatBoxView = Backbone.View.extend({
tagName: 'div',
className: 'chatbox',
events: {'keypress textareea.chat-textarea': keyPressed'};
template: _.template(
'<div class="chat-title"> {{fullname}} </div>' +
'<div class="chat-content"></div>' +
'<form class="sendXMPPMessage" method="post">' +
'<textarea type="text" class="chat-area" />' +
'</form>'),
render: function() {
$(this.el).html(this.template(this.model.toJSON()));
return this;
},
keyPressed: function (ev) {
...
}
});