Start pagina

ChatBox



A ChatBox in JavaScript

This is an extendable chatbox in javascript. It looks like this:

Please wait, loading...

This code has been tested on Mozilla Firefox 1.4 and Internet Explorer 6 only. It should work on most browsers that support XMLHttpRequest. If it doesn't, please contact the author.

You can download the zip with all the code.

Source code

Here is some sample code that demonstrates how to set up the above chatbox.

The call


    var chat = new nl.zeekat.chat.SimpleChat("http://zeekat.nl/downloads/chatbox/","chatbox");
    chat.start();

simplechat.js

This defines the nl.zeekat.chat.SimpleChat class. This is just about the simplest working chatbox class you can build on top of the ChatBase class.


/*
    Copyright (c) 2005 Joost Diepenmaat, Zeekat Softwareontwikkeling, 
    all rights reserved.

    Permission is hereby granted, free of charge, to any person obtaining 
    a copy of this software and associated documentation files (the 
    "Software"), to deal in the Software without restriction, including 
    without limitation the rights to use, copy, modify, merge, publish, 
    distribute, sublicense, and/or sell copies of the Software, and to 
    permit persons to whom the Software is furnished to do so, subject to 
    the following conditions:

    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
    IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 
    CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
    OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
    OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


    simplechat.js $Revision: 1.10 $

    A javascript chatbox using XMLHttpRequest.

    The webpage for this code is at http://zeekat.nl/downloads/chatbox/
*/



(function(){

    var xjs = nl.zeekat.xjs;
    var chat = nl.zeekat.chat;

    chat.SimpleChat = xjs.constructor({
        
        prototype: new chat.ChatBase(),
        
        init: function ( baseUrl, elementId ) {
            if (arguments.length > 0) {
                this.messagesUrl = baseUrl + "/messages.xml";
            }
        },
        
        send: function(message) {
            var chatbox = this;
            chatbox.inputBox.value="";
            chatbox.inputBox.focus();
            this.getRequest(
                this.baseUrl+"/chatbox.cgi?message="+escape(message)+"&author="+escape(chatbox.authorBox.value),
                function (resp) {
                    chatbox.updateStatus("Message posted");
                    chatbox.secondsLeft = 3; 
                    chatbox.countDown();
                },
                null
            );
        },
 

        parseMessage: function(node) {
            var index = 0;
            var nindex = 0;
            var html = "";
            var text = node.firstChild.data;
            this.updateStatus("msg "+text);
            var author = node.getAttribute("author");
            var emote = (text.indexOf("/me") == 0 || text.indexOf("/me") == 1);
            if (emote) {
                text = text.substring(4,text.length);
            }
            html = this.htmlEscape(text);
            html = html.replace(/(http:\/\/\S*)/g,'<a href="$1">$1</a>'); 
            var r = {
                emote: emote,
                html:  html,
                author: author
            };
            return r;
        },
        
       
        createInterface: function() {
            chat.SimpleChat.superclass.createInterface.apply(this);
            this.authorBox = document.createElement("input");
            this.authorBox.type = 'text';
            this.authorBox.value = "anonymous";
            this.form.insertBefore(this.authorBox,this.form.firstChild);
        }
    });

})();


chatbase.js

This is the base class for the chatbox: nl.zeekat.chat.ChatBase. It is intended to be flexible enough to allow for subclasses that use different message formats and functionality. I'm working on a subclass for the perlmonks chatterbox, too. All code is available the zipfile above.

Depends on the xjs library.

chatbox.cgi

This is the server-side component. It stores the last 10 messages in an XML file.

messages.xml

This is were the messages are stored for this demo. See for yourself.

cialis best price online

2,3 Although historically erectile dysfunction was a problem identified and treated by urologists, today primary care physicians and other specialists write 80% of the prescriptions for sildenafil, the most popular drug used to treat the condition. cialis online . Inhibition of PDE-5 increases cGMP activity, which increases vasodilatory effects of NO. One possibility is that high levels of cGMP induced by PDE5 blockade reduce the cytosolic Ca2+ concentration (46), leading to a reduction of the calcium-dependent protein kinase C activity (47) that in turn prevents up-regulation of IL-4R (48). " Q. "Because the herpes virus persists in the nerve cell for as long as it is alive and nerve cells typically do not reproduce, this represents the first-ever demonstration of a long-term treatment for ED that does not rely on the chronic administration of drugs that can have potentially harmful side effects," study co-leader Joseph C. S5, available at http://www. (The erection would last until the constricting band is released, but longer than 30 min is not recommended. viagra online without prescription . A reduced flow of blood as a result of atherosclerosis can sometimes be diagnosed by finding diminished arterial pulses in the legs or listening with a stethoscope for bruits (the sound of blood flowing through narrowed arteries). viagra canada . How should sildenafil (Viagra) be administered? Sildenafil is available as oral tablets at doses of 25, 50, and 100 mg. Men who are hypogonadic, who desire a restoration of libido, and who wish to become sexually active usually benefit from the exogenous supplementation of androgens. cialis online without prescription . On day 12, all groups received 107 AH-1–pulsed CFSEhigh-labeled BALB/c splenocytes admixed with 107 HA-pulsed CFSElow-labeled BALB/c splenocytes. viagra online without prescription . online viagra . So set that argument aside. S6 shows that sildenafil does not alter IL-13 or IFN- production from CD11b+ cells. buy cialis .