1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
var HIDDEN="hidden";
var LEVEL = "level";
var PLUS_SRC="dom-images/butplus.gif";
var MIN_SRC="dom-images/butmin.gif";
var newRoot;
var maxColumns=1;
function loadDomViewer() {
// See if the rootDocument variable has been set on this window.
var rootDocument = window.rootDocument;
// If not look to the opener for an explicity rootDocument variable, otherwise, use the opener document
if (!rootDocument && window.opener) {
rootDocument = window.opener.rootDocument || window.opener.document;
}
if (rootDocument) {
document.body.innerHTML = displayDOM(rootDocument);
}
else {
document.body.innerHTML = "<b>Must specify rootDocument for window. This can be done by setting the rootDocument variable on this window, or on the opener window for a popup window.</b>";
}
}
function displayDOM(root){
var str = "";
str+="<table>";
str += treeTraversal(root,0);
// to make table columns work well.
str += "<tr>";
for (var i=0; i < maxColumns; i++) {
str+= "<td> </td>";
}
str += "</tr>";
str += "</table>";
return str;
}
function checkForChildren(element){
if(!element.hasChildNodes())
return false;
var nodes = element.childNodes;
var size = nodes.length;
var count=0;
for(var i=0; i< size; i++){
var node = nodes.item(i);
//if(node.toString()=="[object Text]"){
//this is equalent to the above
//but will work with more browsers
if(node.nodeType!=1){
count++;
}
}
if(count == size)
return false;
else
return true;
}
function treeTraversal(root, level){
var str = "";
var nodes= null;
var size = null;
//it is supposed to show the last node,
//but the last node is always nodeText type
//and we don't show it
if(!root.hasChildNodes())
return "";//displayNode(root,level,false);
nodes = root.childNodes;
size = nodes.length;
for(var i=0; i< size; i++){
var element = nodes.item(i);
//if the node is textNode, don't display
if(element.nodeType==1){
str+= displayNode(element,level,checkForChildren(element));
str+=treeTraversal(element, level+1);
}
}
return str;
}
function displayNode(element, level, isLink){
nodeContent = getNodeContent(element);
columns = Math.round((nodeContent.length / 12) + 0.5);
if (columns + level > maxColumns) {
maxColumns = columns + level;
}
var str ="<tr class='"+LEVEL+level+"'>";
for (var i=0; i < level; i++)
str+= "<td> </td>";
str+="<td colspan='"+ columns +"' class='box"+" boxlevel"+level+"' >";
if(isLink){
str+='<a onclick="hide(this);return false;" href="javascript:void();">';
str+='<img src="'+MIN_SRC+'" />';
}
str += nodeContent;
if(isLink)
str+="</a></td></tr>";
return str;
}
function getNodeContent(element) {
str = "";
id ="";
if (element.id != null && element.id != "") {
id = " ID(" + element.id +")";
}
name ="";
if (element.name != null && element.name != "") {
name = " NAME(" + element.name + ")";
}
value ="";
if (element.value != null && element.value != "") {
value = " VALUE(" + element.value + ")";
}
href ="";
if (element.href != null && element.href != "") {
href = " HREF(" + element.href + ")";
}
text ="";
if (element.text != null && element.text != "" && element.text != "undefined") {
text = " #TEXT(" + trim(element.text) +")";
}
str+=" <b>"+ element.nodeName + id + name + value + href + text + "</b>";
return str;
}
function trim(val) {
val2 = val.substring(0,20) + " ";
var spaceChr = String.fromCharCode(32);
var length = val2.length;
var retVal = "";
var ix = length -1;
while(ix > -1){
if(val2.charAt(ix) == spaceChr) {
} else {
retVal = val2.substring(0, ix +1);
break;
}
ix = ix-1;
}
if (val.length > 20) {
retVal += "...";
}
return retVal;
}
function hide(hlink){
var isHidden = false;
var image = hlink.firstChild;
if(image.src.toString().indexOf(MIN_SRC)!=-1){
image.src=PLUS_SRC;
isHidden=true;
}else{
image.src=MIN_SRC;
}
var rowObj= hlink.parentNode.parentNode;
var rowLevel = parseInt(rowObj.className.substring(LEVEL.length));
var sibling = rowObj.nextSibling;
var siblingLevel = sibling.className.substring(LEVEL.length);
if(siblingLevel.indexOf(HIDDEN)!=-1){
siblingLevel = siblingLevel.substring(0,siblingLevel.length - HIDDEN.length-1);
}
siblingLevel=parseInt(siblingLevel);
while(sibling!=null && rowLevel<siblingLevel){
if(isHidden){
sibling.className += " "+ HIDDEN;
}else if(!isHidden && sibling.className.indexOf(HIDDEN)!=-1){
var str = sibling.className;
sibling.className=str.substring(0, str.length - HIDDEN.length-1);
}
sibling = sibling.nextSibling;
siblingLevel = parseInt(sibling.className.substring(LEVEL.length));
}
}
function LOG(message) {
window.opener.LOG.warn(message);
}
|