XUL: innerHTML()

Posted on Jul 16, 2009 in Code, JavaScript, XUL | 0 comments

While I’m on a XUL bint… here’s how to implement innerHTML in XUL. Invaluable for debugging:

1
2
3
4
Object.prototype.xulInnerHTML = function()
{
  return (new XMLSerializer()).serializeToString(this);
};

Usage:

1
2
var myElement = document.getElementById("myID");
alert(myElement.xulInnerHTML);

EDIT: I’ve since learned that extending the built-into JS objects in this manner is NOT recommended. Instead you should implement this function as a procedural function instead. Just a heads up.

Read More

Deleting selected row(s) from XUL tree

Posted on Jul 16, 2009 in Code, JavaScript, XUL | 0 comments

XUL is fun, but DAMN there’s not enough doc out there. Coming up with this function took far longer than it should! Other functions I found on the web didn’t work for my case.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
var g = {};
g.removeSelectedTreeRows = function(treeID)
{
 var tree = document.getElementById(treeID);
 var rangeCount = tree.view.selection.getRangeCount();
 var start = {};
 var end   = {};
 for (var i=0; i<rangeCount; i++)  
 {  
 tree.view.selection.getRangeAt(i, start, end);
 for (var c=end.value; c>=start.value; c--)  
 {
 tree.view.getItemAtIndex(c).parentNode.removeChild(tree.view.getItemAtIndex(c));
 }
 }
};
Read More