MozileCore.js
Summary
This file defines the Mozile object, which contains most of Mozile's methods and properties. Also defines the MozileCommand and MozileCommandList objects, from which all other commands are derived, and extends the Node and Selection objects in simple ways.
Version: 0.7.0
Author: James A. Overton
var XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var matchNonWS = /\S/;
function Mozile(optionsString) {
var optionsArray = this.parseOptions(optionsString);
this.version = "0.7.0";
this.root = null;
this.mode = "XHTML";
this.namespace = null;
this.debugLevel = 0;
this.scriptList = new Array("Mozile-Core-MozileCore.js");
this.linkList = new Array();
this.styleList = new Array();
this.moduleList = new Array();
this.commandList = new Array();
this.acceleratorList = new Array();
this.editorList = new Array();
this.currentEditor = null;
this.styleSheet = null;
this.toolbar = null;
this.toolbarUpdateFrequency = 2;
this.firstToolbarShow = true;
this.lastFocusNode = null;
this.lastIP = new Array("","","");
this.keyCounter = 0;
this.maxKeyCount = 20;
this.keyboardShortcuts = true;
this.changesSaved = true;
this.operatingSystem = null;
if(optionsArray["root"]) {
this.root = optionsArray["root"];
}
else {
return "Error initializing Mozile object -- invalid root provided.";
}
if(optionsArray["mode"] && (optionsArray["mode"]=="HTML" || optionsArray["mode"]=="XHTML" || optionsArray["mode"]=="XML") ) {
this.mode = optionsArray["mode"];
}
if(optionsArray["namespace"]) {
this.namespace = optionsArray["namespace"];
}
if(optionsArray["debugLevel"]) {
this.debugLevel = optionsArray["debugLevel"];
}
if(optionsArray["toolbarUpdateFrequency"]) {
this.toolbarUpdateFrequency = optionsArray["toolbarUpdateFrequency"];
}
if(optionsArray["keyboardShortcuts"] && optionsArray["keyboardShortcuts"]=="false") {
this.keyboardShortcuts = false;
}
if(optionsArray["warnBeforeUnload"] && optionsArray["warnBeforeUnload"]=="false") {
window.onbeforeunload = function() { return; }
}
else {
window.onbeforeunload = function() {
return "There are unsaved changes in this document. Changes will be lost if you navigate away from this page.";
}
}
var userAgent = navigator.userAgent.toLowerCase();
if(userAgent.indexOf("windows") >= 0) this.operatingSystem = "Windows";
if(userAgent.indexOf("linux") >= 0) this.operatingSystem = "Linux";
if(userAgent.indexOf("macintosh") >= 0) this.operatingSystem = "Mac";
return "Success";
}
function mozileDebug(details, level, message) {
if(!this.debugLevel || level > this.debugLevel) return true;
var date = new Date();
mozileDebugList.push([date.toLocaleString(), details, level, message]);
return true;
}
var mozileDebugList = new Array();
Mozile.prototype.debug = mozileDebug;
Mozile.prototype.loadScript = function(src, id) {
var f = new Array("core/MozileCore.js","Mozile.loadScript()");
this.debug(f,3,"Loading script "+ src +" with id "+ id);
var scriptTag ="";
if(document.documentElement.tagName.toLowerCase()=="html") {
scriptTag = document.createElement("script");
var head = document.getElementsByTagName("head")[0];
}
else {
scriptTag = document.createElementNS(XHTMLNS,"script");
}
scriptTag.setAttribute("id", id);
scriptTag.setAttribute("src", src);
scriptTag.setAttribute("type","application/x-javascript");
if(head) {
head.appendChild(scriptTag);
}
else {
document.documentElement.insertBefore(scriptTag,document.documentElement.firstChild);
}
this.scriptList.push(id);
return true;
}
Mozile.prototype.unloadScript = function(id) {
var f = new Array("core/MozileCore.js","Mozile.unloadScript()");
this.debug(f,3,"Unloading script "+id);
var scripts = document.getElementsByTagName("script");
for(i=0;i<scripts.length;i++) {
if(scripts[i].getAttribute("id") == id) {
scripts[i].parentNode.removeChild(scripts[i]);
}
}
return true;
}
Mozile.prototype.loadLink = function(href, id) {
var f = new Array("core/MozileCore.js","Mozile.loadLink()");
this.debug(f,3,"Loading link "+ href +" with id "+ id);
var linkTag;
if(document.documentElement.tagName.toLowerCase()=="html") {
linkTag = document.createElement("link");
var head = document.getElementsByTagName("head")[0];
}
else {
linkTag = document.createElementNS(XHTMLNS,"link");
}
linkTag.setAttribute("id", id);
linkTag.setAttribute("href", href);
linkTag.setAttribute("rel", "stylesheet");
linkTag.setAttribute("type", "text/css");
if(head) {
head.appendChild(linkTag);
}
else {
document.documentElement.insertBefore(linkTag,document.documentElement.firstChild);
}
this.linkList.push(id);
return true;
}
Mozile.prototype.unloadLink = function(id) {
var f = new Array("core/MozileCore.js","Mozile.unloadLink()");
this.debug(f,3,"Unloading link "+id);
var links = document.getElementsByTagName("link");
for(i=0;i<links.length;i++) {
if(links[i].getAttribute("id") == id) {
links[i].parentNode.removeChild(links[i]);
}
}
return true;
}
Mozile.prototype.loadModule = function(configString) {
var f = new Array("core/MozileCore.js","Mozile.loadModule()");
this.debug(f,2,"Loading module using configuration string: "+configString);
var configArray = this.parseConfig(configString);
if(this.moduleList[configArray['name']]) {
this.debug(f,0,"Error: Module "+ configArray['name'] +" is already loaded. It will not be loaded again.");
return false;
}
var src="";
if(configArray['remotePath']) { src = configArray['remotePath']; }
else { src = this.root +"modules/"; }
src = src + configArray['name'];
if(configArray['remoteVersion']) src = src +"-"+ configArray['remoteVersion'];
src = src +"/"+ configArray['name'] +".js"
this.debug(f,2,"Source for module: "+src);
var id = "Mozile-"+ configArray['name'] +"-"+ configArray['name'] +".js";
this.loadScript(src,id);
this.moduleList[configArray['name']]="unknown version";
return true;
}
Mozile.prototype.registerModule = function(moduleName, versionString) {
var f = new Array("core/MozileCore.js","Mozile.registerModule()");
this.debug(f,3,"Registering module "+ moduleName +" version "+ versionString);
this.moduleList[moduleName]=versionString;
return true;
}
Mozile.prototype.unregisterModule = function(moduleName) {
var f = new Array("core/MozileCore.js","Mozile.unregisterModule()");
this.debug(f,3,"Unregistering module "+ moduleName);
if(!this.moduleIsLoaded(moduleName)) return false;
var newModuleList = new Array();
for(key in this.moduleList) {
if(key != moduleName) newModuleList[key] = this.moduleList[key];
}
this.moduleList = newModuleList;
return true;
}
Mozile.prototype.moduleIsLoaded = function(moduleName, requirements) {
var f = new Array("core/MozileCore.js","Mozile.moduleIsLoaded()");
this.debug(f,3,"Checking for module "+ moduleName +" with requirements "+ requirements);
if(requirements) {
var loadedVersion = this.moduleList[moduleName];
if(this.checkRequirements(loadedVersion,requirements)) return true;
else return false;
}
else {
if(this.moduleList[moduleName]) return true;
else return false;
}
}
Mozile.prototype.checkRequirements = function(versionString, requirements) {
var f = new Array("core/MozileCore.js","Mozile.checkRequirements()");
this.debug(f,3,"Checking requirements for version "+ versionString +" against requirements "+ requirements);
var reqArray = this.parseOptions(requirements);
var parseVersion = /(\d*)\.(\d*)\.(\d*)/;
var version = parseVersion.exec(versionString);
if(!version) return false;
if(reqArray['requireVersion']) {
if(versionString == reqArray['requireVersion']) return true;
else return false;
}
if(reqArray['minVersion']) {
var minVersion = parseVersion.exec(reqArray['minVersion']);
if(minVersion) {
if(version[1] < minVersion[1]) return false;
if(version[2] < minVersion[2]) return false;
if(version[3] < minVersion[3]) return false;
}
}
if(reqArray['maxVersion']) {
var maxVersion = parseVersion.exec(reqArray['maxVersion']);
if(minVersion) {
if(version[1] > maxVersion[1]) return false;
if(version[2] > maxVersion[2]) return false;
if(version[3] > maxVersion[3]) return false;
}
}
if(reqArray['notVersion']) {
for(var n=0; n < reqArray['notVersion'].length; n++) {
if(versionString == reqArray['notVersion'][n]) return false;
}
}
return true;
}
Mozile.prototype.parseConfig = function(configString) {
var f = new Array("core/MozileCore.js","Mozile.parseConfig()");
this.debug(f,3,"Parsing configuration string: "+configString);
var configArray = new Array();
configArray['configString']=configString;
var firstWord = /\s*(\w*)/;
var arr = firstWord.exec(configString);
var name = arr[1]; // the match we want
configArray['name']=name;
if(configString.indexOf(":")==-1) {
return configArray;
}
var optionString = configString.substring(configString.indexOf(":")+1, configString.length);
var optionArray = this.parseOptions(optionString);
for(key in optionArray) {
configArray[key]=optionArray[key];
}
return configArray;
}
Mozile.prototype.parseOptions = function(optionString) {
var f = new Array("core/MozileCore.js","Mozile.parseOptions()");
this.debug(f,3,"Parsing option string: "+optionString);
var optionArray = new Array();
var options = optionString.split(",");
var parseOption = /(\S*)='(.*)'|(\S*)=(\S*)/;
var option, arr;
for(o in options) {
option = options[o];
arr = parseOption.exec(option);
if(arr) {
var key,val;
if(!arr[1] && !arr[2]) key=arr[3],val=arr[4];
else key=arr[1],val=arr[2];
if(key=="notVersion") {
if(!optionArray['notVersion']) optionArray['notVersion'] = new Array();
optionArray['notVersion'].push(val);
}
else {
optionArray[key]=val;
}
}
}
return optionArray;
}
Mozile.prototype.createCommand = function(configString) {
var f = new Array("core/MozileCore.js","Mozile.createCommand()");
this.debug(f,3,"Creating command "+ configString);
var configArray = this.parseConfig(configString);
var name = configArray['name'];
var command;
var create = "command = new "+name+"(configArray)";
eval(create);
return command;
}
Mozile.prototype.registerCommand = function(command) {
var f = new Array("core/MozileCore.js","Mozile.registerCommand()");
this.debug(f,3,"Registering command "+ command +" with id "+ command.id);
var id = command.id;
if(this.commandIsRegistered(id)) return false;
else {
this.commandList[id] = command;
if(command.accelerator) {
var accel = command.accelerator;
if(this.operatingSystem=="Mac") {
accel = accel.replace("Command", "Meta");
}
else {
accel = accel.replace("Command", "Control");
}
this.acceleratorList[accel] = command;
}
return true;
}
}
Mozile.prototype.unregisterCommand = function(id) {
var f = new Array("core/MozileCore.js","Mozile.unregisterCommand()");
this.debug(f,3,"Unregistering command "+ id);
if(!this.commandIsRegistered(id)) return true;
else {
this.commandList[id] = null;
return true;
}
}
Mozile.prototype.commandIsRegistered = function(id) {
var f = new Array("core/MozileCore.js","Mozile.commandIsRegistered()");
this.debug(f,3,"Checking for command "+ id);
if(this.commandList[id]) return true;
else return false;
}
Mozile.prototype.executeCommand = function(id, event) {
var f = new Array("core/MozileCore.js","Mozile.executeCommand()");
this.debug(f,3,"Executing command "+ id +" "+ event);
var cleanId = /(.*)(\-Button|\-Menuitem)$/;
var result = cleanId.exec(id);
var commandId;
if(result) commandId = result[1];
else commandId = id;
if(!this.commandIsRegistered(commandId)) return false;
else {
var command = this.commandList[commandId];
if(this.keyCounter != 0) this.storeState(command);
result = command.command(event);
if(result && command.id!="Mozile-Undo" && command.id!="Mozile-Redo") this.storeState(command);
this.updateToolbar(true);
return true;
}
}
Mozile.prototype.handleKeypress = function(event) {
var f = new Array("core/MozileCore.js","Mozile.handleKeypress()");
this.debug(f,3,"Handling keypress event "+ event);
if(event.keyCode >= 112 & event.keyCode <= 135) return true;
var selection = window.getSelection();
if(!selection.focusNode) return true;
if(event.keyCode >=33 && event.keyCode <= 40) {
if(event.keyCode == 37 || event.keyCode == 39) {
if(selection.focusNode == this.lastIP[0] && selection.focusOffset == this.lastIP[1] && event.keyCode == this.lastIP[2]) {
var direction="next";
if(event.keyCode==37) direction="previous";
this.debug(f,3,"Cursor seems stuck. Jumping to "+direction+" IP.");
var node = this.seekTextNode(direction, selection.focusNode);
if(direction=="next") selection.collapse(node, 0);
else selection.collapse(node, node.textContent.length);
event.stopPropagation();
event.preventDefault();
}
else {
this.lastIP = [selection.focusNode, selection.focusOffset, event.keyCode];
}
return true;
}
if(this.toolbarUpdateFrequency==2) {
this.updateToolbar();
}
return true;
}
if(this.keyboardShortcuts && (event.ctrlKey || event.metaKey)) {
var accel = "";
if(event.metaKey) accel = accel + "Meta-";
if(event.ctrlKey) accel = accel + "Control-";
if(event.altKey) accel = accel + "Alt-";
if(event.shiftKey) accel = accel + "Shift-";
accel = accel + String.fromCharCode(event.charCode).toUpperCase();
if(this.acceleratorList[accel]) {
this.executeCommand(this.acceleratorList[accel].id, event);
this.updateToolbar();
event.stopPropagation();
event.preventDefault();
return true;
}
else {
return true;
}
}
try {
var userModify = document.defaultView.getComputedStyle(selection.focusNode.parentNode, '').getPropertyValue("-moz-user-modify").toLowerCase();
var userInput = document.defaultView.getComputedStyle(selection.focusNode.parentNode, '').getPropertyValue("-moz-user-input").toLowerCase();
if(userModify=="read-only" || userInput=="disabled") return true;
} catch(e) {
alert("Bad selection? "+e+"\n"+selection.focusNode);
}
if(event.keyCode == event.DOM_VK_BACK_SPACE) {
this.deletion("previous");
event.stopPropagation();
return true;
}
if(event.keyCode == event.DOM_VK_DELETE){
this.deletion("next");
event.stopPropagation();
return true;
}
var whiteSpace = document.defaultView.getComputedStyle(selection.focusNode.parentNode, '').getPropertyValue("white-space").toLowerCase();
if(event.keyCode == event.DOM_VK_ENTER || event.keyCode == event.DOM_VK_RETURN){
if(whiteSpace=="pre") {
this.insertString("\n");
}
else {
this.splitBlock();
}
this.storeState("Enter Key");
event.stopPropagation();
return true;
}
if(event.keyCode == event.DOM_VK_TAB) {
this.insertString("\t");
this.keyCounter++;
if(this.keyCounter > this.maxKeyCount) this.storeState("Typing");
event.stopPropagation();
event.preventDefault();
return true;
}
if(!event.ctrlKey && !event.metaKey) {
this.insertString(String.fromCharCode(event.charCode));
this.keyCounter++;
if(this.keyCounter > this.maxKeyCount) this.storeState("Typing");
event.stopPropagation();
event.preventDefault();
}
return true;
}
Mozile.prototype.handleKeyup = function(event) {
var f = new Array("core/MozileCore.js","Mozile.handleKeyup()");
this.debug(f,3,"Handling keyup event "+ event);
if(event.keyCode >=33 && event.keyCode <= 40) {
mozile.updateToolbar();
return true;
}
if(event.keyCode == event.DOM_VK_BACK_SPACE) {
this.storeState("Backspace Key");
return true;
}
if(event.keyCode == event.DOM_VK_DELETE){
this.storeState("Delete Key");
return true;
}
return true;
}
Mozile.prototype.insertString = function(string) {
var f = new Array("core/MozileCore.js","Mozile.insertString()");
this.debug(f,3,"Inserting string "+ string);
var selection = window.getSelection();
if(!selection.isCollapsed) {
this.deletion("next");
}
var focusNode = selection.focusNode;
if(focusNode.nodeType != 3) {
selection.extend(focusNode.firstChild,0);
focusNode = selection.focusNode;
if(focusNode.nodeType != 3) {
this.debug(f,0,"This node is not a text node! " + focusNode);
return false;
}
}
focusNode.insertData(selection.focusOffset, string);
try {
selection.extend(selection.focusNode,selection.focusOffset+string.length);
}
catch(e) {
alert("Error in insertString "+e);
}
selection.collapseToEnd();
return true;
}
Mozile.prototype.insertFragment = function(fragment) {
var f = new Array("core/MozileCore.js","Mozile.insertFragment()");
this.debug(f,3,"Inserting fragment "+ fragment);
var selection = window.getSelection();
if(!selection.isCollapsed) {
this.deletion("next");
}
var anchorNode = selection.anchorNode;
if(anchorNode.nodeType != 3) {
this.debug(f,0,"This node is not a text node! "+anchorNode);
return false;
}
selection.anchorNode.splitText(selection.anchorOffset);
var parent = selection.anchorNode.parentNode;
var next = selection.anchorNode.nextSibling;
var children;
if(fragment.documentElement) children = fragment.documentElement.childNodes;
else children = fragment.cloneNode(true).childNodes;
var newNode;
for(var i=0;i<children.length;i++) {
newNode = children[i].cloneNode(true);
parent.insertBefore(newNode, next);
}
selection.collapseToEnd();
return true;
}
Mozile.prototype.deletion = function(direction) {
var f = new Array("core/MozileCore.js","Mozile.deletion()");
this.debug(f,3,"Deleting in direction "+ direction);
var selection = window.getSelection();
var collapsed = selection.isCollapsed;
if(collapsed) {
var arr = this.seekIP(direction, selection.focusNode, selection.focusOffset);
if(!arr || !arr[0]) return false;
var userModify = document.defaultView.getComputedStyle(arr[0].parentNode, '').getPropertyValue("-moz-user-modify").toLowerCase();
var userInput = document.defaultView.getComputedStyle(arr[0].parentNode, '').getPropertyValue("-moz-user-input").toLowerCase();
if(userModify=="read-only" || userInput=="disabled") return false;
try {
selection.extend(arr[0],arr[1]);
}
catch(e) {
return false;
}
}
var range = selection.getRangeAt(0).cloneRange();
var startBlock = range.startContainer.parentBlock;
var endBlock = range.endContainer.parentBlock;
if(startBlock==endBlock || !collapsed) {
selection.deleteContents();
}
else {
if(direction=="previous") {
range.setStart(range.startContainer, range.startOffset+1);
}
}
if(collapsed && selection.anchorNode.nodeType==1) {
var text = document.createTextNode("");
selection.anchorNode.appendChild(text);
range.selectNode(text);
range.collapse(true);
selection.removeAllRanges();
selection.addRange(range);
}
if(startBlock != endBlock ) {
range.collapse(true);
selection.removeAllRanges();
selection.addRange(range);
this.insertFragment(endBlock);
endBlock.parentNode.removeChild(endBlock);
}
return true;
}
Selection.prototype.deleteContents = function() {
var range = document.createRange();
try {
range.setStart(this.anchorNode, this.anchorOffset);
range.setEnd(this.focusNode, this.focusOffset);
this.collapseToEnd();
} catch(e) {
range.setEnd(this.anchorNode, this.anchorOffset);
range.setStart(this.focusNode, this.focusOffset);
this.collapseToStart();
}
range.deleteContents();
return true;
}
Mozile.prototype.splitBlock = function() {
var f = new Array("core/MozileCore.js","Mozile.splitBlock()");
this.debug(f,3,"Splitting block");
var selection = window.getSelection();
if(!selection.isCollapsed) {
selection.deleteContents();
}
var range = selection.getRangeAt(0).cloneRange();
var focusNode = selection.focusNode;
var focusOffset = selection.focusOffset;
var node = focusNode;
var flag = false;
var display;
node = node.getParentBlock();
if(node.parentNode) {
range.selectNodeContents(node);
var nodeString = range.toString();
range.setStart(focusNode, focusOffset);
var newNode = document.createElement(node.nodeName);
var rangeString = range.toString();
var textNode = null;
if(rangeString!="") {
newNode.appendChild(range.extractContents());
}
else {
}
switch(rangeString) {
case nodeString:
newNode.appendChild(document.createTextNode(""));
node.parentNode.insertAfter(newNode, node);
textNode = focusNode;
break;
case "":
textNode = document.createTextNode("");
newNode.appendChild(textNode);
node.parentNode.insertAfter(newNode, node);
break;
default:
newNode.appendChild(range.extractContents());
node.parentNode.insertAfter(newNode, node);
textNode = this.seekTextNode("next", focusNode);
break;
}
try {
selection.extend(textNode, 0);
selection.collapseToEnd();
}
catch(e) {
this.debug(f,3,"Major error splitting block: "+e);
}
}
this.debug(f,3,"Done splitting block");
return true;
}
Mozile.prototype.seekIP = function(direction, startNode, startOffset) {
var f = new Array("core/MozileCore.js","Mozile.seekIP()");
this.debug(f,3,"Seeking IP in direction "+ direction +" starting at "+startNode+" "+startOffset);
var range = document.createRange();
var newNode;
if(direction=="previous" && startOffset==0) {
newNode = this.seekTextNode(direction, startNode);
if(newNode) return this.seekIP(direction, newNode, newNode.textContent.length);
else return false;
}
try {
range.selectNode(startNode);
}
catch(e) {
return false;
}
var content = range.toString();
if(direction=="next" && startOffset==content.length) {
newNode = this.seekTextNode(direction, startNode);
if(newNode) return this.seekIP(direction, newNode, 0);
else return false;
}
var currentOffset;
var wsFlag = false; // this will be set to true once the first white-space character is envountered.
var wsMode = document.defaultView.getComputedStyle(startNode.parentNode, '').getPropertyValue("white-space").toLowerCase();
if(direction=="next") currentOffset = startOffset;
else currentOffset = startOffset-1;
var arr = new Array();
while(currentOffset >= 0 && currentOffset < content.length) {
if(wsMode=="pre" || matchNonWS.test(content.charAt(currentOffset))) {
arr[0] = startNode;
if(wsFlag) {
if(direction=="next") arr[1]=currentOffset;
else arr[1]=currentOffset+1;
}
else {
if(direction=="next") arr[1]=currentOffset+1;
else arr[1]=currentOffset;
}
return arr;
}
else {
wsFlag = true;
if(direction=="next") currentOffset++;
else currentOffset--;
}
}
if(wsFlag) {
arr[0] = startNode;
if(direction=="next") arr[1]=currentOffset;
else arr[1]=currentOffset+1;
return arr;
}
newNode = this.seekTextNode(direction, startNode);
if(newNode) {
if(direction=="next") return this.seekIP(direction, newNode, 1);
else return this.seekIP(direction, newNode, newNode.textContent.length);
}
this.debug(f,1,"Something broke! "+currentOffset+" "+content.length);
return false;
}
Mozile.prototype.seekTextNode = function(direction, startNode) {
var f = new Array("core/MozileCore.js","Mozile.seekTextNode()");
this.debug(f,3,"Seeking Text Node in direction "+ direction +" starting at "+startNode);
var treeWalker = document.createTreeWalker(document, NodeFilter.SHOW_TEXT, null, false);
while(treeWalker.currentNode != startNode) {
treeWalker.nextNode();
}
var checkNode;
if(direction=="next") checkNode=treeWalker.nextNode();
else checkNode=treeWalker.previousNode();
var wsMode;
while(checkNode) {
if(matchNonWS.test(checkNode.textContent)) return checkNode;
wsMode = document.defaultView.getComputedStyle(checkNode.parentNode, '').getPropertyValue("white-space").toLowerCase();
if(wsMode=="pre") return checkNode;
if(direction=="next") checkNode=treeWalker.nextNode();
else checkNode=treeWalker.previousNode();
}
this.debug(f,1,"Something broke!");
return false;
}
Mozile.prototype.createToolbar = function(type) {
var f = new Array("core/MozileCore.js","Mozile.createToolbar()");
this.debug(f,3,"Creating toolbar "+ type);
this.loadLink(this.root + "core/widgets.css", "Mozile-Core-widgets.css");
var id = "Mozile-Core-StyleSheet";
var styleTag, head;
if(document.documentElement.tagName.toLowerCase()=="html") {
styleTag = document.createElement("style");
head = document.getElementsByTagName("head")[0];
}
else {
styleTag = document.createElementNS(XHTMLNS,"style");
}
styleTag.setAttribute("id", id);
styleTag.setAttribute("type", "text/css");
if(head) {
head.appendChild(styleTag);
}
else {
document.documentElement.insertBefore(styleTag,document.documentElement.firstChild);
}
this.styleList.push(id);
var sheets = document.styleSheets;
var sheet;
for(var i=0; i < sheets.length; i++) {
if(sheets.item(i).ownerNode == styleTag) {
sheet = sheets.item(i);
break;
}
}
this.debug(f,3,"Style sheet selected: "+ i +" "+ sheet +" "+ sheet.href);
this.styleSheet = sheet;
var rule;
if(document.documentElement.tagName.toLowerCase()=="html") {
rule = "body { -moz-binding: url(" + this.root +"core/widgets.xbl#toolbar); }";
}
else {
rule = "moziletoolbar { -moz-binding: url(" + this.root +"core/widgets.xbl#toolbar); }";
document.documentElement.insertBefore(document.createElement("moziletoolbar"), document.documentElement.firstChild);
}
sheet.insertRule(rule, sheet.cssRules.length);
this.rootCommandList = mozile.createCommand("MozileCommandList: id=Mozile-RootList, label='Mozile Root List'");
var mozileList = this.rootCommandList.createCommand("MozileCommandList: id=Mozile-firstList, label='Mozile First List', image='"+this.root+"images/link.png', buttonPosition=0, menuPosition=0");
var about = mozileList.createCommand("MozileCommand: id=Mozile-About, label='About Mozile'");
about.command = function(event) {
window.open(mozile.root+"core/about.xul", "About Mozile", "centerscreen,chrome,resizable=yes");
}
var accel = mozileList.createCommand("MozileCommand: id=Mozile-Accelerators, label='Keyboard Shortcuts'");
accel.command = function(event) {
if(mozile.keyboardShortcuts) {
var message = "Mozile defines the following keyboard shortcuts:";
var accels = mozile.acceleratorList;
for(key in accels) {
message = message +"\n"+accels[key].label+" => "+key;
}
alert(message);
}
else {
alert("Mozile keyboard shortcuts have been turned off.");
}
}
var debug = mozileList.createCommand("MozileCommand: id=Mozile-Debug, label=Debug");
debug.command = function(event) {
window.open(mozile.root+"core/debug.xul", "Mozile Debugging", "centerscreen,chrome,resizable=yes");
}
var report = mozileList.createCommand("MozileCommand: id=Mozile-ReportBugs, label='Report a Bug'");
report.command = function(event) {
window.open("http://mozile.mozdev.org/bugs.html", "Mozile Bugs", "");
}
var home = mozileList.createCommand("MozileCommand: id=Mozile-Home, label='Mozile Home'");
home.command = function(event) {
window.open("http://mozile.mozdev.org", "Mozile Home", "");
}
var help = mozileList.createCommand("MozileCommand: id=Mozile-Help, label='Help'");
help.command = function(event) {
window.open(mozile.root+"docs/index.html", "Mozile Help", "");
}
var save = this.rootCommandList.createCommand("MozileCommand: id=Mozile-SaveToDialog, label=Save, tooltip='Save to a dialog', accelerator='Command-S', image='"+this.root+"images/save.png'");
save.command = function(event) {
window.open(mozile.root+"core/source.xul", "Mozile Save", "centerscreen,chrome,resizable=yes");
}
return true;
}
Mozile.prototype.initializeToolbar = function() {
var f = new Array("core/MozileCore.js","Mozile.initializeToolbar()");
this.debug(f,3,"Initializing toolbar");
commands.createBox();
var children = commands.box.childNodes;
for(var i=0; i<children.length; i++) {
this.toolbar.appendChild(children[i]);
}
return true;
}
Mozile.prototype.hideToolbar = function() {
var f = new Array("core/MozileCore.js","Mozile.hideToolbar()");
this.debug(f,3,"Hiding toolbar");
this.toolbar.collapsed = true;
}
Mozile.prototype.showToolbar = function() {
var f = new Array("core/MozileCore.js","Mozile.showToolbar()");
this.debug(f,3,"Showing toolbar. First time? " + this.firstToolbarShow);
if(this.firstToolbarShow) {
this.initializeToolbar();
this.storeState("Initial state");
this.firstToolbarShow=false;
}
this.toolbar.collapsed = false;
}
Mozile.prototype.updateToolbar = function() {
var f = new Array("core/MozileCore.js","Mozile.updateToolbar()");
this.debug(f,3,"Updating toolbar");
if(this.toolbarUpdateFrequency==0) return true;
var force = false;
if(arguments.length > 0) {
force = arguments[0];
}
var selection = window.getSelection();
if(!force) {
if(selection.focusNode == this.lastFocusNode) {
this.debug(f,4,"Toolbar update not required");
return true;
}
}
this.debug(f,3,"Updating toolbar");
this.lastFocusNode = selection.focusNode;
for(var command in this.commandList) {
try {
this.commandList[command].update();
} catch(e) {
}
}
return true;
}
Mozile.prototype.createEditor = function(id, options) {
var f = new Array("core/MozileCore.js","Mozile.createEditor()");
this.debug(f,3,"Creating editor "+ id +" "+ options);
var rule1 = "#"+ id +" { -moz-binding: url(" + this.root +"core/widgets.xbl#editor); -moz-user-focus: normal; -moz-user-modify: read-write; }";
var rule2 = "#"+ id +" * { -moz-user-focus: ignore; }";
this.styleSheet.insertRule(rule1, this.styleSheet.cssRules.length);
this.styleSheet.insertRule(rule2, this.styleSheet.cssRules.length);
return true;
}
Mozile.prototype.createEditors = function(selector, options) {
var f = new Array("core/MozileCore.js","Mozile.createEditors()");
this.debug(f,3,"Creating editor "+ selector +" "+ options);
var rule1 = selector +" { -moz-binding: url(" + this.root +"core/widgets.xbl#editor); -moz-user-focus: normal; -moz-user-modify: read-write; }";
var rule2 = selector +" * { -moz-user-focus: ignore; }";
this.styleSheet.insertRule(rule1, this.styleSheet.cssRules.length);
this.styleSheet.insertRule(rule2, this.styleSheet.cssRules.length);
return true;
}
Mozile.prototype.registerEditor = function(element) {
var f = new Array("core/MozileCore.js","Mozile.registerEditor()");
this.debug(f,3,"Registering editor "+ element);
this.editorList.push(element);
}
Mozile.prototype.setCurrentEditor = function(element) {
var f = new Array("core/MozileCore.js","Mozile.setCurrentEditor()");
this.debug(f,3,"Setting current editor "+ element);
this.currentEditor = element;
}
Mozile.prototype.cleanUp = function(element) {
var f = new Array("core/MozileCore.js","Mozile.cleanUp()");
this.debug(f,3,"Cleaning up element "+element);
var i,j=0;
var scripts = element.getElementsByTagName("script");
for(i=0; i < scripts.length; i++) {
for(j=0; j < this.scriptList.length; j++) {
if(scripts[i].getAttribute("id") == this.scriptList[j]) {
scripts[i].parentNode.removeChild(scripts[i]);
}
}
}
var links = element.getElementsByTagName("link");
for(i=0; i < links.length; i++) {
for(j=0; j < this.linkList.length; j++) {
if(links[i].getAttribute("id") == this.linkList[j]) {
links[i].parentNode.removeChild(links[i]);
}
}
}
var styles = element.getElementsByTagName("style");
for(i=0; i < styles.length; i++) {
for(j=0; j < this.styleList.length; j++) {
if(styles[i].getAttribute("id") == this.styleList[j]) {
styles[i].parentNode.removeChild(styles[i]);
}
}
}
var moziletoolbars = element.getElementsByTagName("moziletoolbar");
for(i=0; i < moziletoolbars.length; i++) {
moziletoolbars[i].parentNode.removeChild(moziletoolbar[i]);
}
return element;
}
Mozile.prototype.toHTML = function() {
var f = new Array("core/MozileCore.js","Mozile.toHTML()");
this.debug(f,3,"Rendering document to XML string");
var serializer = new XMLSerializer;
var newDoc = document.documentElement.cloneNode(true);
newDoc = this.cleanUp(newDoc);
var contents = serializer.serializeToString(newDoc);
this.changesSaved = true;
return contents;
}
Mozile.prototype.toXML = function() {
var f = new Array("core/MozileCore.js","Mozile.toXML()");
this.debug(f,3,"Rendering document to XML string");
var serializer = new XMLSerializer;
var newDoc = document.documentElement.cloneNode(true);
newDoc = this.cleanUp(newDoc);
var contents = serializer.serializeToString(newDoc);
this.changesSaved = true;
return mozileHTML2xhtml(contents);
}
Mozile.prototype.editorToHTML = function() {
var f = new Array("core/MozileCore.js","Mozile.editorToHTML()");
this.debug(f,3,"Rendering current editor "+ this.currentEditor +" to XML string");
if(!this.currentEditor) {
this.debug(f,0,"No current editor to serialize to XML!");
return false;
}
var serializer = new XMLSerializer;
var editor = this.currentEditor.cloneNode(true);
editor = this.cleanUp(editor);
var contents = serializer.serializeToString(editor);
this.changesSaved = true;
return contents;
}
Mozile.prototype.editorToXML = function() {
var f = new Array("core/MozileCore.js","Mozile.editorToXML()");
this.debug(f,3,"Rendering current editor "+ this.currentEditor +" to XML string");
if(!this.currentEditor) {
this.debug(f,0,"No current editor to serialize to XML!");
return false;
}
var serializer = new XMLSerializer;
var editor = this.currentEditor.cloneNode(true);
editor = this.cleanUp(editor);
var contents = serializer.serializeToString(editor);
this.changesSaved = true;
return mozileHTML2xhtml(contents);
}
function mozileHTML2xhtml( h ) {
var TAG = /[A-Z]/;
var c, i, x, startTag, inTag, endTag;
x = "";
startTag = endTag = inTag = false;
for( i=0; i<h.length; i++ ){
c=h[i];
if (c=='<'){
startTag = true;
inTag = endTag = false;
x+=c;
}else if (startTag) {
if ( TAG.test(c) ) {
x+=c.toLowerCase();
inTag = true;
}else{
x+=c;
if ( c == '/' )
endTag = true;
}
startTag = false;
}else if (inTag) {
if ( TAG.test(c) ) {
x+=c.toLowerCase();
}else {
inTag = false;
x+=c;
}
}else if (endTag) {
if ( TAG.test(c) ) {
x+=c.toLowerCase();
inTag = true;
}else {
x+=c;
}
endTag = false;
}else {
x+=c;
}
}
return x;
}
Mozile.prototype.storeState = function(command) {
var f = new Array("core/MozileCore.js","Mozile.storeState()");
this.debug(f,3,"Storing current state");
this.changesSaved = false;
this.keyCounter = 0;
return true;
}
Mozile.prototype.storeSelection = function() {
var f = new Array("core/MozileCore.js","Mozile.storeSelection()");
this.debug(f,3,"Storing current selection");
var selection = window.getSelection();
if(!selection.anchorNode || !selection.focusNode) {
this.debug(f,2,"No selection to store!");
return false;
}
var elementList, children;
var anchorElement;
var anchorNodeIndex = "none";
if(selection.anchorNode.nodeType==3) {
anchorElement = selection.anchorNode.parentNode;
children = anchorElement.childNodes;
for(i=0; i<children.length; i++) {
if(children[i]==selection.anchorNode) {
anchorNodeIndex = i;
break;
}
}
}
else {
anchorElement = selection.anchorNode;
}
var anchorNodeOffset = selection.anchorOffset;
var anchorElementName = anchorElement.nodeName;
var anchorElementIndex;
elementList = document.getElementsByTagName(anchorElementName);
for(var i=0; i<elementList.length; i++) {
if(elementList[i]==anchorElement) {
anchorElementIndex = i;
break;
}
}
if(selection.isCollapsed) {
focusElementName = anchorElementName;
focusElementIndex = anchorElementIndex;
focusNodeIndex = anchorNodeIndex;
focusNodeOffset = anchorNodeOffset;
}
else {
var focusElement;
var focusNodeIndex = "none";
if(selection.focusNode.nodeType==3) {
focusElement = selection.focusNode.parentNode;
children = focusElement.childNodes;
for(i=0; i<children.length; i++) {
if(children[i]==selection.focusNode) {
focusNodeIndex = i;
break;
}
}
}
else {
focusElement = selection.focusNode;
}
var focusNodeOffset = selection.focusOffset;
var focusElementName = focusElement.nodeName;
var focusElementIndex;
elementList = document.getElementsByTagName(focusElementName);
for(i=0; i<elementList.length; i++) {
if(elementList[i]==focusElement) {
focusElementIndex = i;
break;
}
}
}
var selectionArray = new Array(anchorElementName, anchorElementIndex, anchorNodeIndex, anchorNodeOffset, focusElementName, focusElementIndex, focusNodeIndex, focusNodeOffset);
return selectionArray;
}
Mozile.prototype.restoreSelection = function(selectionArray) {
var f = new Array("core/MozileCore.js","Mozile.restoreSelection()");
this.debug(f,3,"Restoring current selection using "+selectionArray);
if(!selectionArray) {
this.debug(f,2,"No selectionArray to restore!");
return false;
}
var anchorElementName = selectionArray[0];
var anchorElementIndex = selectionArray[1];
var anchorNodeIndex = selectionArray[2];
var anchorNodeOffset = selectionArray[3];
var focusElementName = selectionArray[4];
var focusElementIndex = selectionArray[5];
var focusNodeIndex = selectionArray[6];
var focusNodeOffset = selectionArray[7];
var anchorNode;
if(anchorNodeIndex!="none") {
anchorNode = document.getElementsByTagName(anchorElementName)[anchorElementIndex].childNodes[anchorNodeIndex];
}
else {
anchorNode = document.getElementsByTagName(anchorElementName)[anchorElementIndex].firstChild;
}
var focusNode;
if(focusNodeIndex!="none") {
focusNode = document.getElementsByTagName(focusElementName)[focusElementIndex].childNodes[focusNodeIndex];
}
else {
focusNode = document.getElementsByTagName(focusElementName)[focusElementIndex].firstChild;
}
var range = document.createRange();
try {
range.setStart(anchorNode, anchorNodeOffset);
range.setEnd(focusNode, focusNodeOffset);
}
catch(e) {
range = document.createRange();
range.setEnd(anchorNode, anchorNodeOffset);
range.setStart(focusNode, focusNodeOffset);
}
var selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
return true;
}
function MozileCommand() {
this.type = "MozileCommand";
this.id = null;
this.label = null;
this.tooltip = null;
this.image = null;
this.accesskey = null;
this.accelerator = null;
this.namespace = XULNS;
this.debugLevel = 0;
this.button = null;
this.menuitem = null;
if(arguments.length > 0){
var configArray = arguments[0];
this.init(configArray);
}
else return true;
return "Success";
}
MozileCommand.prototype.init = function(configArray) {
this.type = configArray['name'];
if(configArray['id'] && typeof(configArray['id'])!="null") {
this.id = configArray['id'];
}
else {
return "Error initializing MozileCommandList object -- invalid id provided: "+configArray['id'];
}
if(configArray['label'] && typeof(configArray['label'])!="null") {
this.label = configArray['label'];
}
else {
return "Error initializing MozileCommandList object -- invalid label provided: "+configArray['label'];
}
if(configArray['tooltip']) {
this.tooltip = configArray['tooltip'];
}
if(configArray['image']) {
this.image = configArray['image'];
}
if(configArray['accesskey']) {
this.accesskey = configArray['accesskey'];
}
if(configArray['accelerator']) {
this.accelerator = configArray['accelerator'];
}
if(configArray['debugLevel']) {
if(typeof(configArray['debugLevel'])=="number") {
this.debugLevel = configArray['debugLevel'];
}
else {
this.debugLevel = mozile.debugLevel;
}
}
return true;
}
MozileCommand.prototype.debug = mozileDebug;
MozileCommand.prototype.createButton = function() {
var f = new Array("core/MozileCore.js","MozileCommand.createButton()");
this.debug(f,3,"Creating button");
var button = document.createElementNS(XULNS, "toolbarbutton");
button.setAttribute("id", this.id+"-Button");
button.setAttribute("class", "mozileButton");
button.setAttribute("image", this.image);
button.setAttribute("label", this.label);
if(this.tooltip) button.setAttribute("tooltiptext", this.tooltip);
this.button = button;
return button;
}
MozileCommand.prototype.createMenuitem = function() {
var f = new Array("core/MozileCore.js","MozileCommand.createMenuitem()");
this.debug(f,3,"Creating menuitem");
var menuitem = document.createElementNS(XULNS, "menuitem");
menuitem.setAttribute("id", this.id+"-Menuitem");
menuitem.setAttribute("class", "mozileMenuitem");
menuitem.setAttribute("label", this.label);
if(this.tooltip) menuitem.setAttribute("tooltiptext", this.tooltip);
if(this.accesskey) menuitem.setAttribute("accesskey", this.accesskey);
this.menuitem = menuitem;
return menuitem;
}
MozileCommand.prototype.isActive = function() {
var f = new Array("core/MozileCore.js","MozileCommand.isActive()");
this.debug(f,4,"Checking to see if this command is active");
return false;
}
MozileCommand.prototype.update = function() {
var f = new Array("core/MozileCore.js","MozileCommand.update()");
this.debug(f,4,"Updating button and menuitem");
var button = this.button;
var menuitem = this.menuitem;
if(this.isActive()) {
if(button) {
button.setAttribute("active",true);
}
if(menuitem) {
menuitem.setAttribute("checked",true);
}
return true;
}
else {
if(button) {
button.setAttribute("active",false);
}
if(menuitem) {
menuitem.setAttribute("checked",false);
}
return false;
}
}
MozileCommand.prototype.command = function(event) {
var f = new Array("core/MozileCore.js","MozileCommand.command()");
this.debug(f,3,"Executing command "+event);
alert("Command! "+ this.id +" "+ event);
return true;
}
MozileCommandList.prototype = new MozileCommand();
MozileCommandList.prototype.constructor = MozileCommandList;
MozileCommandList.superclass = MozileCommand.prototype;
function MozileCommandList() {
if(arguments.length > 0){
var configArray = arguments[0];
this.init(configArray);
}
else return true;
this.box = null;
this.menu = null;
this.commandList = new Array();
this.buttonList = new Array();
this.menuList = new Array();
return true;
}
MozileCommandList.prototype.createCommand = function(configString) {
var f = new Array("core/MozileCore.js","MozileCommandList.createCommand()");
this.debug(f,3,"Creating command "+ configString);
var configArray = mozile.parseConfig(configString);
var name = configArray['name'];
var command;
var create = "command = new "+name+"(configArray)";
eval(create);
var buttonPosition = null;
if(configArray['buttonPosition'] != null) buttonPosition = configArray['buttonPosition'];
var menuPosition = null;
if(configArray['menuPosition'] != null) menuPosition = configArray['menuPosition'];
this.registerCommand(command, buttonPosition, menuPosition);
return command;
}
MozileCommandList.prototype.registerCommand = function(command, buttonPosition, menuPosition) {
var f = new Array("core/MozileCore.js","MozileCommandList.registerCommand()");
this.debug(f,3,"Registering command "+ command +" with id "+ command.id +" at "+ buttonPosition +" and "+ menuPosition);
var id = command.id
if(command.type!="MozileCommandList") {
mozile.registerCommand(command);
}
this.commandList[id] = command;
if(buttonPosition == null) {
this.buttonList.push(command);
}
else {
if(this.buttonList[buttonPosition]==null) {
this.buttonList[buttonPosition] = command;
}
else {
this.buttonList.splice(buttonPosition, 0, command);
}
}
if(menuPosition == null) {
this.menuList.push(command);
}
else {
if(this.menuList[menuPosition]==null) {
this.menuList[menuPosition] = command;
}
else {
this.menuList.splice(menuPosition, 0, command);
}
}
return true;
}
MozileCommandList.prototype.unregisterCommand = function(id) {
var f = new Array("core/MozileCore.js","MozileCommandList.unregisterCommand()");
this.debug(f,3,"Unregistering command "+ id);
mozile.unregisterCommand(command);
this.commandList[id]=null;
var i;
for(i=0; i < this.buttonList; i++) {
if(this.buttonList[i].id == id) {
this.buttonList.splice(i,0);
i--;
}
}
for(i=0; i < this.menuList; i++) {
if(this.menuList[i].id == id) {
this.menuList.splice(i,0);
i--;
}
}
return true;
}
MozileCommandList.prototype.createBox = function() {
var f = new Array("core/MozileCore.js","MozileCommandList.createBox()");
this.debug(f,3,"Creating box");
var box = document.createElementNS(XULNS, "box");
box.setAttribute("id", this.id+"-Box");
box.setAttribute("class", "mozileBox");
box.setAttribute("label", this.label);
if(this.tooltip) box.setAttribute("tooltiptext", this.tooltip);
var button;
for(var i=0; i < this.buttonList.length; i++) {
if(this.buttonList[i]) {
button = this.buttonList[i].button;
if(!button || button=="") {
this.buttonList[i].createButton();
button = this.buttonList[i].button;
}
box.appendChild(button);
}
}
this.box = box;
return box;
}
MozileCommandList.prototype.createButton = function() {
var f = new Array("core/MozileCore.js","MozileCommandList.createButton()");
this.debug(f,3,"Creating button");
var button = document.createElementNS(XULNS, "toolbarbutton");
button.setAttribute("id", this.id+"-Button");
button.setAttribute("class", "mozileButton");
button.setAttribute("image", this.image);
button.setAttribute("label", this.label);
if(this.tooltip) button.setAttribute("tooltiptext", this.tooltip);
button.setAttribute("type", "menu");
var menuPopup = document.createElementNS(XULNS, "menupopup");
button.appendChild(menuPopup);
var menuitem,menu;
for(var i=0; i < this.menuList.length; i++) {
if(this.menuList[i]) {
if(this.menuList[i].type!="MozileCommandList") {
menuitem = this.menuList[i].menuitem;
if(!menuitem || menuitem=="") {
this.menuList[i].createMenuitem();
menuitem = this.menuList[i].menuitem;
}
menuPopup.appendChild(menuitem);
}
else {
menu = this.menuList[i].menu;
if(!menu || menu=="") {
this.menuList[i].createMenu();
menu = this.menuList[i].menu;
}
menuPopup.appendChild(menu);
}
}
}
this.button = button;
return button;
}
MozileCommandList.prototype.createMenu = function() {
var f = new Array("core/MozileCore.js","MozileCommandList.createMenu()");
this.debug(f,3,"Creating menu");
var menu = document.createElementNS(XULNS, "menu");
menu.setAttribute("id", this.id+"-Menu");
menu.setAttribute("class", "mozileMenu");
menu.setAttribute("label", this.label);
if(this.tooltip) menu.setAttribute("tooltiptext", this.tooltip);
if(this.accesskey) menu.setAttribute("accesskey", this.accesskey);
var menuPopup = document.createElementNS(XULNS, "menupopup");
menu.appendChild(menuPopup);
var menuitem;
for(var i=0; i < this.menuList.length; i++) {
if(this.menuList[i]) {
menuitem = this.menuList[i].menuitem;
if(!menuitem || menuitem=="") {
this.menuList[i].createMenuitem();
menuitem = this.menuList[i].menuitem;
}
menuPopup.appendChild(menuitem);
}
}
this.menu = menu;
return menu;
}
MozileCommandList.prototype.updateBox = function() {
var f = new Array("core/MozileCore.js","MozileCommandList.updateBox()");
this.debug(f,3,"Updating box");
return true;
}
MozileCommandList.prototype.updateMenu = function() {
var f = new Array("core/MozileCore.js","MozileCommandList.updateMenu()");
this.debug(f,3,"Updating menu");
return true;
}
Node.prototype.insertAfter = function(newNode, refNode) {
if(refNode.nextSibling) {
return this.insertBefore(newNode, refNode.nextSibling);
}
else {
return this.appendChild(newNode);
}
}
Node.prototype.isBlock = function() {
var matchDisplayBlock = /(block|list\-item|table\-cell)/;
if(this.nodeType == 1) {
var display = document.defaultView.getComputedStyle(this, '').getPropertyValue("display").toLowerCase();
if(matchDisplayBlock.test(display)) {
return true;
}
}
return false;
}
Node.prototype.getParentBlock = function() {
var thisNode = this;
while(thisNode) {
if(thisNode.isBlock()) {
return thisNode;
}
thisNode = thisNode.parentNode;
}
return document.documentElement;
}
Node.prototype.__defineGetter__(
'parentBlock',
function() {
return this.getParentBlock();
}
);
Node.prototype.isAncestorOf = function(node) {
var thisNode = node;
while(thisNode) {
if(thisNode == this) {
return true;
}
thisNode = thisNode.parentNode;
}
return false;
}
Mozile.prototype.testFunction = function() {
return 0;
}
try {
mozileConfiguration();
}
catch(e) {
alert("Error in MozileCore.js when calling mozileConfiguration: "+e);
}
function dumpArray(arr) {
var s = "Array Dump: ";
for(key in arr) {
s = s + key +"=>"+ arr[key] +"\n";
}
alert(s);
}
function printXML(XML) {
if(!XML || XML=="") return "Nothing to print!!";
var objXMLSerializer = new XMLSerializer;
var output = objXMLSerializer.serializeToString(XML);
output = output.replace( /<(\/?)([A-Z]+)/g,
function (output,p1,p2,offset,s) {
return '<'+p1+p2.toLowerCase() ;
} ) ;
return output;
}
Documentation generated by
JSDoc on Wed Jun 29 22:15:33 2005