Source Code

for file ~/controls/OpenAjaxEventLog.js

// OpenAjaxEventLog.js
// Display an area where all the published OpenAjax events are logged.
// Copyright (c) by Matthias Hertel, http://www.mathertel.de
// This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx
// -----
// 19.12.2007 created by Matthias Hertel

function _OpenAjaxEventLog() {
  var obj = document.getElementById("_OpenAjaxEventArea");
  if (obj == null) {
    obj = document.body.appendChild(document.createElement("DIV"));
    obj.style.height = "240px";
    obj.style.overflow = "hidden";
    obj.style.border = "solid 1px blue";
    obj.style.padding = "2px";
    obj.appendChild(document.createElement("h3"));
    obj.firstChild.appendChild(document.createTextNode("OpenAjax hub event log:"));
  
    obj.dumpevent = function (eventName, eventData) {
      this.Dump(eventName + ":" + this._objToText(eventData));
    }; // dumpevent
    
    obj.Dump = function (txt) {
      var p = window.document.createElement("div");
      this.appendChild(p);
      p.appendChild(document.createTextNode(txt));

      if (this.childNodes.length > 14)
        this.removeChild(this.childNodes[1]);
    }; // Dump


    // get some pretty printable object notation in one line
    obj._objToText = function (obj) {
      var s = "";

      if (obj == null) {
        s = "(null)";
      } else if (obj.constructor == String) {
        s = "\"" + obj + "\"";
      } else if (typeof (obj) == "function") {
        s += " [function]" + obj;

      } else if (obj.constructor == Array) {
        s += "[";
        for (n = 0; n < obj[p].length; n++) {
          if (n > 0) s += ", ";
          s += obj[n];
        }
        s += "]";
      } else if (obj.constructor == Object) {
        s += "{";
        for (n in obj) {
          s += n + ": " + obj[n] + ", ";
        }
        s += "}";
      } else {
        s = obj.toString();
      }
      return (s);
    }; // _objToText
    
    if (window.OpenAjax) {
      OpenAjax.hub.subscribe("**", obj.dumpevent, obj);
      OpenAjax.hub.registerLibrary("_OpenAjaxEventLog", "http://www.mathertel.de/OpenAjax/OpenAjaxEventLog");
    }
  } // if
} // _OpenAjaxEventLog

_OpenAjaxEventLog();



This page is part of the http://www.mathertel.de/ web site.

For updates and discussions see http://ajaxaspects.blogspot.com/.