misc.js

Summary

No overview generated for 'misc.js'


// This contains misc stuff that isn't strictly related to XBLinJS.

/**
  display an object in an 'alert' box

  <p>display <tt>alert()</tt>s an object with some relatively nice
  formatting, showing the relevant attributes and eliding some things
  like functions that shouldn't be displayed as strings. Works more
  nicely in Mozilla where more of the browser-provided objects have
  nicer string representations than in IE, but works better in both
  than a simple <tt>alert(object)</tt>.</p>

  <p>This does require the object to support the <tt>for (var x in
  object)</tt> syntax, and every once in a while you will find
  a browser object which doesn't.</p>
*/
function display(object) {
  if (typeof(object) == typeof("") || typeof(object) == typeof(1)) {
    alert(object);
    return;
  }
  var res = "";

  // sort the names
  var names = getKeys(object);
  names.sort();
  for (var nameIdx in names) {
    name = names[nameIdx];
    if (typeof(object[name]) != "function") {
      res += name + ": " + object[name] + "\n";
    } else {
      res += name + ": [function]\n";
    }
  }
  alert(res);
}

/**
 Given a JS object, returns a list of the keys of the values in that object.
*/
function getKeys(object) {
  var keys = [];
  for (var name in object) keys.push(name)
  return keys;
}

/**
 Given a DOM node, empty it of all children nodes by removing them
 until they are all gone.
*/
function emptyNode (domNode) {
  while (domNode.childNodes.length) {
    domNode.removeChild(domNode.childNodes[0]);
  }
}



Documentation generated by JSDoc on Tue May 3 17:16:26 2005