Perldoc-Server

 view release on metacpan or  search on metacpan

root/static/js/OpenThought.js  view on Meta::CPAN

    var packet = "";

    for (var child in hash) {
        if(typeof(hash[child]) == "object") {
            for(var grandchild in hash[child])
            {
                if (typeof(hash[child][grandchild]) != "function") {
                    packet += escape(child) + "=" +
                              escape(hash[child][grandchild]) + "&";
                }
            }
        }
        else {
            packet += escape(child) + "=" +
                      escape(hash[child]) + "&";
        }
    }

    // Replace '+' characters with %2B
    packet = packet.replace(/\+/g, "%2B");

    // Drop the trailing &
    packet = packet.substr(0, packet.length - 1);

    this.log.debug("Finished creating get parameter");
    return packet;
}

// Convert our parameter hash into a form for POST params
this.Hash2PostParam = function(hash)
{
    this.log.debug("Creating post params");

    var form = '<html><head><title></title></head><body><form action="" name="OpenThought" method="post" target="">';

    for (var child in hash) {
        if(typeof(hash[child]) == "object") {
            for(var grandchild in hash[child]) {
                form += '<input type="hidden" name="' + escape(child) +
                        '" value="' + escape(hash[child][grandchild]) + '">';
            }
        }
        else {
            form += '<input type="hidden" name="' + escape(child) +
                    '" value="' + escape(hash[child]) + '">';
        }
    }

    form += '</form></body></html>';

    this.log.debug("Finished creating post params");
    return form;
}


this.getOpenChannel = function() {

    var channelName;

    for(var i=0; i < channels.length ;i++) {
        if(! channels[i]["busy"]) {
            channels[i]["busy"] = true;
            this.log.info("Reusing channel [" + i + "].");
            return channels[i];
        }
    }

    var channel = new Object;

    var id       = channels.length;
    channels[id] = channel;

    channels[id]["busy"]    = true;
    var channel_info = this.createChannel(id);
    channels[id]["channel"] = channel_info[0];
    channels[id]["type"]    = channel_info[1];

    return channels[id];
}

this.createChannel = function(channelName) {
    var channel = false;

    if (this.config.channel_type != "iframe") {

        // For the XMLHttp related tests, we need to use try/catch (largely because
        // of IE and varying ActiveX objects).  Unfortunatly, both NS4 and IE4
        // consider 'try' to be invalid syntax.  The best way I know of to handle
        // this is to use eval to hide the 'try' statements from those browsers.

        // native XMLHttpRequest object
        if(window.XMLHttpRequest) {
            eval("try { channel = new XMLHttpRequest(); } catch(e) { channel = false; }");
        }
        // IE/Windows ActiveX version
        else if(window.ActiveXObject && this.browser.version != "IE4") {
            eval("try { channel = new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) { try { channel = new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) { channel = false; } }");
        }

        // If we were able to use the XMLHttp related methods, good, go ahead and
        // return it now
        if ( channel ) {
            this.log.info("Created XMLHttpRequest/XMLHTTP channel");
            return [channel, "XMLHttp" ];
        }
    }

    var type;

    // Most of this layer/iframe code in this function was created by Brent Ashley
    // of AshleyIT for JSRS.  Used with permission.
    switch( this.browser.version ) {
        case 'NS4':
            channel = new Layer(100);
            channel.name = channelName;
            channel.clip.width = 100;
            channel.clip.height = 100;

            if (this.config.channel_visible) {
                channel.visibility = 'visible';
            }
            else {
                channel.visibility = 'hidden';
            }

            type = "layer";
            this.log.info("Created new channel [" + channelName + "], using layers for NS4");
        break;

        // If this gets called before the browser considers the web page
        // loaded, one will get a "Error 8000000a", which basically means it
        // doesn't like us changing stuff that's not ready yet.  That should
        // only ever happen when trying to call CallUrl while the page is

root/static/js/OpenThought.js  view on Meta::CPAN

                iframe.height = 20;
                iframe.width = 20;
            }
            else {
                span.style.display = none;
                iframe.style.display = none;
                iframe.style.visibility = hidden;
                iframe.height = 0;
                iframe.width = 0;
            }

            type = "iframe";
            this.log.info("Created new channel [" + channelName + "], using iframes for Konqueror");
        break;
*/

        // Handle Mozilla, IE>4, Safari, and folks last (most of these should
        // be handled by the XMLHTTP stuff, this is mostly in case somehow
        // their implementation is borked, or config.channel_type is set to
        // 'iframe')
        case 'W3C':
        case 'SFR':
        case 'KNQ':
        case 'OPR':
            var span = document.createElement('SPAN');
            span.style.display = 'none';
            span.id = "SPAN" + channelName;
            document.body.appendChild( span );
            var iframe = document.createElement('IFRAME');
            iframe.name = channelName;
            iframe.id = channelName;
            span.appendChild( iframe );
            channel = iframe;

            if (this.config.channel_visible) {
                iframe.width = 20;
                iframe.height = 20;
                iframe.frameBorder = 1;
            }
            else {
                iframe.width = 0;
                iframe.height = 0;
                iframe.frameBorder = 0;
                span.style.display = 'block';
            }

            type = "iframe";
            this.log.info("Created new channel [" + channelName + "], using iframes for Mozilla/Safari/Opera/IE5+");

        break;

    }

    return [channel, type];
}

this.Complete = function(channel) {

    if (channel.name && channel.name >= 0) {
        this.log.info('Freeing channel [' + channel.name + ']');
        channels[channel.name]["busy"] = false;
    }

    return true;
}

}

/////////////////////////////////////////////////////////////////////////////
//
// OpenThought Browser Check Class
//
function OpenThoughtBrowser(config_l) {

    this.w3c     = W3cCompat();
    this.version = Version();
    this.config  = config_l;

    function W3cCompat() {
        if (document.getElementById) {
            return true;
        }
        else {
            return false;
        }
    }

    function Version() {

        var version = "";

        // Test for browser types
        if (document.layers) {
            version = "NS4";
        }
        else if (document.getElementById) {

            // Obviously, this will break if the user changes who their browser appears
            // as.  At the moment, I'm not sure how else to do this, so we'll shoot for
            // the common case.  There *are* cases where Opera, Safari, and Konqueror
            // act differently than other browsers.
            if(window.opera) {
                version = "OPR";
            }
            else if(navigator.userAgent.indexOf("Safari")!=-1) {
                version = "SFR";
            }
            else if(navigator.userAgent.indexOf("Konqueror")!=-1) {
                version = "KNQ";
            }
            else {
                version = "W3C";
            }
        }
        else if (document.all) {
            version = "IE4";
        }
        else {
            version = "unknown";
        }
        return version;



( run in 0.529 second using v1.01-cache-2.11-cpan-d8267643d1d )