Permalink
Browse files

Fixed variables to new notation.

Corrected if/else bracket notation to match code style spec.
  • Loading branch information...
1 parent e8c9d77 commit c422e61bd4d6cab0d5777c96cbbbb00da05acfcc @h6w committed Mar 16, 2012
Showing with 42 additions and 66 deletions.
  1. +42 −66 ample/languages/xul/classes/cXULDocument.js
View
108 ample/languages/xul/classes/cXULDocument.js
@@ -16,7 +16,6 @@ cXULDocument.prototype.tooltipNode = null;
cXULDocument.prototype.commandDispatcher = null;
// Private properties
-//var hXULDocument_overlays = {};
var hXULDocument_overlayFragments = {};
// Public methods
@@ -26,8 +25,7 @@ cXULDocument.prototype.loadOverlay = function(sUrl, fObserver) {
"url": sUrl,
"async": true,
"dataType": "xml",
- "success": function(oResponse)
- {
+ "success": function(oResponse) {
//oOverlay = ample.importNode(oResponse.documentElement, true);
oOverlay = oResponse.documentElement; //We can't import the overlay document
//because we still need to differentiate
@@ -42,14 +40,12 @@ cXULDocument.prototype.loadOverlay = function(sUrl, fObserver) {
});
};
-cXULDocument.prototype.applyOverlay = function(oOverlayRoot)
-{
+cXULDocument.prototype.applyOverlay = function(oOverlayRoot) {
var oDocument = this;
fXULDocument_applyOverlays(oDocument.documentElement, oOverlayRoot);
};
-function fXULDocument_applyOverlays(oAmpleNode, oOverlayNode)
-{
+function fXULDocument_applyOverlays(oAmpleNode, oOverlayNode) {
//For each child of the overlay node, if:
// - it does have an ID and:
// -- that ID matches an existing node in the ample document, then if
@@ -69,24 +65,19 @@ function fXULDocument_applyOverlays(oAmpleNode, oOverlayNode)
// --- otherwise, it gets inserted into the ample node passed in by this function
// and the process repeats for all children.
//Action...
- for (var iIndex = 0; iIndex < oOverlayNode.childNodes.length; iIndex++)
- {
- var oChild = oOverlayNode.childNodes.item(iIndex);
+ for (var nIndex = 0; nIndex < oOverlayNode.childNodes.length; nIndex++) {
+ var oChild = oOverlayNode.childNodes.item(nIndex);
if (oChild.nodeType == ample.classes.Node.TEXT_NODE && oChild.nodeValue.trim() == '') continue;
if (oChild.nodeType == ample.classes.Node.COMMENT_NODE) continue;
- if (oChild.nodeType == ample.classes.Node.ELEMENT_NODE)
- {
+ if (oChild.nodeType == ample.classes.Node.ELEMENT_NODE) {
var oNewDocEl = null;
- if (oChild.getAttribute('id'))
- {
+ if (oChild.getAttribute('id')) {
//Our overlay node child has an ID.
var sID = oChild.getAttribute('id');
oNewDocEl = ample.getElementById(sID);
- if (!oNewDocEl)
- {
+ if (!oNewDocEl) {
//Our id doesn't match an existing element, ...
- if (oOverlayNode == oOverlayNode.ownerDocument.documentElement)
- {
+ if (oOverlayNode == oOverlayNode.ownerDocument.documentElement) {
//...and it's a child of the overlay root, so store it for later, and
//skip to the next child.
hXULDocument_overlayFragments[oChild.getAttribute('id')] = oChild;
@@ -100,30 +91,31 @@ function fXULDocument_applyOverlays(oAmpleNode, oOverlayNode)
else {
//Our id does match an existing element
//Check to see if this is a remove instruction...
- if (oChild.getAttribute('removeelement') && oChild.getAttribute('removeelement') == 'true') {
- //Remove it, and all children, and skip to the next child.
- oNewDocEl.parentNode.removeChild(oNewDocEl);
- continue;
- }
- //Otherwise, just allow it to merge.
- }
- }
- else {
- //Our overlay node child doesn't have an ID.
- if (oOverlayNode == oOverlayNode.ownerDocument.documentElement)
- {
- //...and it's a child of the overlay root, so insert it into the root.
- oNewDocEl = fXULDocument_importAndAdd(oAmpleNode.ownerDocument.documentElement,oChild);
- } else {
- //...and it's not a child of root, so add it to the current node.
- oNewDocEl = fXULDocument_importAndAdd(oAmpleNode,oChild); //We don't have an id, so insert.
- }
- }
- fXULDocument_mergeAttributes(oNewDocEl,oChild);
- fXULDocument_applyOverlays(oNewDocEl,oChild);
- } else
- alert('Non-XUL element in overlay.'+oChild); //We have a non-XUL element, alert.
-}
+ if (oChild.getAttribute('removeelement') && oChild.getAttribute('removeelement') == 'true') {
+ //Remove it, and all children, and skip to the next child.
+ oNewDocEl.parentNode.removeChild(oNewDocEl);
+ continue;
+ }
+ //Otherwise, just allow it to merge.
+ }
+ }
+ else { //(!oChild.getAttribute('id')
+ //Our overlay node child doesn't have an ID.
+ if (oOverlayNode == oOverlayNode.ownerDocument.documentElement) {
+ //...and it's a child of the overlay root, so insert it into the root.
+ oNewDocEl = fXULDocument_importAndAdd(oAmpleNode.ownerDocument.documentElement,oChild);
+ }
+ else {
+ //...and it's not a child of root, so add it to the current node.
+ oNewDocEl = fXULDocument_importAndAdd(oAmpleNode,oChild); //We don't have an id, so insert.
+ }
+ }
+ fXULDocument_mergeAttributes(oNewDocEl,oChild);
+ fXULDocument_applyOverlays(oNewDocEl,oChild);
+ }
+ else
+ alert('Non-XUL element in overlay.'+oChild); //We have a non-XUL element, alert.
+ }
};
function fXULDocument_importAndAdd(oParent,oNodeToAdd) {
@@ -135,8 +127,8 @@ function fXULDocument_importAndAdd(oParent,oNodeToAdd) {
}
if (oNodeToAdd.getAttribute('insertafter')) {
var aInsertAfter = oNodeToAdd.getAttribute('insertafter').split(',');
- for (var iIndex = 0; iIndex < aInsertAfter.length; iIndex++) {
- oInsertAfterEl = ample.query("#"+aInsertAfter[iIndex].trim());
+ for (var nIndex = 0; nIndex < aInsertAfter.length; nIndex++) {
+ oInsertAfterEl = ample.query("#"+aInsertAfter[nIndex].trim());
if (oInsertAfterEl.size() > 0) {
oInsertAfterEl.after(oNewNode);
return oNewNode;
@@ -145,8 +137,8 @@ function fXULDocument_importAndAdd(oParent,oNodeToAdd) {
}
if (oNodeToAdd.getAttribute('insertbefore')) {
var aInsertBefore = oNodeToAdd.getAttribute('insertbefore').split(',');
- for (var iIndex = 0; iIndex < aInsertBefore.length; iIndex++) {
- oInsertBeforeEl = ample.query("#"+aInsertBefore[iIndex].trim());
+ for (var nIndex = 0; nIndex < aInsertBefore.length; nIndex++) {
+ oInsertBeforeEl = ample.query("#"+aInsertBefore[nIndex].trim());
if (oInsertBeforeEl.size() > 0) {
oInsertBeforeEl.before(oNewNode);
return oNewNode;
@@ -168,16 +160,16 @@ function fXULDocument_importAndAdd(oParent,oNodeToAdd) {
function fXULDocument_mergeAttributes(oAmpleNode,oOverlayNode) {
if (oOverlayNode.attributes) {
- for (var iCounter = 0; iCounter < oOverlayNode.attributes.length; iCounter++) {
- var oAttr = oOverlayNode.attributes.item(iCounter);
+ for (var nCounter = 0; nCounter < oOverlayNode.attributes.length; nCounter++) {
+ var oAttr = oOverlayNode.attributes.item(nCounter);
if (['insertbefore','insertafter','position'].indexOf(oAttr.name) < 0)
oAmpleNode.setAttribute(oAttr.name,oAttr.value);
}
return;
}
//else
- for (var iCounter = 0; iCounter < oOverlayNode.attributes.length; iCounter++) {
- var oAttr = oOverlayNode.attributes.item(iCounter);
+ for (var nCounter = 0; nCounter < oOverlayNode.attributes.length; nCounter++) {
+ var oAttr = oOverlayNode.attributes.item(nCounter);
if (!(oAttr.value instanceof Function)
&& !(oAttr.value instanceof Object)
&& ['insertbefore','insertafter','position'].indexOf(oAttr.name) < 0
@@ -188,22 +180,6 @@ function fXULDocument_mergeAttributes(oAmpleNode,oOverlayNode) {
}
/*
-function fXULDocument_applyOverlaysRecurse(oOverlayEl,oDocEl) {
- //Action...
- for (var iIndex = 0; iIndex < oOverlayEl.childNodes.length; iIndex++) {
- var oChild = oOverlayEl.childNodes.item(iIndex);
- if (oChild.getAttribute('id')) {
- //We have an id
- var oNewDocEl = ample.query(oChild.getAttribute('id'),oDocEl);
- if (oNewDocEl) fXULDocument_applyOverlaysRecurse(oChild,oNewDocEl); //Our id matches an existing element.
- else fXULDocument_importAndAdd(oChild,oDocEl); //Our id doesn't insert it at the current location with the id.
- }
- else fXULDocument_importAndAdd(oChild,oDocEl); //We don't have an id, so insert.
- }
-}
-*/
-
-/*
cXULDocument.prototype.addBroadcastListenerFor = function(oBroadcaster, oObserver, sAttr) {
};

0 comments on commit c422e61

Please sign in to comment.