I am not the author of this code, but it is no longer maintained. So I am trying to fix it, but I have very little experience in javascript.
Since Firefox 9, Components.classesByID["{3a9cd622-264d-11d4-ba06-0060b0fc76dd}"]. has been obsolete. Instead, it is suggested that
document.implementation.createDocument be used. Can someone here show me how to implement these changes? I seem to be, just banging my head with everything I have tried.
The example given at Mozilla developer network is:
var doc = document.implementation.createDocument ("http://www.w3.org/1999/xhtml", "html", null);
var body = document.createElementNS("http://www.w3.org/1999/xhtml", "body");
body.setAttribute("id", "abc");
doc.documentElement.appendChild(body);
alert(doc.getElementById("abc")); // [object HTMLBodyElement]
and the code in the .jsm I am trying to fix is:
this.fgImageData = {};
this.fgImageData["check"] = [
" *",
" **",
"* ***",
"** *** ",
"***** ",
" *** ",
" * "];
this.fgImageData["radio"] = [
" **** ",
"******",
"******",
"******",
"******",
" **** "];
this.fgImageData["menu-ltr"] = [
"* ",
"** ",
"*** ",
"****",
"*** ",
"** ",
"* "];
this.fgImageData["menu-rtl"] = [
" *",
" **",
" ***",
"****",
" ***",
" **",
" *"];
// I think I'm doing something slightly wrong when creating the document
// but I'm not sure. It works though. *FIX*
var domi = Components.classesByID["{3a9cd622-264d-11d4-ba06-0060b0fc76dd}"].
createInstance(Components.interfaces.nsIDOMDOMImplementation);
this.document = domi.createDocument("http://www.w3.org/1999/xhtml", "html", null);
this.canvas = this.document.createElementNS("http://www.w3.org/1999/xhtml", "html:canvas");
for(var name in this.fgImageData) {
if (this.fgImageData.hasOwnProperty(name)) {
var data = this.fgImageData[name];
var width = data[0].length;
var height = data.length;
this.canvas.width = width;
this.canvas.height = height;
var g = this.canvas.getContext("2d");
g.clearRect(0, 0, width, height);
var idata = g.getImageData(0, 0, width, height);
for(var y=0, oy=0; y<height; y++, oy+=idata.width*4)
for(var x=0, ox=oy; x<width; x++, ox+=4)
idata.data[ox+3] = data[y][x] == " " ? 0 : 255;
this.fgImageData[name] = idata;
}
}
},