mirror of https://github.com/apache/activemq.git
working for IE
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@373771 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1c5b05ae56
commit
ad83b4da4f
|
@ -26,73 +26,73 @@ function elementText(element) {
|
|||
|
||||
var room =
|
||||
{
|
||||
last: "",
|
||||
username: "unknown",
|
||||
_last: "",
|
||||
_username: null,
|
||||
|
||||
join: function()
|
||||
{
|
||||
var name = $('username').value;
|
||||
if (name == null || name.length==0 )
|
||||
{
|
||||
alert("Please enter a username!");
|
||||
alert('Please enter a username!');
|
||||
}
|
||||
else
|
||||
{
|
||||
username=name;
|
||||
this._username=name;
|
||||
|
||||
$('join').className='hidden';
|
||||
Behaviour.apply();
|
||||
amq.addListener('chat',chatTopic,this._chat);
|
||||
amq.addListener('chat',chatTopic,room._chat);
|
||||
$('join').className='hidden';
|
||||
$('joined').className='';
|
||||
$('phrase').focus();
|
||||
Behaviour.apply();
|
||||
amq.sendMessage(chatMembership, "<message type='join' from='" + username + "'/>");
|
||||
amq.sendMessage(chatMembership, "<message type='join' from='" + room._username + "'/>");
|
||||
}
|
||||
},
|
||||
|
||||
leave: function()
|
||||
{
|
||||
amq.sendMessage(chatMembership, "<message type='leave' from='" + username + "'/>");
|
||||
amq.removeListener('chat',chatTopic);
|
||||
// switch the input form
|
||||
$('join').className='';
|
||||
$('joined').className='hidden';
|
||||
$('username').focus();
|
||||
username=null;
|
||||
room._username=null;
|
||||
Behaviour.apply();
|
||||
amq.sendMessage(chatMembership, "<message type='leave' from='" + room._username + "'/>");
|
||||
},
|
||||
|
||||
chat: function()
|
||||
{
|
||||
var text = $('phrase').value;
|
||||
var text = $F('phrase');
|
||||
$('phrase').value='';
|
||||
if (text != null && text.length>0 )
|
||||
{
|
||||
// TODO more encoding?
|
||||
text=text.replace('<','<');
|
||||
text=text.replace('>','>');
|
||||
amq.sendMessage(chatTopic, "<message type='chat' from='" + username + "'>" + text + "</message>");
|
||||
$('phrase').value="";
|
||||
amq.sendMessage(chatTopic, "<message type='chat' from='" + room._username + "'>" + text + "</message>");
|
||||
}
|
||||
},
|
||||
|
||||
_chat: function(message)
|
||||
{
|
||||
var chat=$('chat');
|
||||
var type=message.attributes['type'].value;
|
||||
var from=message.attributes['from'].value;
|
||||
var type=message.getAttribute('type');
|
||||
var from=message.getAttribute('from');
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case 'chat' :
|
||||
{
|
||||
var text=message.childNodes[0].data;
|
||||
var alert='false';
|
||||
|
||||
if ( from == this.last )
|
||||
if ( from == room._last )
|
||||
from="...";
|
||||
else
|
||||
{
|
||||
this.last=from;
|
||||
room._last=from;
|
||||
from+=":";
|
||||
}
|
||||
|
||||
|
@ -111,8 +111,8 @@ var room =
|
|||
case 'join' :
|
||||
{
|
||||
$('members').innerHTML="";
|
||||
if (username!=null)
|
||||
amq.sendMessage(chatMembership, "<message type='ping' from='" + username + "'/>");
|
||||
if (room._username!=null)
|
||||
amq.sendMessage(chatMembership, "<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/>";
|
||||
break;
|
||||
}
|
||||
|
@ -120,8 +120,8 @@ var room =
|
|||
case 'leave':
|
||||
{
|
||||
$('members').innerHTML="";
|
||||
if (username!=null)
|
||||
amq.sendMessage(chatMembership, "<message type='ping' from='" + username + "'/>");
|
||||
if (room._username!=null)
|
||||
amq.sendMessage(chatMembership, "<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/>";
|
||||
break;
|
||||
}
|
||||
|
@ -129,11 +129,9 @@ var room =
|
|||
|
||||
chat.scrollTop = chat.scrollHeight - chat.clientHeight;
|
||||
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
function chatPoll(first)
|
||||
_poll: function(first)
|
||||
{
|
||||
if (first || $('join').className=='hidden' && $('joined').className=='hidden')
|
||||
{
|
||||
|
@ -143,41 +141,52 @@ function chatPoll(first)
|
|||
Behaviour.apply();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function chatInit()
|
||||
{
|
||||
amq.addPollHandler(chatPoll);
|
||||
}
|
||||
amq.addPollHandler(room._poll);
|
||||
|
||||
|
||||
var behaviours =
|
||||
var chatBehaviours =
|
||||
{
|
||||
'#username' : function(element)
|
||||
{
|
||||
element.setAttribute("autocomplete","OFF");
|
||||
element.onkeypress = function(event)
|
||||
element.onkeyup = function(ev)
|
||||
{
|
||||
if (event && (event.keyCode==13 || event.keyCode==10))
|
||||
var keyc;
|
||||
if (window.event)
|
||||
keyc=window.event.keyCode;
|
||||
else
|
||||
keyc=ev.keyCode;
|
||||
if (keyc==13 || keyc==10)
|
||||
{
|
||||
room.join();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
||||
'#joinB' : function(element)
|
||||
{
|
||||
element.onclick = function()
|
||||
element.onclick = function(event)
|
||||
{
|
||||
room.join();
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
||||
'#phrase' : function(element)
|
||||
{
|
||||
element.setAttribute("autocomplete","OFF");
|
||||
element.onkeypress = function(event)
|
||||
element.onkeyup = function(ev)
|
||||
{
|
||||
if (event && (event.keyCode==13 || event.keyCode==10))
|
||||
var keyc;
|
||||
if (window.event)
|
||||
keyc=window.event.keyCode;
|
||||
else
|
||||
keyc=ev.keyCode;
|
||||
|
||||
if (keyc==13 || keyc==10)
|
||||
{
|
||||
room.chat();
|
||||
return false;
|
||||
|
@ -188,7 +197,7 @@ var behaviours =
|
|||
|
||||
'#sendB' : function(element)
|
||||
{
|
||||
element.onclick = function()
|
||||
element.onclick = function(event)
|
||||
{
|
||||
room.chat();
|
||||
}
|
||||
|
@ -200,12 +209,12 @@ var behaviours =
|
|||
element.onclick = function()
|
||||
{
|
||||
room.leave();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Behaviour.register(behaviours);
|
||||
Behaviour.addLoadEvent(chatInit);
|
||||
Behaviour.register(chatBehaviours);
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue