|
// Messages class
/**
* Chat messages processing and formatting class.
*/
function Messages() {
this.addMessage = Messages_addMessage;
this.formatMessage = Messages_formatMessage;
this.getMessages = Messages_getMessages;
this.formatAll = Messages_formatAll;
this.replaceNewLine = Messages_replaceNewLine;
this.formatSysMessage = Messages_formatSysMessage;
this.addSysMessage = Messages_addSysMessage;
}
/**
* Formats all messages in reversing order as HTML.
* @return HTML with messages.
*/
function Messages_formatAll() {
var strMessages = "";
var objMessages = this.getMessages();
var items = objMessages.getItems();
var i = items.length-1;
for(;i >= 0; i--) {
var x = items.item(i);
strMessages += x.text;
strMessages += "<BR>\n"
}
return strMessages;
}
/**
* Adds new message and performs message formatting.
* @param clientIP IP address of message sender.
* @param strNick nick name of sender.
* @param strMessage textual message contents.
* @param moodType mood type for current message.
*/
function Messages_addMessage(clientIP, strNick, strMessage, moodType) {
var filter = new IncorrectInputFilter;
strMessage = filter.processText(strMessage);
strNick = Server.HTMLEncode(strNick);
strMessage = Server.HTMLEncode(strMessage);
strMessage = this.replaceNewLine(strMessage);
var strFormatted = this.formatMessage(clientIP, strNick, strMessage, moodType);
this.getMessages().add(strFormatted);
}
/**
* Addition of a new system message for the chat.
*/
function Messages_addSysMessage(strMessage) {
strMessage = Server.HTMLEncode(strMessage);
var strFormatted = this.formatSysMessage(strMessage);
this.getMessages().add(strFormatted);
}
/**
* Performs single system message formatting.
* @param strMessage textual message contents.
* @return Formatted message HTML.
*/
function Messages_formatSysMessage(strMessage) {
var strFormatted = "<font color=\"red\">System: " + strMessage + "</font>";
return strFormatted;
}
/**
* Performs single message formatting.
* @param clientIP IP address of message sender.
* @param strNick nick name of sender.
* @param strMessage textual message contents.
* @param moodType mood type for current message.
* @return Formatted message HTML.
*/
function Messages_formatMessage(clientIP, strNick, strMessage, moodType) {
var strFormatted = "<font color=\"#006666\">" + strNick
+ " (" + clientIP + "): " + strMessage + "</font>";
if(moodType > 0 && moodType <= 5) {
strFormatted += " <img src=\"img/mood" + moodType + ".gif\">";
}
return strFormatted;
}
/**
* Replaces all new line symbols to be visible in HTML.
*/
function Messages_replaceNewLine(source) {
var re = /\n/g;
return source.replace(re, "<BR>");
}
/**
* Prepares messages store for easy accessing.
* @return LimitedXML object with shared messages.
*/
function Messages_getMessages() {
var objMessages = new LimitedXML("Messages", getMaxMessages())
return objMessages;
}
// Messages class
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.