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:
Gregory John Wilkins 2006-01-31 09:12:44 +00:00
parent 1c5b05ae56
commit ad83b4da4f
1 changed files with 57 additions and 48 deletions

View File

@ -26,73 +26,73 @@ function elementText(element) {
var room = var room =
{ {
last: "", _last: "",
username: "unknown", _username: null,
join: function() join: function()
{ {
var name = $('username').value; var name = $('username').value;
if (name == null || name.length==0 ) if (name == null || name.length==0 )
{ {
alert("Please enter a username!"); alert('Please enter a username!');
} }
else else
{ {
username=name; this._username=name;
$('join').className='hidden'; $('join').className='hidden';
Behaviour.apply(); Behaviour.apply();
amq.addListener('chat',chatTopic,this._chat); 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='" + username + "'/>"); amq.sendMessage(chatMembership, "<message type='join' from='" + room._username + "'/>");
} }
}, },
leave: function() leave: function()
{ {
amq.sendMessage(chatMembership, "<message type='leave' from='" + username + "'/>"); amq.removeListener('chat',chatTopic);
// switch the input form // switch the input form
$('join').className=''; $('join').className='';
$('joined').className='hidden'; $('joined').className='hidden';
$('username').focus(); $('username').focus();
username=null; room._username=null;
Behaviour.apply(); Behaviour.apply();
amq.sendMessage(chatMembership, "<message type='leave' from='" + room._username + "'/>");
}, },
chat: function() chat: function()
{ {
var text = $('phrase').value; 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('<','&lt;'); text=text.replace('<','&lt;');
text=text.replace('>','&gt;'); text=text.replace('>','&gt;');
amq.sendMessage(chatTopic, "<message type='chat' from='" + username + "'>" + text + "</message>"); amq.sendMessage(chatTopic, "<message type='chat' from='" + room._username + "'>" + text + "</message>");
$('phrase').value="";
} }
}, },
_chat: function(message) _chat: function(message)
{ {
var chat=$('chat'); var chat=$('chat');
var type=message.attributes['type'].value; var type=message.getAttribute('type');
var from=message.attributes['from'].value; var from=message.getAttribute('from');
switch(type) switch(type)
{ {
case 'chat' : case 'chat' :
{ {
var text=message.childNodes[0].data; var text=message.childNodes[0].data;
var alert='false';
if ( from == this.last ) if ( from == room._last )
from="..."; from="...";
else else
{ {
this.last=from; room._last=from;
from+=":"; from+=":";
} }
@ -111,8 +111,8 @@ var room =
case 'join' : case 'join' :
{ {
$('members').innerHTML=""; $('members').innerHTML="";
if (username!=null) if (room._username!=null)
amq.sendMessage(chatMembership, "<message type='ping' from='" + username + "'/>"); amq.sendMessage(chatMembership, "<message type='ping' from='" + room._username + "'/>");
chat.innerHTML += "<span class=\"alert\"><span class=\"from\">"+from+"&nbsp;</span><span class=\"text\">has joined the room!</span></span><br/>"; chat.innerHTML += "<span class=\"alert\"><span class=\"from\">"+from+"&nbsp;</span><span class=\"text\">has joined the room!</span></span><br/>";
break; break;
} }
@ -120,8 +120,8 @@ var room =
case 'leave': case 'leave':
{ {
$('members').innerHTML=""; $('members').innerHTML="";
if (username!=null) if (room._username!=null)
amq.sendMessage(chatMembership, "<message type='ping' from='" + username + "'/>"); amq.sendMessage(chatMembership, "<message type='ping' from='" + room._username + "'/>");
chat.innerHTML += "<span class=\"alert\"><span class=\"from\">"+from+"&nbsp;</span><span class=\"text\">has left the room!</span></span><br/>"; chat.innerHTML += "<span class=\"alert\"><span class=\"from\">"+from+"&nbsp;</span><span class=\"text\">has left the room!</span></span><br/>";
break; break;
} }
@ -129,12 +129,10 @@ var room =
chat.scrollTop = chat.scrollHeight - chat.clientHeight; chat.scrollTop = chat.scrollHeight - chat.clientHeight;
} },
};
_poll: function(first)
function chatPoll(first) {
{
if (first || $('join').className=='hidden' && $('joined').className=='hidden') if (first || $('join').className=='hidden' && $('joined').className=='hidden')
{ {
$('join').className=''; $('join').className='';
@ -142,42 +140,53 @@ function chatPoll(first)
$('username').focus(); $('username').focus();
Behaviour.apply(); Behaviour.apply();
} }
} }
};
function chatInit() amq.addPollHandler(room._poll);
{
amq.addPollHandler(chatPoll);
}
var chatBehaviours =
var behaviours =
{ {
'#username' : function(element) '#username' : function(element)
{ {
element.setAttribute("autocomplete","OFF"); 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(); room.join();
return false;
} }
return true;
} }
}, },
'#joinB' : function(element) '#joinB' : function(element)
{ {
element.onclick = function() element.onclick = function(event)
{ {
room.join(); room.join();
return true;
} }
}, },
'#phrase' : function(element) '#phrase' : function(element)
{ {
element.setAttribute("autocomplete","OFF"); 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(); room.chat();
return false; return false;
@ -188,7 +197,7 @@ var behaviours =
'#sendB' : function(element) '#sendB' : function(element)
{ {
element.onclick = function() element.onclick = function(event)
{ {
room.chat(); room.chat();
} }
@ -200,12 +209,12 @@ var behaviours =
element.onclick = function() element.onclick = function()
{ {
room.leave(); room.leave();
return false;
} }
} }
}; };
Behaviour.register(behaviours); Behaviour.register(chatBehaviours);
Behaviour.addLoadEvent(chatInit);