| 1 |
dojo.provide("dojox.xmpp.widget.ChatSession"); |
| 2 |
|
| 3 |
dojo.require("dijit.layout.LayoutContainer"); |
| 4 |
dojo.require("dijit._Templated"); |
| 5 |
|
| 6 |
dojo.declare("dojox.xmpp.widget.ChatSession", |
| 7 |
[dijit.layout.LayoutContainer, dijit._Templated], |
| 8 |
{ |
| 9 |
templateString: dojo.cache("dojox.xmpp.widget", "templates/ChatSession.html"), |
| 10 |
enableSubWidgets: true, |
| 11 |
widgetsInTemplate: true, |
| 12 |
|
| 13 |
widgetType: "ChatSession", |
| 14 |
chatWith: null, |
| 15 |
instance: null, |
| 16 |
postCreate: function(){ |
| 17 |
|
| 18 |
}, |
| 19 |
|
| 20 |
displayMessage: function(message, type) { |
| 21 |
|
| 22 |
if(message) { |
| 23 |
var name = message.from ? this.chatWith : "me"; |
| 24 |
this.messages.domNode.innerHTML += "<b>" + name + ":</b> " + message.body + "<br/>"; |
| 25 |
this.goToLastMessage(); |
| 26 |
} |
| 27 |
|
| 28 |
}, |
| 29 |
|
| 30 |
goToLastMessage: function() { |
| 31 |
this.messages.domNode.scrollTop = this.messages.domNode.scrollHeight; |
| 32 |
}, |
| 33 |
|
| 34 |
onKeyPress: function(e){ |
| 35 |
var key = e.keyCode || e.charCode; |
| 36 |
if ((key == dojo.keys.ENTER) && (this.chatInput.value != "")){ |
| 37 |
this.instance.sendMessage({body: this.chatInput.value}); |
| 38 |
this.displayMessage( {body: this.chatInput.value}, "out"); |
| 39 |
this.chatInput.value = ""; |
| 40 |
} |
| 41 |
} |
| 42 |
}); |