mirror of https://github.com/apache/activemq.git
minor refactor
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@405484 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
cb97916c98
commit
075778e346
|
@ -1,12 +1,11 @@
|
||||||
|
|
||||||
var chatTopic = "topic://CHAT.DEMO";
|
|
||||||
var chatMembership = "topic://CHAT.DEMO";
|
|
||||||
|
|
||||||
|
|
||||||
var room =
|
var room =
|
||||||
{
|
{
|
||||||
_last: "",
|
_last: "",
|
||||||
_username: null,
|
_username: null,
|
||||||
|
_chatTopic: "topic://CHAT.DEMO",
|
||||||
|
|
||||||
join: function()
|
join: function()
|
||||||
{
|
{
|
||||||
|
@ -19,39 +18,35 @@ var room =
|
||||||
{
|
{
|
||||||
this._username=name;
|
this._username=name;
|
||||||
|
|
||||||
$('join').className='hidden';
|
amq.addListener('chat',this._chatTopic,room._chat);
|
||||||
Behaviour.apply();
|
|
||||||
amq.addListener('chat',chatTopic,room._chat);
|
|
||||||
$('join').className='hidden';
|
$('join').className='hidden';
|
||||||
$('joined').className='';
|
$('joined').className='';
|
||||||
$('phrase').focus();
|
$('phrase').focus();
|
||||||
Behaviour.apply();
|
Behaviour.apply();
|
||||||
amq.sendMessage(chatMembership, "<message type='join' from='" + room._username + "'/>");
|
amq.sendMessage(this._chatTopic, "<message type='join' from='" + room._username + "'/>");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
leave: function()
|
leave: function()
|
||||||
{
|
{
|
||||||
amq.removeListener('chat',chatTopic);
|
amq.removeListener('chat',this._chatTopic);
|
||||||
// switch the input form
|
// switch the input form
|
||||||
$('join').className='';
|
$('join').className='';
|
||||||
$('joined').className='hidden';
|
$('joined').className='hidden';
|
||||||
$('username').focus();
|
$('username').focus();
|
||||||
Behaviour.apply();
|
Behaviour.apply();
|
||||||
amq.sendMessage(chatMembership, "<message type='leave' from='" + room._username + "'/>");
|
amq.sendMessage(this._chatTopic, "<message type='leave' from='" + room._username + "'/>");
|
||||||
room._username=null;
|
room._username=null;
|
||||||
},
|
},
|
||||||
|
|
||||||
chat: function()
|
chat: function(text)
|
||||||
{
|
{
|
||||||
var text = $F('phrase');
|
|
||||||
$('phrase').value='';
|
|
||||||
if (text != null && text.length>0 )
|
if (text != null && text.length>0 )
|
||||||
{
|
{
|
||||||
// TODO more encoding?
|
// TODO more encoding?
|
||||||
text=text.replace('<','<');
|
text=text.replace('<','<');
|
||||||
text=text.replace('>','>');
|
text=text.replace('>','>');
|
||||||
amq.sendMessage(chatTopic, "<message type='chat' from='" + room._username + "'>" + text + "</message>");
|
amq.sendMessage(this._chatTopic, "<message type='chat' from='" + room._username + "'>" + text + "</message>");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -89,7 +84,7 @@ var room =
|
||||||
{
|
{
|
||||||
$('members').innerHTML="";
|
$('members').innerHTML="";
|
||||||
if (room._username!=null)
|
if (room._username!=null)
|
||||||
amq.sendMessage(chatMembership, "<message type='ping' from='" + room._username + "'/>");
|
amq.sendMessage(this._chatTopic, "<message type='ping' from='" + room._username + "'/>");
|
||||||
chat.innerHTML += "<span class=\"alert\"><span class=\"from\">"+from+" </span><span class=\"text\">has joined the room!</span></span><br/>";
|
chat.innerHTML += "<span class=\"alert\"><span class=\"from\">"+from+" </span><span class=\"text\">has joined the room!</span></span><br/>";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -98,7 +93,7 @@ var room =
|
||||||
{
|
{
|
||||||
$('members').innerHTML="";
|
$('members').innerHTML="";
|
||||||
if (room._username!=null)
|
if (room._username!=null)
|
||||||
amq.sendMessage(chatMembership, "<message type='ping' from='" + room._username + "'/>");
|
amq.sendMessage(this._chatTopic, "<message type='ping' from='" + room._username + "'/>");
|
||||||
chat.innerHTML += "<span class=\"alert\"><span class=\"from\">"+from+" </span><span class=\"text\">has left the room!</span></span><br/>";
|
chat.innerHTML += "<span class=\"alert\"><span class=\"from\">"+from+" </span><span class=\"text\">has left the room!</span></span><br/>";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -157,7 +152,9 @@ var chatBehaviours =
|
||||||
|
|
||||||
if (keyc==13 || keyc==10)
|
if (keyc==13 || keyc==10)
|
||||||
{
|
{
|
||||||
room.chat();
|
var text = $F('phrase');
|
||||||
|
$('phrase').value='';
|
||||||
|
room.chat(text);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -168,7 +165,9 @@ var chatBehaviours =
|
||||||
{
|
{
|
||||||
element.onclick = function(event)
|
element.onclick = function(event)
|
||||||
{
|
{
|
||||||
room.chat();
|
var text = $F('phrase');
|
||||||
|
$('phrase').value='';
|
||||||
|
room.chat(text);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue