===========
Backbone.js
===========
`Backbone.js `_ erlaubt strukturiertes Javascript mit
- Models
- Collections
- Views
Models
======
Erstellen eines Model
---------------------
::
ChatBox = Backbone.Modeol.extend({
initialize: function () {
this.set ({
'jid' : Strophe.getNodeFromJid(this.get('jid')),
'box_id' : this.get('id'),
'fullname' : this.get('fullname'),
});
}
});
Instantiieren eines Model
-------------------------
::
var box = new ChatBox({'id': hex_sha1(jid), 'jid': jid, 'fullname': name});
Views
=====
Die offensichtlichsten Views für ``collective.xmpp.chat`` sind definiert in `collective.xmpp.chat.browser.javascripts.converse.js `_:
- ``ControlBoxView``
- ``ChatRoomView``
- ``ChatBoxView``
Erstellen eines eigenen Views
-----------------------------
::
ChatBoxView = Backbone.View.extend({
tagName: 'div',
className: 'chatbox',
events: {'keypress textareea.chat-textarea': keyPressed'};
template: _.template(
' {{fullname}}
' +
'' +
''),
render: function() {
$(this.el).html(this.template(this.model.toJSON()));
return this;
},
keyPressed: function (ev) {
...
}
});