git-svn-id: svn://euphorik.ch/pompage@45 02bbb61a-6d21-0410-aba0-cb053bdfd66a
[pompage.git] / doc / webdeveloper / information.js
1 // Adds colors from the specified property of the element to the given list
2 function webdeveloper_addColor(element, property, colorList)
3 {
4 // If the element, property and color list are set
5 if(element && property && colorList)
6 {
7 var computedStyle = element.ownerDocument.defaultView.getComputedStyle(element, null);
8 var color = computedStyle.getPropertyCSSValue(property);
9
10 // If the color is set and it is a color
11 if(color && color.primitiveType == CSSPrimitiveValue.CSS_RGBCOLOR)
12 {
13 color = color.getRGBColorValue();
14
15 colorList.push("#" + webdeveloper_formatColor(color.red.getFloatValue(CSSPrimitiveValue.CSS_NUMBER)) + webdeveloper_formatColor(color.green.getFloatValue(CSSPrimitiveValue.CSS_NUMBER)) + webdeveloper_formatColor(color.blue.getFloatValue(CSSPrimitiveValue.CSS_NUMBER)));
16 }
17 }
18 }
19
20 // Displays all abbreviations
21 function webdeveloper_displayAbbreviations(element)
22 {
23 webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/display_abbreviations.css", "webdeveloper-display-abbreviations");
24 webdeveloper_toggleFeatureTooltipStyles(element, "webdeveloper-display-abbreviations-tooltips", "*:before");
25 }
26
27 // Displays all access keys
28 function webdeveloper_displayAccessKeys(element)
29 {
30 var accessKeyElement = null;
31 var accessKeyElementList = null;
32 var accessKeyElementsLength = null;
33 var display = element.getAttribute("checked");
34 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
35 var documentLength = documentList.length;
36 var pageDocument = null;
37 var spanElement = null;
38 var text = null;
39
40 // Loop through the documents
41 for(var i = 0; i < documentLength; i++)
42 {
43 pageDocument = documentList[i];
44
45 // Need to do this to stop the feature running twice
46 webdeveloper_removeAllElementsByXPath(pageDocument, "//span[@class='webdeveloper-display-access-keys']");
47
48 // If displaying
49 if(display)
50 {
51 accessKeyElementList = webdeveloper_evaluateXPath(pageDocument, "//*[@accesskey]");
52 accessKeyElementsLength = accessKeyElementList.length;
53
54 // Loop through all the access key elements
55 for(var j = 0; j < accessKeyElementsLength; j++)
56 {
57 accessKeyElement = accessKeyElementList[j];
58 spanElement = pageDocument.createElement("span");
59 text = "Accesskey=" + accessKeyElement.getAttribute("accesskey");
60
61 spanElement.setAttribute("class", "webdeveloper-display-access-keys");
62 spanElement.setAttribute("title", text);
63 spanElement.appendChild(pageDocument.createTextNode(text));
64 accessKeyElement.parentNode.insertBefore(spanElement, accessKeyElement);
65 }
66 }
67 }
68
69 webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/imports/tooltips.css", "webdeveloper-display-access-keys");
70 webdeveloper_toggleFeatureTooltipStyles(element, "webdeveloper-display-access-keys-tooltips", "span.webdeveloper-display-access-keys");
71 }
72
73 // Displays all anchors
74 function webdeveloper_displayAnchors(element)
75 {
76 var anchorElement = null;
77 var anchorElementList = null;
78 var anchorElementsLength = null;
79 var anchorText = null;
80 var display = element.getAttribute("checked");
81 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
82 var documentLength = documentList.length;
83 var linkElement = null;
84 var pageDocument = null;
85 var spanElement = null;
86
87 // Loop through the documents
88 for(var i = 0; i < documentLength; i++)
89 {
90 pageDocument = documentList[i];
91
92 // Need to do this to stop the feature running twice
93 webdeveloper_removeAllElementsByXPath(pageDocument, "//span[@class='webdeveloper-display-anchors']");
94
95 // If displaying
96 if(display)
97 {
98 anchorElementList = webdeveloper_evaluateXPath(pageDocument, "//*[@id] | //a[@name]");
99 anchorElementsLength = anchorElementList.length;
100
101 // Loop through all the anchor elements
102 for(var j = 0; j < anchorElementsLength; j++)
103 {
104 anchorElement = anchorElementList[j];
105 linkElement = pageDocument.createElement("a");
106 spanElement = pageDocument.createElement("span");
107
108 // If the anchor element has an id attribute
109 if(anchorElement.hasAttribute("id"))
110 {
111 anchorText = "#" + anchorElement.getAttribute("id");
112 }
113 else if(anchorElement.hasAttribute("name"))
114 {
115 anchorText = "#" + anchorElement.getAttribute("name");
116 }
117
118 linkElement.setAttribute("href", anchorText);
119 linkElement.setAttribute("title", anchorText);
120 linkElement.appendChild(pageDocument.createTextNode(anchorText));
121
122 spanElement.setAttribute("class", "webdeveloper-display-anchors");
123 spanElement.setAttribute("title", anchorText);
124 spanElement.appendChild(linkElement);
125
126
127 // Try to insert the anchor element
128 try
129 {
130 anchorElement.parentNode.insertBefore(spanElement, anchorElement);
131 }
132 catch(exception)
133 {
134 // Do nothing
135 }
136 }
137 }
138 }
139
140 webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/display_anchors.css", "webdeveloper-display-anchors");
141 webdeveloper_toggleFeatureTooltipStyles(element, "webdeveloper-display-anchors-tooltips", "span.webdeveloper-display-anchors, span.webdeveloper-display-anchors a");
142 }
143
144 // Displays all block sizes
145 function webdeveloper_displayBlockSize(element)
146 {
147 var blockSizeElement = null;
148 var blockSizeElementList = null;
149 var blockSizeElementsLength = null;
150 var display = element.getAttribute("checked");
151 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
152 var documentLength = documentList.length;
153 var height = null;
154 var left = null;
155 var pageDocument = null;
156 var spanElement = null;
157 var text = null;
158 var top = null;
159 var width = null;
160
161 // Loop through the documents
162 for(var i = 0; i < documentLength; i++)
163 {
164 pageDocument = documentList[i];
165
166 // Need to do this to stop the feature running twice
167 webdeveloper_removeAllElementsByXPath(pageDocument, "//span[@class='webdeveloper-display-block-size']");
168
169 // If displaying
170 if(display)
171 {
172 blockSizeElementList = webdeveloper_evaluateXPath(pageDocument, "//div | //form | //table");
173 blockSizeElementsLength = blockSizeElementList.length;
174
175 // Loop through the block size elements
176 for(var j = 0; j < blockSizeElementsLength; j++)
177 {
178 blockSizeElement = blockSizeElementList[j];
179 height = blockSizeElement.offsetHeight;
180 left = blockSizeElement.offsetLeft;
181 spanElement = pageDocument.createElement("span");
182 top = blockSizeElement.offsetTop;
183 width = blockSizeElement.offsetWidth;
184 text = webdeveloper_getElementDescription(blockSizeElement) + " " + width + "x" + height;
185
186 spanElement.style.left = left + "px";
187 spanElement.style.position = "absolute";
188 spanElement.style.top = top + "px";
189
190 spanElement.setAttribute("class", "webdeveloper-display-block-size");
191 spanElement.setAttribute("title", text);
192 spanElement.appendChild(pageDocument.createTextNode(text));
193
194 webdeveloper_insertAsFirstChild(blockSizeElement, spanElement);
195 }
196 }
197 }
198
199 webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/display_block_size.css", "webdeveloper-display-block-size");
200 webdeveloper_toggleFeatureTooltipStyles(element, "webdeveloper-display-block-size-tooltips", "span.webdeveloper-display-block-size");
201 }
202
203 // Displays the order of the divs on the page
204 function webdeveloper_displayDivOrder(element)
205 {
206 var display = element.getAttribute("checked");
207 var divElement = null;
208 var divElementList = null;
209 var divElementsLength = null;
210 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
211 var documentLength = documentList.length;
212 var pageDocument = null;
213 var spanElement = null;
214 var text = null;
215
216 // Loop through the documents
217 for(var i = 0; i < documentLength; i++)
218 {
219 pageDocument = documentList[i];
220
221 // Need to do this to stop the feature running twice
222 webdeveloper_removeAllElementsByXPath(pageDocument, "//span[@class='webdeveloper-display-div-order']");
223
224 // If displaying
225 if(display)
226 {
227 divElementList = pageDocument.getElementsByTagName("div");
228 divElementsLength = divElementList.length;
229
230 // Loop through the div elements
231 for(var j = 0; j < divElementsLength; j++)
232 {
233 divElement = divElementList[j];
234 spanElement = pageDocument.createElement("span");
235 text = webdeveloper_getElementDescription(divElement) + " " + (j + 1);
236
237 spanElement.setAttribute("class", "webdeveloper-display-div-order");
238 spanElement.setAttribute("title", text);
239 spanElement.appendChild(pageDocument.createTextNode(text));
240
241 webdeveloper_insertAsFirstChild(divElement, spanElement);
242 }
243 }
244 }
245
246 webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/display_div_order.css", "webdeveloper-display-div-order");
247 webdeveloper_toggleFeatureTooltipStyles(element, "webdeveloper-display-div-order-tooltips", "span.webdeveloper-display-div-order");
248 }
249
250 // Displays id and class details for the page
251 function webdeveloper_displayIdClassDetails(element)
252 {
253 var display = element.getAttribute("checked");
254 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
255 var documentLength = documentList.length;
256 var idClassElement = null;
257 var idClassElementList = null;
258 var idClassElementsLength = null;
259 var idClassElementText = null;
260 var pageDocument = null;
261 var spanElement = null;
262
263 // Loop through the documents
264 for(var i = 0; i < documentLength; i++)
265 {
266 pageDocument = documentList[i];
267
268 // Need to do this to stop the feature running twice
269 webdeveloper_removeAllElementsByXPath(pageDocument, "//span[@class='webdeveloper-display-id-class-details']");
270
271 // If displaying
272 if(display)
273 {
274 idClassElementList = webdeveloper_evaluateXPath(pageDocument, "//*[@class] | //*[@id]");
275 idClassElementsLength = idClassElementList.length;
276
277 // Loop through all the id class elements
278 for(var j = 0; j < idClassElementsLength; j++)
279 {
280 idClassElement = idClassElementList[j];
281
282 // If the id class element is a Web Developer element
283 if((idClassElement.hasAttribute("class") && idClassElement.getAttribute("class").indexOf("webdeveloper-")) || (idClassElement.hasAttribute("id") && idClassElement.getAttribute("id").indexOf("webdeveloper-")))
284 {
285 idClassElementText = "";
286 spanElement = pageDocument.createElement("span");
287
288 // If the id class element has an id attribute
289 if(idClassElement.hasAttribute("id"))
290 {
291 idClassElementText += " #" + idClassElement.getAttribute("id");
292 }
293
294 // If the id class element has a class attribute
295 if(idClassElement.hasAttribute("class"))
296 {
297 idClassElementText += " ." + idClassElement.getAttribute("class");
298 }
299
300 spanElement.setAttribute("class", "webdeveloper-display-id-class-details");
301 spanElement.setAttribute("title", idClassElementText);
302 spanElement.appendChild(pageDocument.createTextNode(idClassElementText));
303
304 // Try to insert the id class element
305 try
306 {
307 idClassElement.parentNode.insertBefore(spanElement, idClassElement);
308 }
309 catch(exception)
310 {
311 // Do nothing
312 }
313 }
314 }
315 }
316 }
317
318 webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/imports/tooltips.css", "webdeveloper-display-id-class-details");
319 webdeveloper_toggleFeatureTooltipStyles(element, "webdeveloper-display-id-class-details-tooltips", "span.webdeveloper-display-id-class-details");
320 }
321
322 // Displays all link details
323 function webdeveloper_displayLinkDetails(element)
324 {
325 webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/display_link_details.css", "webdeveloper-display-link-details");
326 webdeveloper_toggleFeatureTooltipStyles(element, "webdeveloper-display-link-details-tooltips", "*:before");
327 }
328
329 // Displays object information
330 function webdeveloper_displayObjectInformation(element)
331 {
332 var checked = element.getAttribute("checked");
333 var divElement = null;
334 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
335 var documentLength = documentList.length;
336 var objectAttributes = null;
337 var objectElement = null;
338 var objectElementList = null;
339 var objectElementsLength = null;
340 var pageDocument = null;
341 var paramAttributes = null;
342 var paramElement = null;
343 var paramElementList = null;
344 var paramElementsLength = null;
345 var pElement = null;
346 var treeWalker = null;
347
348 // Loop through the documents
349 for(var i = 0; i < documentLength; i++)
350 {
351 pageDocument = documentList[i];
352
353 // Need to do this to stop the feature running twice
354 webdeveloper_removeAllElementsByXPath(pageDocument, "//div[@class='webdeveloper-display-object-information']");
355
356 // If the element is checked
357 if(checked)
358 {
359 objectElementList = pageDocument.getElementsByTagName("object");
360 objectElementsLength = objectElementList.length;
361
362 // Loop through all the object elements
363 for(var j = 0; j < objectElementsLength; j++)
364 {
365 divElement = pageDocument.createElement("div");
366 objectAttributes = "";
367 objectElement = objectElementList[j];
368 paramElementList = objectElement.getElementsByTagName("param");
369 paramElementsLength = paramElementList.length;
370 pElement = pageDocument.createElement("p");
371
372 // If the object has an width attribute
373 if(objectElement.hasAttribute("width"))
374 {
375 objectAttributes += ' width="' + objectElement.getAttribute("width") + '"';
376 }
377
378 // If the object has an height attribute
379 if(objectElement.hasAttribute("height"))
380 {
381 objectAttributes += ' height="' + objectElement.getAttribute("height") + '"';
382 }
383
384 // If the object has an archive attribute
385 if(objectElement.hasAttribute("archive"))
386 {
387 objectAttributes += ' archive="' + objectElement.getAttribute("archive") + '"';
388 }
389
390 // If the object has an classid attribute
391 if(objectElement.hasAttribute("classid"))
392 {
393 objectAttributes += ' classid="' + objectElement.getAttribute("classid") + '"';
394 }
395
396 // If the object has an codebase attribute
397 if(objectElement.hasAttribute("codebase"))
398 {
399 objectAttributes += ' codebase="' + objectElement.getAttribute("codebase") + '"';
400 }
401
402 // If the object has an codetype attribute
403 if(objectElement.hasAttribute("codetype"))
404 {
405 objectAttributes += ' codetype="' + objectElement.getAttribute("codetype") + '"';
406 }
407
408 // If the object has an data attribute
409 if(objectElement.hasAttribute("data"))
410 {
411 objectAttributes += ' data="' + objectElement.getAttribute("data") + '"';
412 }
413
414 // If the object has an standby attribute
415 if(objectElement.hasAttribute("standby"))
416 {
417 objectAttributes += ' standby="' + objectElement.getAttribute("standby") + '"';
418 }
419
420 // If the object has an type attribute
421 if(objectElement.hasAttribute("type"))
422 {
423 objectAttributes += ' type="' + objectElement.getAttribute("type") + '"';
424 }
425
426 pElement.appendChild(document.createTextNode("<object" + objectAttributes + ">"));
427 divElement.appendChild(pElement);
428
429 // Loop through all the param elements
430 for(var k = 0; k < paramElementsLength; k++)
431 {
432 paramAttributes = "";
433 paramElement = paramElementList[k];
434 pElement = pageDocument.createElement("p");
435
436 // If the param has a name attribute
437 if(paramElement.hasAttribute("name"))
438 {
439 paramAttributes += ' name="' + paramElement.getAttribute("name") + '"';
440 }
441
442 // If the param has a value attribute
443 if(paramElement.hasAttribute("value"))
444 {
445 paramAttributes += ' value="' + paramElement.getAttribute("value") + '"';
446 }
447
448 pElement.appendChild(document.createTextNode("<param" + paramAttributes + " />"));
449 pElement.setAttribute("class", "param");
450 divElement.appendChild(pElement);
451 }
452
453 pElement = pageDocument.createElement("p");
454 pElement.appendChild(document.createTextNode("</object>"));
455 divElement.appendChild(pElement);
456
457 divElement.setAttribute("class", "webdeveloper-display-object-information");
458 objectElement.parentNode.insertBefore(divElement, objectElement);
459 }
460 }
461 }
462
463 webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/display_object_information.css", "webdeveloper-display-object-information");
464 webdeveloper_toggleFeatureTooltipStyles(element, "webdeveloper-display-object-information-tooltips", "div.webdeveloper-display-object-information");
465 }
466
467 // Displays the stack level of all elements on the page
468 function webdeveloper_displayStackLevels(element)
469 {
470 var display = element.getAttribute("checked");
471 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
472 var documentLength = documentList.length;
473 var pageDocument = null;
474 var pageElement = null;
475 var spanElement = null;
476 var text = null;
477 var treeWalker = null;
478
479 // Loop through the documents
480 for(var i = 0; i < documentLength; i++)
481 {
482 pageDocument = documentList[i];
483
484 // Need to do this to stop the feature running twice
485 webdeveloper_removeAllElementsByXPath(pageDocument, "//span[@class='webdeveloper-display-stack-levels']");
486
487 // If displaying
488 if(display)
489 {
490 treeWalker = pageDocument.createTreeWalker(pageDocument, NodeFilter.SHOW_ELEMENT, webdeveloper_stackLevelFilter, false);
491
492 // While the tree walker has more nodes
493 while((pageElement = treeWalker.nextNode()) != null)
494 {
495 spanElement = pageDocument.createElement("span");
496 text = webdeveloper_getElementDescription(pageElement) + " Z-index=" + pageElement.ownerDocument.defaultView.getComputedStyle(pageElement, null).getPropertyCSSValue("z-index").cssText;
497
498 spanElement.setAttribute("class", "webdeveloper-display-stack-levels");
499 spanElement.setAttribute("title", text);
500 spanElement.appendChild(pageDocument.createTextNode(text));
501
502 webdeveloper_insertAsFirstChild(pageElement, spanElement);
503 }
504 }
505 }
506
507 webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/imports/tooltips.css", "webdeveloper-display-stack-levels");
508 webdeveloper_toggleFeatureTooltipStyles(element, "webdeveloper-display-stack-levels-tooltips", "span.webdeveloper-display-stack-levels");
509 }
510
511 // Displays all tab indices
512 function webdeveloper_displayTabIndex(element)
513 {
514 var checked = element.getAttribute("checked");
515 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
516 var documentLength = documentList.length;
517 var pageDocument = null;
518 var spanElement = null;
519 var tabIndexElement = null;
520 var tabIndexElementList = null;
521 var tabIndexElementsLength = null;
522 var text = null;
523
524 // Loop through the documents
525 for(var i = 0; i < documentLength; i++)
526 {
527 pageDocument = documentList[i];
528
529 // Need to do this to stop the feature running twice
530 webdeveloper_removeAllElementsByXPath(pageDocument, "//span[@class='webdeveloper-display-tab-index']");
531
532 // If the element is checked
533 if(checked)
534 {
535 tabIndexElementList = webdeveloper_evaluateXPath(pageDocument, "//*[@tabindex]");
536 tabIndexElementsLength = tabIndexElementList.length;
537
538 // Loop through all the tab index elements
539 for(var j = 0; j < tabIndexElementsLength; j++)
540 {
541 spanElement = pageDocument.createElement("span");
542 tabIndexElement = tabIndexElementList[j];
543 text = "Tabindex=" + tabIndexElement.getAttribute("tabindex");
544
545 spanElement.setAttribute("class", "webdeveloper-display-tab-index");
546 spanElement.setAttribute("title", text);
547 spanElement.appendChild(document.createTextNode(text));
548 tabIndexElement.parentNode.insertBefore(spanElement, tabIndexElement);
549 }
550 }
551 }
552
553 webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/imports/tooltips.css", "webdeveloper-display-tab-index");
554 webdeveloper_toggleFeatureTooltipStyles(element, "webdeveloper-display-tab-index-tooltips", "span.webdeveloper-display-tab-index");
555 }
556
557 // Displays the depth of all tables
558 function webdeveloper_displayTableDepth(element)
559 {
560 var checked = element.getAttribute("checked");
561 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
562 var documentLength = documentList.length;
563 var pageDocument = null;
564 var spanElement = null;
565 var stringBundle = document.getElementById("webdeveloper-string-bundle");
566 var tableElement = null;
567 var tableElementList = null;
568 var tableElementsLength = null;
569 var text = null;
570
571 // Loop through the documents
572 for(var i = 0; i < documentLength; i++)
573 {
574 pageDocument = documentList[i];
575
576 // Need to do this to stop the feature running twice
577 webdeveloper_removeAllElementsByXPath(pageDocument, "//span[@class='webdeveloper-display-table-depth']");
578
579 // If the element is checked
580 if(checked)
581 {
582 tableElementList = pageDocument.getElementsByTagName("table");
583 tableElementsLength = tableElementList.length;
584
585 // Loop through all the table elements
586 for(var j = 0; j < tableElementsLength; j++)
587 {
588 spanElement = pageDocument.createElement("span");
589 tableElement = tableElementList[j];
590 text = stringBundle.getString("webdeveloper_depth") + "=" + webdeveloper_getTableDepth(tableElement);
591
592 spanElement.setAttribute("class", "webdeveloper-display-table-depth");
593 spanElement.setAttribute("title", text);
594 spanElement.appendChild(document.createTextNode(text));
595 tableElement.parentNode.insertBefore(spanElement, tableElement);
596 }
597 }
598 }
599
600 webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/imports/tooltips.css", "webdeveloper-display-table-depth");
601 webdeveloper_toggleFeatureTooltipStyles(element, "webdeveloper-display-table-depth-tooltips", "span.webdeveloper-display-table-depth");
602 }
603
604 // Displays table information
605 function webdeveloper_displayTableInformation(element)
606 {
607 var checked = element.getAttribute("checked");
608 var divElement = null;
609 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
610 var documentLength = documentList.length;
611 var pageDocument = null;
612 var tableCellElementList = null;
613 var tableCellElementsLength = null;
614 var tableElement = null;
615 var tableElementList = null;
616 var tableElementsLength = null;
617
618 // Loop through the documents
619 for(var i = 0; i < documentLength; i++)
620 {
621 pageDocument = documentList[i];
622
623 // Need to do this to stop the feature running twice
624 webdeveloper_removeAllElementsByXPath(pageDocument, "//div[@class='webdeveloper-display-table-information']");
625
626 // If the element is checked
627 if(checked)
628 {
629 tableElementList = pageDocument.getElementsByTagName("table");
630 tableElementsLength = tableElementList.length;
631
632 // Loop through all the table elements
633 for(var j = 0; j < tableElementsLength; j++)
634 {
635 tableElement = tableElementList[j];
636 tableCellElementList = tableElement.getElementsByTagName("th");
637 tableCellElementsLength = tableCellElementList.length;
638
639 // If the table has a summary attribute
640 if(tableElement.hasAttribute("summary"))
641 {
642 divElement = pageDocument.createElement("div");
643
644 divElement.setAttribute("class", "webdeveloper-display-table-information");
645 divElement.appendChild(pageDocument.createTextNode("Summary=" + tableElement.getAttribute("summary")));
646 tableElement.parentNode.insertBefore(divElement, tableElement);
647 }
648
649 // Loop through the cell elements
650 for(var k = 0; k < tableCellElementsLength; k++)
651 {
652 webdeveloper_outputTableCellInformation(tableCellElementList[k], pageDocument);
653 }
654
655 tableCellElementList = tableElement.getElementsByTagName("td");
656 tableCellElementsLength = tableCellElementList.length;
657
658 // Loop through the cell elements
659 for(k = 0; k < tableCellElementsLength; k++)
660 {
661 webdeveloper_outputTableCellInformation(tableCellElementList[k], pageDocument);
662 }
663 }
664 }
665 }
666
667 webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/display_table_information.css", "webdeveloper-display-table-information");
668 webdeveloper_toggleFeatureTooltipStyles(element, "webdeveloper-display-table-information-tooltips", "div.webdeveloper-display-table-information");
669 }
670
671 // Displays all title attributes
672 function webdeveloper_displayTitleAttributes(element)
673 {
674 var checked = element.getAttribute("checked");
675 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
676 var documentLength = documentList.length;
677 var pageDocument = null;
678 var spanElement = null;
679 var text = null;
680 var titleAttributeElement = null;
681 var titleAttributeElementList = null;
682 var titleAttributeElementsLength = null;
683
684 // Loop through the documents
685 for(var i = 0; i < documentLength; i++)
686 {
687 pageDocument = documentList[i];
688
689 // Need to do this to stop the feature running twice
690 webdeveloper_removeAllElementsByXPath(pageDocument, "//span[@class='webdeveloper-display-title-attributes']");
691
692 // If the element is checked
693 if(checked)
694 {
695 titleAttributeElementList = webdeveloper_evaluateXPath(pageDocument, "//*[@title]");
696 titleAttributeElementsLength = titleAttributeElementList.length;
697
698 // Loop through all the title attribute elements
699 for(var j = 0; j < titleAttributeElementsLength; j++)
700 {
701 spanElement = pageDocument.createElement("span");
702 titleAttributeElement = titleAttributeElementList[j];
703 text = "Title=" + titleAttributeElement.getAttribute("title");
704
705 spanElement.setAttribute("class", "webdeveloper-display-title-attributes");
706 spanElement.setAttribute("title", text);
707 spanElement.appendChild(pageDocument.createTextNode(text));
708 titleAttributeElement.parentNode.insertBefore(spanElement, titleAttributeElement);
709 }
710 }
711 }
712
713 webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/imports/tooltips.css", "webdeveloper-display-title-attributes");
714 webdeveloper_toggleFeatureTooltipStyles(element, "webdeveloper-display-title-attributes-tooltips", "span.webdeveloper-display-title-attributes");
715 }
716
717 // Displays the topographic information for all elements
718 function webdeveloper_displayTopographicInformation(element)
719 {
720 webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/display_topographic_information.css", "webdeveloper-display-topographic-information");
721 }
722
723 // Formats a CSS color
724 function webdeveloper_formatColor(color)
725 {
726 var formattedColor = color.toString(16);
727
728 // If the formatted color is less than 2 characters long
729 if(formattedColor.length < 2)
730 {
731 return "0" + formattedColor;
732 }
733 else
734 {
735 return formattedColor;
736 }
737 }
738
739 // Returns the depth of the table
740 function webdeveloper_getTableDepth(table)
741 {
742 var depth = 1;
743
744 // If the table is set
745 if(table)
746 {
747 var ancestorList = webdeveloper_getElementAncestors(table);
748 var ancestorLength = ancestorList.length;
749 var tagName = null;
750
751 // Loop through the ancestors
752 for(var i = 0; i < ancestorLength; i++)
753 {
754 tagName = ancestorList[i].tagName;
755
756 // If the tag name is set and equals table
757 if(tagName && tagName.toLowerCase() == "table")
758 {
759 depth++;
760 }
761 }
762 }
763
764 return depth;
765 }
766
767 // Returns the text from a table heading
768 function webdeveloper_getTableHeadingText(headingNode, headingText)
769 {
770 // If the heading node is set
771 if(headingNode)
772 {
773 var childNode = null;
774 var childNodeList = headingNode.childNodes;
775 var childNodeLength = childNodeList.length;
776 var childNodeType = null;
777
778 // Loop through the child nodes
779 for(var i = 0; i < childNodeLength; i++)
780 {
781 childNode = childNodeList[i];
782 childNodeType = childNode.nodeType;
783
784 // If the child node type is an element and it does not have a webdeveloper-table-information class
785 if(childNodeType == Node.ELEMENT_NODE && (!childNode.hasAttribute("class") || childNode.getAttribute("class") != "webdeveloper-table-information"))
786 {
787 headingText = webdeveloper_getTableHeadingText(childNode, headingText);
788 }
789 else if(childNodeType == Node.TEXT_NODE)
790 {
791 headingText += childNode.nodeValue + " ";
792 }
793 }
794 }
795
796 return headingText.trim();
797 }
798
799 // Outputs the information for a table cell
800 function webdeveloper_outputTableCellInformation(tableCellElement, pageDocument)
801 {
802 // If the table cell element is set
803 if(tableCellElement)
804 {
805 var divElement = null;
806 var pElement = null;
807 var stringBundle = document.getElementById("webdeveloper-string-bundle");
808
809 // If the table cell has a headers attribute
810 if(tableCellElement.hasAttribute("headers"))
811 {
812 var definitionElement = pageDocument.createElement("dd");
813 var headerList = tableCellElement.getAttribute("headers").split(" ");
814 var headersLength = headerList.length;
815
816 // Loop through the headers
817 for(var i = 0; i < headersLength; i++)
818 {
819 pElement = pageDocument.createElement("p");
820 pElement.appendChild(pageDocument.createTextNode(webdeveloper_getTableHeadingText(pageDocument.getElementById(headerList[i]), "")));
821 definitionElement.appendChild(pElement);
822 }
823
824 // If the definition element has child nodes
825 if(definitionElement.childNodes.length > 0)
826 {
827 var listElement = pageDocument.createElement("dl");
828 var termElement = pageDocument.createElement("dt");
829
830 divElement = pageDocument.createElement("div");
831
832 termElement.appendChild(pageDocument.createTextNode(stringBundle.getString("webdeveloper_headers")));
833 listElement.appendChild(termElement);
834 listElement.appendChild(definitionElement);
835
836 divElement.setAttribute("class", "webdeveloper-table-information");
837 divElement.appendChild(listElement);
838 tableCellElement.appendChild(divElement);
839 }
840 }
841
842 divElement = pageDocument.createElement("div");
843
844 // If the table cell has a scope attribute
845 if(tableCellElement.hasAttribute("scope"))
846 {
847 var scope = tableCellElement.getAttribute("scope");
848
849 pElement = pageDocument.createElement("p");
850
851 // If the scope is col
852 if(scope == "col")
853 {
854 pElement.appendChild(pageDocument.createTextNode(stringBundle.getString("webdeveloper_tableInformationHeadingColumn")));
855 }
856 else if(scope == "colgroup")
857 {
858 pElement.appendChild(pageDocument.createTextNode(stringBundle.getString("webdeveloper_tableInformationHeadingColumnGroup")));
859 }
860 else if(scope == "row")
861 {
862 pElement.appendChild(pageDocument.createTextNode(stringBundle.getString("webdeveloper_tableInformationHeadingRow")));
863 }
864 else if(scope == "rowgroup")
865 {
866 pElement.appendChild(pageDocument.createTextNode(stringBundle.getString("webdeveloper_tableInformationHeadingRowGroup")));
867 }
868
869 divElement.appendChild(pElement);
870 }
871
872 // If the table cell has an abbr attribute
873 if(tableCellElement.hasAttribute("abbr"))
874 {
875 pElement = pageDocument.createElement("p");
876 pElement.appendChild(pageDocument.createTextNode(stringBundle.getString("webdeveloper_abbreviation") + "=" + tableCellElement.getAttribute("abbr")));
877 divElement.appendChild(pElement);
878 }
879
880 // If the table cell has an axis attribute
881 if(tableCellElement.hasAttribute("axis"))
882 {
883 pElement = pageDocument.createElement("p");
884 pElement.appendChild(pageDocument.createTextNode(stringBundle.getString("webdeveloper_axis") + "=" + tableCellElement.getAttribute("axis")));
885 divElement.appendChild(pElement);
886 }
887
888 // If the div element has child nodes
889 if(divElement.childNodes.length > 0)
890 {
891 divElement.setAttribute("class", "webdeveloper-table-information");
892 tableCellElement.appendChild(divElement);
893 }
894 }
895 }
896
897 // Sets the image file sizes for a list of images
898 function webdeveloper_setImageFileSizes(imageList)
899 {
900 var image = null;
901 var imageListLength = imageList.length;
902 var newImageList = new Array();
903
904 // Loop through the images
905 for(var i = 0; i < imageListLength; i++)
906 {
907 image = imageList[i];
908 image.fileSize = webdeveloper_getFileSize(image.src);
909
910 newImageList.push(image);
911 }
912
913 return newImageList;
914 }
915
916 // Sets the script file sizes for a list of scripts
917 function webdeveloper_setScriptFileSizes(scriptList)
918 {
919 var script = null;
920 var scriptListLength = scriptList.length;
921 var newScriptList = new Array();
922
923 // Loop through the images
924 for(var i = 0; i < scriptListLength; i++)
925 {
926 script = scriptList[i];
927 script.fileSize = webdeveloper_getFileSize(script.src);
928 script.uncompressedFileSize = webdeveloper_getUncompressedFileSize(script.src);
929
930 newScriptList.push(script);
931 }
932
933 return newScriptList;
934 }
935
936 // Sets the style sheet file sizes for a list of style sheets
937 function webdeveloper_setStyleSheetFileSizes(styleSheetList)
938 {
939 var styleSheet = null;
940 var styleSheetListLength = styleSheetList.length;
941 var newStyleSheetList = new Array();
942
943 // Loop through the style sheets
944 for(var i = 0; i < styleSheetListLength; i++)
945 {
946 styleSheet = styleSheetList[i];
947 styleSheet.fileSize = webdeveloper_getFileSize(styleSheet.href);
948 styleSheet.uncompressedFileSize = webdeveloper_getUncompressedFileSize(styleSheet.href);
949
950 newStyleSheetList.push(styleSheet);
951 }
952
953 return newStyleSheetList;
954 }
955
956 // Sorts two anchors
957 function webdeveloper_sortAnchors(anchorOne, anchorTwo)
958 {
959 // If both anchors are set
960 if(anchorOne && anchorTwo)
961 {
962 var anchorOneLink = null;
963 var anchorTwoLink = null;
964
965 // If the first anchor has an id attribute
966 if(anchorOne.hasAttribute("id"))
967 {
968 anchorOneLink = anchorOne.getAttribute("id");
969 }
970 else if(anchorOne.hasAttribute("name"))
971 {
972 anchorOneLink = anchorOne.getAttribute("name");
973 }
974
975 // If the second anchor has an id attribute
976 if(anchorTwo.hasAttribute("id"))
977 {
978 anchorTwoLink = anchorTwo.getAttribute("id");
979 }
980 else if(anchorTwo.hasAttribute("name"))
981 {
982 anchorTwoLink = anchorTwo.getAttribute("name");
983 }
984
985 // If the anchor links are equal
986 if(anchorOneLink == anchorTwoLink)
987 {
988 return 0;
989 }
990 else if(anchorOneLink < anchorTwoLink)
991 {
992 return -1;
993 }
994 }
995
996 return 1;
997 }
998
999 // Sorts two documents
1000 function webdeveloper_sortDocuments(documentOne, documentTwo)
1001 {
1002 // If both documents are set
1003 if(documentOne && documentTwo)
1004 {
1005 var documentOneURL = documentOne.documentURI;
1006 var documentTwoURL = documentTwo.documentURI;
1007
1008 // If the documents are equal
1009 if(documentOneURL == documentTwoURL)
1010 {
1011 return 0;
1012 }
1013 else if(documentOneURL < documentTwoURL)
1014 {
1015 return -1;
1016 }
1017 }
1018
1019 return 1;
1020 }
1021
1022 // Sorts two documents by file size
1023 function webdeveloper_sortDocumentsByFileSize(documentOne, documentTwo)
1024 {
1025 // If both documents and their URLs are set
1026 if(documentOne && documentTwo && documentOne.documentURI && documentTwo.documentURI)
1027 {
1028 var documentOneFileSize = webdeveloper_getFileSize(documentOne.documentURI);
1029 var documentTwoFileSize = webdeveloper_getFileSize(documentTwo.documentURI);
1030
1031 // If the document file sizes are equal
1032 if(documentOneFileSize == documentTwoFileSize)
1033 {
1034 return webdeveloper_sortDocuments(documentOne, documentTwo);
1035 }
1036 else if(documentOneFileSize > documentTwoFileSize)
1037 {
1038 return -1;
1039 }
1040 }
1041
1042 return 1;
1043 }
1044
1045 // Sorts two images by file size
1046 function webdeveloper_sortImagesByFileSize(imageOne, imageTwo)
1047 {
1048 // If both images and their file sizes are set
1049 if(imageOne && imageTwo && imageOne.fileSize && imageTwo.fileSize)
1050 {
1051 var imageOneFileSize = imageOne.fileSize;
1052 var imageTwoFileSize = imageTwo.fileSize;
1053
1054 // If the image file sizes are equal
1055 if(imageOneFileSize == imageTwoFileSize)
1056 {
1057 return webdeveloper_sortImages(imageOne, imageTwo);
1058 }
1059 else if(imageOneFileSize > imageTwoFileSize)
1060 {
1061 return -1;
1062 }
1063 }
1064
1065 return 1;
1066 }
1067
1068 // Sorts two links
1069 function webdeveloper_sortLinks(linkOne, linkTwo)
1070 {
1071 // If both links are set
1072 if(linkOne && linkTwo)
1073 {
1074 var linkOneHref = linkOne.href;
1075 var linkTwoHref = linkTwo.href;
1076
1077 // If the links are equal
1078 if(linkOneHref == linkTwoHref)
1079 {
1080 return 0;
1081 }
1082 else if(linkOneHref < linkTwoHref)
1083 {
1084 return -1;
1085 }
1086 }
1087
1088 return 1;
1089 }
1090
1091 // Sorts two scripts
1092 function webdeveloper_sortScripts(scriptOne, scriptTwo)
1093 {
1094 // If both scripts and src are set
1095 if(scriptOne && scriptTwo && scriptOne.src && scriptTwo.src)
1096 {
1097 var scriptOneSrc = scriptOne.src;
1098 var scriptTwoSrc = scriptTwo.src;
1099
1100 // If the scripts are equal
1101 if(scriptOneSrc == scriptTwoSrc)
1102 {
1103 return 0;
1104 }
1105 else if(scriptOneSrc < scriptTwoSrc)
1106 {
1107 return -1;
1108 }
1109 }
1110
1111 return 1;
1112 }
1113
1114 // Sorts two scripts by file size
1115 function webdeveloper_sortScriptsByFileSize(scriptOne, scriptTwo)
1116 {
1117 // If both scripts and src are set
1118 if(scriptOne && scriptTwo && scriptOne.src && scriptTwo.src)
1119 {
1120 var scriptOneFileSize = webdeveloper_getFileSize(scriptOne.src);
1121 var scriptTwoFileSize = webdeveloper_getFileSize(scriptTwo.src);
1122
1123 // If the script file sizes are equal
1124 if(scriptOneFileSize == scriptTwoFileSize)
1125 {
1126 return webdeveloper_sortScripts(scriptOne, scriptTwo);
1127 }
1128 else if(scriptOneFileSize > scriptTwoFileSize)
1129 {
1130 return -1;
1131 }
1132 }
1133
1134 return 1;
1135 }
1136
1137 // Sorts two style sheets
1138 function webdeveloper_sortStyleSheets(styleSheetOne, styleSheetTwo)
1139 {
1140 // If both style sheets and href are set
1141 if(styleSheetOne && styleSheetTwo && styleSheetOne.href && styleSheetTwo.href)
1142 {
1143 var styleSheetOneSrc = styleSheetOne.href;
1144 var styleSheetTwoSrc = styleSheetTwo.href;
1145
1146 // If the style sheets are equal
1147 if(styleSheetOneSrc == styleSheetTwoSrc)
1148 {
1149 return 0;
1150 }
1151 else if(styleSheetOneSrc < styleSheetTwoSrc)
1152 {
1153 return -1;
1154 }
1155 }
1156
1157 return 1;
1158 }
1159
1160 // Sorts two style sheets by file size
1161 function webdeveloper_sortStyleSheetsByFileSize(styleSheetOne, styleSheetTwo)
1162 {
1163 // If both style sheets and href are set
1164 if(styleSheetOne && styleSheetTwo && styleSheetOne.href && styleSheetTwo.href)
1165 {
1166 var styleSheetOneFileSize = webdeveloper_getFileSize(styleSheetOne.href);
1167 var styleSheetTwoFileSize = webdeveloper_getFileSize(styleSheetTwo.href);
1168
1169 // If the style sheet file sizes are equal
1170 if(styleSheetOneFileSize == styleSheetTwoFileSize)
1171 {
1172 return webdeveloper_sortStyleSheets(styleSheetOne, styleSheetTwo);
1173 }
1174 else if(styleSheetOneFileSize > styleSheetTwoFileSize)
1175 {
1176 return -1;
1177 }
1178 }
1179
1180 return 1;
1181 }
1182
1183 // Filter for stack level tree walker
1184 function webdeveloper_stackLevelFilter(node)
1185 {
1186 // If the node has a class attribute and it starts with webdeveloper
1187 if(node && (!node.hasAttribute("class") || node.getAttribute("class").indexOf("webdeveloper-") != 0))
1188 {
1189 var zIndex = node.ownerDocument.defaultView.getComputedStyle(node, null).getPropertyCSSValue("z-index").cssText;
1190
1191 // If the node has a z-index and it is not set to auto
1192 if(zIndex && zIndex != "auto")
1193 {
1194 return NodeFilter.FILTER_ACCEPT;
1195 }
1196 }
1197
1198 return NodeFilter.FILTER_SKIP;
1199 }
1200
1201 // Tidies a list of anchors by removing duplicates and sorting
1202 function webdeveloper_tidyAnchors(anchorList)
1203 {
1204 var anchor = null;
1205 var anchorLink = null;
1206 var anchorListLength = anchorList.length;
1207 var newAnchorList = new Array();
1208 var newAnchorListLength = null;
1209 var nextAnchor = null;
1210 var nextAnchorLink = null;
1211 var tidiedAnchorList = new Array();
1212
1213 // Loop through the anchors
1214 for(var i = 0; i < anchorListLength; i++)
1215 {
1216 newAnchorList.push(anchorList[i]);
1217 }
1218
1219 newAnchorList.sort(webdeveloper_sortAnchors);
1220
1221 newAnchorListLength = newAnchorList.length;
1222
1223 // Loop through the anchors
1224 for(i = 0; i < newAnchorListLength; i++)
1225 {
1226 anchor = newAnchorList[i];
1227
1228 // If the anchor has an id attribute
1229 if(anchor.hasAttribute("id"))
1230 {
1231 anchorLink = anchor.getAttribute("id");
1232 }
1233 else
1234 {
1235 anchorLink = anchor.getAttribute("name");
1236 }
1237
1238 // If this is not the last anchor
1239 if(i + 1 < newAnchorListLength)
1240 {
1241 nextAnchor = newAnchorList[i + 1];
1242
1243 // If the next anchor has an id attribute
1244 if(nextAnchor.hasAttribute("id"))
1245 {
1246 nextAnchorLink = nextAnchor.getAttribute("id");
1247 }
1248 else
1249 {
1250 nextAnchorLink = nextAnchor.getAttribute("name");
1251 }
1252
1253 // If the anchor link is the same as the next anchor link
1254 if(anchorLink == nextAnchorLink)
1255 {
1256 continue;
1257 }
1258 }
1259
1260 tidiedAnchorList.push(anchor);
1261 }
1262
1263 return tidiedAnchorList;
1264 }
1265
1266 // Tidies a list of colors by removing duplicates and sorting
1267 function webdeveloper_tidyColors(colorList)
1268 {
1269 var color = null;
1270 var colorListLength = colorList.length;
1271 var newColorList = new Array();
1272 var newColorListLength = null;
1273 var tidiedColorList = new Array();
1274
1275 // Loop through the colors
1276 for(var i = 0; i < colorListLength; i++)
1277 {
1278 newColorList.push(colorList[i]);
1279 }
1280
1281 newColorList.sort();
1282
1283 newColorListLength = newColorList.length;
1284
1285 // Loop through the colors
1286 for(i = 0; i < newColorListLength; i++)
1287 {
1288 color = newColorList[i];
1289
1290 // If this is not the last color and the color is the same as the next color
1291 if(i + 1 < newColorListLength && color == newColorList[i + 1])
1292 {
1293 continue;
1294 }
1295
1296 tidiedColorList.push(color);
1297 }
1298
1299 return tidiedColorList;
1300 }
1301
1302 // Tidies a list of documents by removing duplicates and sorting
1303 function webdeveloper_tidyDocuments(documentList)
1304 {
1305 var documentListLength = documentList.length;
1306 var documentURL = null;
1307 var newDocumentList = new Array();
1308 var newDocumentListLength = null;
1309 var pageDocument = null;
1310 var tidiedDocumentList = new Array();
1311
1312 // Loop through the documents
1313 for(var i = 0; i < documentListLength; i++)
1314 {
1315 newDocumentList.push(documentList[i]);
1316 }
1317
1318 newDocumentList.sort(webdeveloper_sortDocuments);
1319
1320 newDocumentListLength = newDocumentList.length;
1321
1322 // Loop through the documents
1323 for(i = 0; i < newDocumentListLength; i++)
1324 {
1325 pageDocument = newDocumentList[i];
1326
1327 // If this is not the last document and the document is the same as the next document
1328 if(i + 1 < newDocumentListLength && pageDocument.documentURI == newDocumentList[i + 1].documentURI)
1329 {
1330 continue;
1331 }
1332
1333 tidiedDocumentList.push(pageDocument);
1334 }
1335
1336 return tidiedDocumentList;
1337 }
1338
1339 // Tidies a list of links by removing duplicates and sorting
1340 function webdeveloper_tidyLinks(linkList)
1341 {
1342 var link = null;
1343 var linkListLength = linkList.length;
1344 var newLinkList = new Array();
1345 var newLinkListLength = null;
1346 var tidiedLinkList = new Array();
1347
1348 // Loop through the links
1349 for(var i = 0; i < linkListLength; i++)
1350 {
1351 link = linkList[i];
1352
1353 // If this link is set
1354 if(link.href)
1355 {
1356 newLinkList.push(link);
1357 }
1358 }
1359
1360 newLinkList.sort(webdeveloper_sortLinks);
1361
1362 newLinkListLength = newLinkList.length;
1363
1364 // Loop through the links
1365 for(i = 0; i < newLinkListLength; i++)
1366 {
1367 link = newLinkList[i];
1368
1369 // If this is not the last link and the link is the same as the next link
1370 if(i + 1 < newLinkListLength && link.href == newLinkList[i + 1].href)
1371 {
1372 continue;
1373 }
1374
1375 tidiedLinkList.push(link);
1376 }
1377
1378 return tidiedLinkList;
1379 }
1380
1381 // Tidies a list of scripts by removing duplicates and sorting
1382 function webdeveloper_tidyScripts(scriptList)
1383 {
1384 var script = null;
1385 var scriptListLength = scriptList.length;
1386 var newScriptList = new Array();
1387 var newScriptListLength = null;
1388 var tidiedScriptList = new Array();
1389
1390 // Loop through the scripts
1391 for(var i = 0; i < scriptListLength; i++)
1392 {
1393 script = scriptList[i];
1394
1395 // If this script and the src is set
1396 if(script && script.src)
1397 {
1398 newScriptList.push(script);
1399 }
1400 }
1401
1402 newScriptList.sort(webdeveloper_sortScripts);
1403
1404 newScriptListLength = newScriptList.length;
1405
1406 // Loop through the scripts
1407 for(i = 0; i < newScriptListLength; i++)
1408 {
1409 script = newScriptList[i];
1410
1411 // If this is not the last script and the script is the same as the next script
1412 if(i + 1 < newScriptListLength && script.src == newScriptList[i + 1].src)
1413 {
1414 continue;
1415 }
1416
1417 tidiedScriptList.push(script);
1418 }
1419
1420 return tidiedScriptList;
1421 }
1422
1423 // Tidies a list of style sheets by removing duplicates and sorting
1424 function webdeveloper_tidyStyleSheets(styleSheetList)
1425 {
1426 var styleSheet = null;
1427 var styleSheetListLength = styleSheetList.length;
1428 var newStyleSheetList = new Array();
1429 var newStyleSheetListLength = null;
1430 var tidiedStyleSheetList = new Array();
1431
1432 // Loop through the style sheets
1433 for(var i = 0; i < styleSheetListLength; i++)
1434 {
1435 styleSheet = styleSheetList[i];
1436
1437 // If this style sheet and the href is set
1438 if(styleSheet && styleSheet.href)
1439 {
1440 newStyleSheetList.push(styleSheet);
1441 }
1442 }
1443
1444 newStyleSheetList.sort(webdeveloper_sortStyleSheets);
1445
1446 newStyleSheetListLength = newStyleSheetList.length;
1447
1448 // Loop through the style sheets
1449 for(i = 0; i < newStyleSheetListLength; i++)
1450 {
1451 styleSheet = newStyleSheetList[i];
1452
1453 // If this is not the last style sheet and the style sheet is the same as the next style sheet
1454 if(i + 1 < newStyleSheetListLength && styleSheet.href == newStyleSheetList[i + 1].href)
1455 {
1456 continue;
1457 }
1458
1459 tidiedStyleSheetList.push(styleSheet);
1460 }
1461
1462 return tidiedStyleSheetList;
1463 }
1464
1465 // Updates the information menu
1466 function webdeveloper_updateInformationMenu(suffix)
1467 {
1468 webdeveloper_configureElementByAppliedStyle(document.getElementById("webdeveloper-display-abbreviations-" + suffix), "checked", "webdeveloper-display-abbreviations");
1469 webdeveloper_configureElementByAppliedStyle(document.getElementById("webdeveloper-display-access-keys-" + suffix), "checked", "webdeveloper-display-access-keys");
1470 webdeveloper_configureElementByAppliedStyle(document.getElementById("webdeveloper-display-anchors-" + suffix), "checked", "webdeveloper-display-anchors");
1471 webdeveloper_configureElementByAppliedStyle(document.getElementById("webdeveloper-display-block-size-" + suffix), "checked", "webdeveloper-display-block-size");
1472 webdeveloper_configureElementByAppliedStyle(document.getElementById("webdeveloper-display-div-order-" + suffix), "checked", "webdeveloper-display-div-order");
1473 webdeveloper_configureElementByAppliedStyle(document.getElementById("webdeveloper-display-element-information-" + suffix), "checked", "webdeveloper-display-element-information");
1474 webdeveloper_configureElementByAppliedStyle(document.getElementById("webdeveloper-display-id-class-details-" + suffix), "checked", "webdeveloper-display-id-class-details");
1475 webdeveloper_configureElementByAppliedStyle(document.getElementById("webdeveloper-display-link-details-" + suffix), "checked", "webdeveloper-display-link-details");
1476 webdeveloper_configureElementByAppliedStyle(document.getElementById("webdeveloper-display-object-information-" + suffix), "checked", "webdeveloper-display-object-information");
1477 webdeveloper_configureElementByAppliedStyle(document.getElementById("webdeveloper-display-stack-levels-" + suffix), "checked", "webdeveloper-display-stack-levels");
1478 webdeveloper_configureElementByAppliedStyle(document.getElementById("webdeveloper-display-tab-index-" + suffix), "checked", "webdeveloper-display-tab-index");
1479 webdeveloper_configureElementByAppliedStyle(document.getElementById("webdeveloper-display-table-depth-" + suffix), "checked", "webdeveloper-display-table-depth");
1480 webdeveloper_configureElementByAppliedStyle(document.getElementById("webdeveloper-display-table-information-" + suffix), "checked", "webdeveloper-display-table-information");
1481 webdeveloper_configureElementByAppliedStyle(document.getElementById("webdeveloper-display-title-attributes-" + suffix), "checked", "webdeveloper-display-title-attributes");
1482 webdeveloper_configureElementByAppliedStyle(document.getElementById("webdeveloper-display-topographic-information-" + suffix), "checked", "webdeveloper-display-topographic-information");
1483 }
1484
1485 // Displays all the anchors for the page
1486 function webdeveloper_viewAnchorInformation()
1487 {
1488 var anchor = null;
1489 var anchorLength = null;
1490 var anchorLink = null;
1491 var anchorList = null;
1492 var divElement = null;
1493 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
1494 var documentLength = documentList.length;
1495 var documentURL = null;
1496 var linkElement = null;
1497 var linkHref = null;
1498 var linkLength = null;
1499 var listElement = null;
1500 var listItemElement = null;
1501 var oldTab = getBrowser().selectedTab;
1502 var oldURL = getBrowser().currentURI.spec;
1503 var generatedDocument = webdeveloper_generateDocument("");
1504 var bodyElement = webdeveloper_getDocumentBodyElement(generatedDocument);
1505 var headElement = webdeveloper_getDocumentHeadElement(generatedDocument);
1506 var headerElement = generatedDocument.createElement("h1");
1507 var pageDocument = null;
1508 var pElement = null;
1509 var scriptElement = generatedDocument.createElement("script");
1510 var spanElement = null;
1511 var stringBundle = document.getElementById("webdeveloper-string-bundle");
1512 var title = stringBundle.getFormattedString("webdeveloper_viewAnchorInformationTitle", [oldURL]);
1513
1514 generatedDocument.title = title;
1515
1516 webdeveloper_addGeneratedStyles(generatedDocument);
1517
1518 headerElement.appendChild(generatedDocument.createTextNode(title));
1519 bodyElement.appendChild(headerElement);
1520
1521 webdeveloper_addGeneratedTools(generatedDocument);
1522
1523 // Loop through the documents
1524 for(var i = 0; i < documentLength; i++)
1525 {
1526 divElement = generatedDocument.createElement("div");
1527 headerElement = generatedDocument.createElement("h2");
1528 linkElement = generatedDocument.createElement("a");
1529 pageDocument = documentList[i];
1530 anchorList = webdeveloper_evaluateXPath(pageDocument, "//*[@id] | //a[@name]");
1531 documentURL = pageDocument.documentURI;
1532 spanElement = generatedDocument.createElement("span");
1533
1534 // If the tidy information preference is set
1535 if(webdeveloper_getBooleanPreference("webdeveloper.information.tidy", true))
1536 {
1537 anchorList = webdeveloper_tidyAnchors(anchorList);
1538 }
1539
1540 spanElement.setAttribute("class", "expanded pivot");
1541 headerElement.appendChild(spanElement);
1542 linkElement.setAttribute("href", documentURL);
1543 linkElement.appendChild(generatedDocument.createTextNode(documentURL));
1544 headerElement.appendChild(linkElement);
1545 bodyElement.appendChild(headerElement);
1546
1547 anchorLength = anchorList.length;
1548
1549 // If there are no anchors
1550 if(anchorLength == 0)
1551 {
1552 pElement = generatedDocument.createElement("p");
1553
1554 pElement.appendChild(generatedDocument.createTextNode(stringBundle.getString("webdeveloper_noAnchors")));
1555 divElement.appendChild(pElement);
1556 }
1557 else
1558 {
1559 listElement = generatedDocument.createElement("ol");
1560
1561 // Loop through the links
1562 for(var j = 0; j < anchorLength; j++)
1563 {
1564 anchor = anchorList[j];
1565
1566 // If the anchor has an id attribute
1567 if(anchor.hasAttribute("id"))
1568 {
1569 anchorLink = "#" + anchor.getAttribute("id");
1570 }
1571 else
1572 {
1573 anchorLink = "#" + anchor.getAttribute("name");
1574 }
1575
1576 linkElement = generatedDocument.createElement("a");
1577 listItemElement = generatedDocument.createElement("li");
1578
1579 linkElement.setAttribute("href", documentURL + anchorLink);
1580 linkElement.appendChild(generatedDocument.createTextNode(anchorLink));
1581 listItemElement.appendChild(linkElement);
1582 listElement.appendChild(listItemElement);
1583 }
1584
1585 divElement.appendChild(listElement);
1586 }
1587
1588 divElement.setAttribute("class", "output");
1589 bodyElement.appendChild(divElement);
1590 }
1591
1592 scriptElement.setAttribute("defer", "defer");
1593 scriptElement.setAttribute("src", "chrome://webdeveloper/content/common/xpath.js");
1594 scriptElement.setAttribute("type", "text/javascript");
1595 headElement.appendChild(scriptElement);
1596
1597 scriptElement = generatedDocument.createElement("script");
1598
1599 scriptElement.setAttribute("defer", "defer");
1600 scriptElement.setAttribute("src", "chrome://webdeveloper/content/generated/output_pivot.js");
1601 scriptElement.setAttribute("type", "text/javascript");
1602 headElement.appendChild(scriptElement);
1603
1604 // If the open tabs in background preference is set to true
1605 if(webdeveloper_getBooleanPreference("webdeveloper.open.tabs.background", true))
1606 {
1607 getBrowser().selectedTab = oldTab;
1608 }
1609 }
1610
1611 // Displays all the colors on the page
1612 function webdeveloper_viewColorInformation()
1613 {
1614 var color = null;
1615 var colorList = null;
1616 var colorsLength = null;
1617 var definitionElement = null;
1618 var definitionListElement = null;
1619 var divElement = null;
1620 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
1621 var documentLength = documentList.length;
1622 var documentURL = null;
1623 var element = null;
1624 var oldTab = getBrowser().selectedTab;
1625 var oldURL = getBrowser().currentURI.spec;
1626 var generatedDocument = webdeveloper_generateDocument("");
1627 var bodyElement = webdeveloper_getDocumentBodyElement(generatedDocument);
1628 var headElement = webdeveloper_getDocumentHeadElement(generatedDocument);
1629 var headerElement = generatedDocument.createElement("h1");
1630 var linkElement = generatedDocument.createElement("link");
1631 var pageDocument = null;
1632 var scriptElement = generatedDocument.createElement("script");
1633 var spanElement = null;
1634 var termElement = null;
1635 var title = document.getElementById("webdeveloper-string-bundle").getFormattedString("webdeveloper_viewColorInformationTitle", [oldURL]);
1636 var treeWalker = null;
1637
1638 generatedDocument.title = title;
1639
1640 webdeveloper_addGeneratedStyles(generatedDocument);
1641
1642 linkElement.setAttribute("href", "chrome://webdeveloper/content/stylesheets/generated/view_color_information.css");
1643 linkElement.setAttribute("rel", "stylesheet");
1644 linkElement.setAttribute("type", "text/css");
1645 headElement.appendChild(linkElement);
1646
1647 headerElement.appendChild(generatedDocument.createTextNode(title));
1648 bodyElement.appendChild(headerElement);
1649
1650 webdeveloper_addGeneratedTools(generatedDocument);
1651
1652 // Loop through the documents
1653 for(var i = 0; i < documentLength; i++)
1654 {
1655 colorList = new Array();
1656 divElement = generatedDocument.createElement("div");
1657 headerElement = generatedDocument.createElement("h2");
1658 linkElement = generatedDocument.createElement("a");
1659 pageDocument = documentList[i];
1660 documentURL = pageDocument.documentURI;
1661 spanElement = generatedDocument.createElement("span");
1662 treeWalker = pageDocument.createTreeWalker(webdeveloper_getDocumentBodyElement(pageDocument), NodeFilter.SHOW_ELEMENT, null, false);
1663
1664 // Loop through the anchor elements
1665 while((element = treeWalker.nextNode()) != null)
1666 {
1667 webdeveloper_addColor(element, "background-color", colorList);
1668 webdeveloper_addColor(element, "border-bottom-color", colorList);
1669 webdeveloper_addColor(element, "border-left-color", colorList);
1670 webdeveloper_addColor(element, "border-right-color", colorList);
1671 webdeveloper_addColor(element, "border-top-color", colorList);
1672 webdeveloper_addColor(element, "color", colorList);
1673 }
1674
1675 spanElement.setAttribute("class", "expanded pivot");
1676 headerElement.appendChild(spanElement);
1677 linkElement.setAttribute("href", documentURL);
1678 linkElement.appendChild(generatedDocument.createTextNode(documentURL));
1679 headerElement.appendChild(linkElement);
1680 bodyElement.appendChild(headerElement);
1681
1682 colorList = webdeveloper_tidyColors(colorList);
1683 colorsLength = colorList.length;
1684
1685 // Loop through the colors
1686 for(var j = 0; j < colorsLength; j++)
1687 {
1688 color = colorList[j];
1689 definitionElement = generatedDocument.createElement("dd");
1690 definitionListElement = generatedDocument.createElement("dl");
1691 termElement = generatedDocument.createElement("dt");
1692
1693 termElement.appendChild(generatedDocument.createTextNode(color));
1694 definitionListElement.appendChild(termElement);
1695
1696 definitionElement.setAttribute("style", "background-color: " + color);
1697 definitionListElement.appendChild(definitionElement);
1698 divElement.appendChild(definitionListElement);
1699 }
1700
1701 divElement.setAttribute("class", "output");
1702 bodyElement.appendChild(divElement);
1703 }
1704
1705 scriptElement.setAttribute("defer", "defer");
1706 scriptElement.setAttribute("src", "chrome://webdeveloper/content/common/xpath.js");
1707 scriptElement.setAttribute("type", "text/javascript");
1708 headElement.appendChild(scriptElement);
1709
1710 scriptElement = generatedDocument.createElement("script");
1711
1712 scriptElement.setAttribute("defer", "defer");
1713 scriptElement.setAttribute("src", "chrome://webdeveloper/content/generated/output_pivot.js");
1714 scriptElement.setAttribute("type", "text/javascript");
1715 headElement.appendChild(scriptElement);
1716
1717 // If the open tabs in background preference is set to true
1718 if(webdeveloper_getBooleanPreference("webdeveloper.open.tabs.background", true))
1719 {
1720 getBrowser().selectedTab = oldTab;
1721 }
1722 }
1723
1724 // Displays an outline of the page
1725 function webdeveloper_viewDocumentOutline()
1726 {
1727 var divElement = null;
1728 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
1729 var documentLength = documentList.length;
1730 var documentURL = null;
1731 var headerElementList = null;
1732 var headerElementsLength = null;
1733 var headerLevel = null;
1734 var headerTagName = null;
1735 var headerText = null;
1736 var oldTab = getBrowser().selectedTab;
1737 var oldURL = getBrowser().currentURI.spec;
1738 var generatedDocument = webdeveloper_generateDocument("");
1739 var bodyElement = webdeveloper_getDocumentBodyElement(generatedDocument);
1740 var headElement = webdeveloper_getDocumentHeadElement(generatedDocument);
1741 var headerElement = generatedDocument.createElement("h1");
1742 var linkElement = generatedDocument.createElement("link");
1743 var outlineElement = null;
1744 var pageDocument = null;
1745 var previousHeaderLevel = null;
1746 var scriptElement = generatedDocument.createElement("script");
1747 var spanElement = null;
1748 var stringBundle = document.getElementById("webdeveloper-string-bundle");
1749 var title = stringBundle.getFormattedString("webdeveloper_viewDocumentOutlineTitle", [oldURL]);
1750 var treeWalker = null;
1751
1752 generatedDocument.title = title;
1753
1754 webdeveloper_addGeneratedStyles(generatedDocument);
1755
1756 linkElement.setAttribute("href", "chrome://webdeveloper/content/stylesheets/generated/view_document_outline.css");
1757 linkElement.setAttribute("rel", "stylesheet");
1758 linkElement.setAttribute("type", "text/css");
1759 headElement.appendChild(linkElement);
1760
1761 headerElement.appendChild(generatedDocument.createTextNode(title));
1762 bodyElement.appendChild(headerElement);
1763
1764 webdeveloper_addGeneratedTools(generatedDocument);
1765
1766 // Loop through the documents
1767 for(var i = 0; i < documentLength; i++)
1768 {
1769 divElement = generatedDocument.createElement("div");
1770 headerElement = generatedDocument.createElement("h2");
1771 linkElement = generatedDocument.createElement("a");
1772 pageDocument = documentList[i];
1773 documentURL = pageDocument.documentURI;
1774 headerElementList = webdeveloper_evaluateXPath(pageDocument, "//h1 | //h2 | //h3 | //h4 | //h5 | //h6");
1775 headerElementsLength = headerElementList.length;
1776 previousHeaderLevel = 0;
1777 spanElement = generatedDocument.createElement("span");
1778
1779 spanElement.setAttribute("class", "expanded pivot");
1780 headerElement.appendChild(spanElement);
1781 linkElement.setAttribute("href", documentURL);
1782 linkElement.appendChild(generatedDocument.createTextNode(documentURL));
1783 headerElement.appendChild(linkElement);
1784 bodyElement.appendChild(headerElement);
1785
1786 // Loop through the heading elements
1787 for(var j = 0; j < headerElementsLength; j++)
1788 {
1789 headerElement = headerElementList[j];
1790 headerTagName = headerElement.tagName.toLowerCase();
1791 headerText = webdeveloper_getElementText(headerElement).trim();
1792 headerLevel = parseInt(headerTagName.substring(1));
1793
1794 // Loop through any missing headers
1795 for(var k = previousHeaderLevel + 1; k < headerLevel; k++)
1796 {
1797 outlineElement = generatedDocument.createElement("h" + k);
1798
1799 outlineElement.setAttribute("class", "webdeveloper-document-outline webdeveloper-document-outline-missing");
1800 outlineElement.appendChild(generatedDocument.createTextNode(stringBundle.getString("webdeveloper_viewDocumentOutlineMissingHeading")));
1801 divElement.appendChild(outlineElement);
1802 }
1803
1804 // If there is no header text
1805 if(!headerText)
1806 {
1807 headerText = stringBundle.getString("webdeveloper_viewDocumentOutlineEmptyHeading");
1808 }
1809
1810 outlineElement = generatedDocument.createElement(headerTagName);
1811
1812 outlineElement.setAttribute("class", "webdeveloper-document-outline");
1813 outlineElement.appendChild(generatedDocument.createTextNode(headerText));
1814 divElement.appendChild(outlineElement);
1815
1816 previousHeaderLevel = headerLevel;
1817 }
1818
1819 divElement.setAttribute("class", "output");
1820 bodyElement.appendChild(divElement);
1821 }
1822
1823 scriptElement.setAttribute("defer", "defer");
1824 scriptElement.setAttribute("src", "chrome://webdeveloper/content/common/xpath.js");
1825 scriptElement.setAttribute("type", "text/javascript");
1826 headElement.appendChild(scriptElement);
1827
1828 scriptElement = generatedDocument.createElement("script");
1829
1830 scriptElement.setAttribute("defer", "defer");
1831 scriptElement.setAttribute("src", "chrome://webdeveloper/content/generated/output_pivot.js");
1832 scriptElement.setAttribute("type", "text/javascript");
1833 headElement.appendChild(scriptElement);
1834
1835 // If the open tabs in background preference is set to true
1836 if(webdeveloper_getBooleanPreference("webdeveloper.open.tabs.background", true))
1837 {
1838 getBrowser().selectedTab = oldTab;
1839 }
1840 }
1841
1842 // View JavaScript
1843 function webdeveloper_viewJavaScript()
1844 {
1845 var divElement = null;
1846 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
1847 var documentLength = documentList.length;
1848 var documentURL = null;
1849 var linkElement = null;
1850 var oldTab = getBrowser().selectedTab;
1851 var oldURL = getBrowser().currentURI.spec;
1852 var generatedDocument = webdeveloper_generateDocument("");
1853 var bodyElement = webdeveloper_getDocumentBodyElement(generatedDocument);
1854 var headElement = webdeveloper_getDocumentHeadElement(generatedDocument);
1855 var headerElement = generatedDocument.createElement("h1");
1856 var pageDocument = null;
1857 var preElement = null;
1858 var scriptElement = null;
1859 var scriptLength = null;
1860 var scriptList = new Array();
1861 var scriptSource = null;
1862 var spanElement = null;
1863 var stringBundle = document.getElementById("webdeveloper-string-bundle");
1864 var title = stringBundle.getFormattedString("webdeveloper_viewJavaScriptTitle", [oldURL]);
1865
1866 generatedDocument.title = title;
1867
1868 webdeveloper_addGeneratedStyles(generatedDocument);
1869
1870 headerElement.appendChild(generatedDocument.createTextNode(title));
1871 bodyElement.appendChild(headerElement);
1872
1873 webdeveloper_addGeneratedTools(generatedDocument);
1874
1875 // Loop through the documents
1876 for(var i = 0; i < documentLength; i++)
1877 {
1878 headerElement = generatedDocument.createElement("h2");
1879 linkElement = generatedDocument.createElement("a");
1880 pageDocument = documentList[i];
1881 documentURL = pageDocument.documentURI;
1882 scriptList = pageDocument.getElementsByTagName("script");
1883 scriptLength = scriptList.length;
1884
1885 linkElement.setAttribute("href", pageDocument.documentURI);
1886 linkElement.appendChild(generatedDocument.createTextNode(documentURL));
1887 headerElement.appendChild(linkElement);
1888 bodyElement.appendChild(headerElement);
1889
1890 // Loop through the scripts
1891 for(var j = 0; j < scriptLength; j++)
1892 {
1893 divElement = generatedDocument.createElement("div");
1894 headerElement = generatedDocument.createElement("h3");
1895 preElement = generatedDocument.createElement("pre");
1896 scriptElement = scriptList[j];
1897 scriptSource = scriptElement.src;
1898 spanElement = generatedDocument.createElement("span");
1899
1900 // If the script is external
1901 if(scriptSource)
1902 {
1903 // If this is a not chrome script
1904 if(scriptSource.indexOf("chrome://") != 0)
1905 {
1906 linkElement = generatedDocument.createElement("a");
1907
1908 spanElement.setAttribute("class", "expanded pivot");
1909 headerElement.appendChild(spanElement);
1910 linkElement.setAttribute("href", scriptSource);
1911 linkElement.appendChild(generatedDocument.createTextNode(scriptSource));
1912 headerElement.appendChild(linkElement);
1913 bodyElement.appendChild(headerElement);
1914
1915 preElement.appendChild(generatedDocument.createTextNode(webdeveloper_retrieveSource(scriptSource).replace(new RegExp("\r", "gi"), "\n")));
1916 divElement.setAttribute("class", "output");
1917 divElement.appendChild(preElement);
1918 bodyElement.appendChild(divElement);
1919 }
1920 }
1921 else
1922 {
1923 spanElement.setAttribute("class", "expanded pivot");
1924 headerElement.appendChild(spanElement);
1925 headerElement.appendChild(generatedDocument.createTextNode(stringBundle.getFormattedString("webdeveloper_inlineScript", [documentURL])));
1926 bodyElement.appendChild(headerElement);
1927
1928 preElement.appendChild(generatedDocument.createTextNode(scriptElement.innerHTML));
1929 divElement.setAttribute("class", "output");
1930 divElement.appendChild(preElement);
1931 bodyElement.appendChild(divElement);
1932 }
1933 }
1934 }
1935
1936 scriptElement = generatedDocument.createElement("script");
1937
1938 scriptElement.setAttribute("defer", "defer");
1939 scriptElement.setAttribute("src", "chrome://webdeveloper/content/common/xpath.js");
1940 scriptElement.setAttribute("type", "text/javascript");
1941 headElement.appendChild(scriptElement);
1942
1943 scriptElement = generatedDocument.createElement("script");
1944
1945 scriptElement.setAttribute("defer", "defer");
1946 scriptElement.setAttribute("src", "chrome://webdeveloper/content/generated/output_pivot.js");
1947 scriptElement.setAttribute("type", "text/javascript");
1948 headElement.appendChild(scriptElement);
1949
1950 // If the open tabs in background preference is set to true
1951 if(webdeveloper_getBooleanPreference("webdeveloper.open.tabs.background", true))
1952 {
1953 getBrowser().selectedTab = oldTab;
1954 }
1955 }
1956
1957 // Displays all the links for the page
1958 function webdeveloper_viewLinkInformation()
1959 {
1960 var divElement = null;
1961 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
1962 var documentLength = documentList.length;
1963 var documentURL = null;
1964 var link = null;
1965 var linkElement = null;
1966 var linkHref = null;
1967 var linkLength = null;
1968 var links = null;
1969 var listElement = null;
1970 var listItemElement = null;
1971 var oldTab = getBrowser().selectedTab;
1972 var oldURL = getBrowser().currentURI.spec;
1973 var generatedDocument = webdeveloper_generateDocument("");
1974 var bodyElement = webdeveloper_getDocumentBodyElement(generatedDocument);
1975 var headElement = webdeveloper_getDocumentHeadElement(generatedDocument);
1976 var headerElement = generatedDocument.createElement("h1");
1977 var pageDocument = null;
1978 var pElement = null;
1979 var scriptElement = generatedDocument.createElement("script");
1980 var spanElement = null;
1981 var stringBundle = document.getElementById("webdeveloper-string-bundle");
1982 var title = stringBundle.getFormattedString("webdeveloper_viewLinkInformationTitle", [oldURL]);
1983
1984 generatedDocument.title = title;
1985
1986 webdeveloper_addGeneratedStyles(generatedDocument);
1987
1988 headerElement.appendChild(generatedDocument.createTextNode(title));
1989 bodyElement.appendChild(headerElement);
1990
1991 webdeveloper_addGeneratedTools(generatedDocument);
1992
1993 // Loop through the documents
1994 for(var i = 0; i < documentLength; i++)
1995 {
1996 divElement = generatedDocument.createElement("div");
1997 headerElement = generatedDocument.createElement("h2");
1998 linkElement = generatedDocument.createElement("a");
1999 pageDocument = documentList[i];
2000 documentURL = pageDocument.documentURI;
2001 links = pageDocument.links;
2002 spanElement = generatedDocument.createElement("span");
2003
2004 // If the tidy information preference is set
2005 if(webdeveloper_getBooleanPreference("webdeveloper.information.tidy", true))
2006 {
2007 links = webdeveloper_tidyLinks(links);
2008 }
2009
2010 spanElement.setAttribute("class", "expanded pivot");
2011 headerElement.appendChild(spanElement);
2012 linkElement.setAttribute("href", documentURL);
2013 linkElement.appendChild(generatedDocument.createTextNode(documentURL));
2014 headerElement.appendChild(linkElement);
2015 bodyElement.appendChild(headerElement);
2016
2017 linkLength = links.length;
2018
2019 // If there are no links
2020 if(linkLength == 0)
2021 {
2022 pElement = generatedDocument.createElement("p");
2023
2024 pElement.appendChild(generatedDocument.createTextNode(stringBundle.getString("webdeveloper_noLinks")));
2025 divElement.appendChild(pElement);
2026 }
2027 else
2028 {
2029 listElement = generatedDocument.createElement("ol");
2030
2031 // Loop through the links
2032 for(var j = 0; j < linkLength; j++)
2033 {
2034 link = links[j];
2035 linkHref = link.href;
2036
2037 // If the link is set
2038 if(linkHref)
2039 {
2040 linkElement = generatedDocument.createElement("a");
2041 listItemElement = generatedDocument.createElement("li");
2042
2043 linkElement.setAttribute("href", linkHref);
2044 linkElement.appendChild(generatedDocument.createTextNode(linkHref));
2045 listItemElement.appendChild(linkElement);
2046 listElement.appendChild(listItemElement);
2047 }
2048 }
2049
2050 divElement.appendChild(listElement);
2051 }
2052
2053 divElement.setAttribute("class", "output");
2054 bodyElement.appendChild(divElement);
2055 }
2056
2057 scriptElement.setAttribute("defer", "defer");
2058 scriptElement.setAttribute("src", "chrome://webdeveloper/content/common/xpath.js");
2059 scriptElement.setAttribute("type", "text/javascript");
2060 headElement.appendChild(scriptElement);
2061
2062 scriptElement = generatedDocument.createElement("script");
2063
2064 scriptElement.setAttribute("defer", "defer");
2065 scriptElement.setAttribute("src", "chrome://webdeveloper/content/generated/output_pivot.js");
2066 scriptElement.setAttribute("type", "text/javascript");
2067 headElement.appendChild(scriptElement);
2068
2069 // If the open tabs in background preference is set to true
2070 if(webdeveloper_getBooleanPreference("webdeveloper.open.tabs.background", true))
2071 {
2072 getBrowser().selectedTab = oldTab;
2073 }
2074 }
2075
2076 // Displays all the meta tags for the page
2077 function webdeveloper_viewMetaTagInformation()
2078 {
2079 var cellDataElement = null;
2080 var cellHeaderElement = null;
2081 var divElement = null;
2082 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
2083 var documentLength = documentList.length;
2084 var documentURL = null;
2085 var linkElement = null;
2086 var metaTag = null;
2087 var metaTags = null;
2088 var metaTagsLength = null;
2089 var oldTab = getBrowser().selectedTab;
2090 var oldURL = getBrowser().currentURI.spec;
2091 var generatedDocument = webdeveloper_generateDocument("");
2092 var bodyElement = webdeveloper_getDocumentBodyElement(generatedDocument);
2093 var headElement = webdeveloper_getDocumentHeadElement(generatedDocument);
2094 var headerElement = generatedDocument.createElement("h1");
2095 var pageDocument = null;
2096 var pElement = null;
2097 var scriptElement = generatedDocument.createElement("script");
2098 var spanElement = null;
2099 var stringBundle = document.getElementById("webdeveloper-string-bundle");
2100 var tableElement = null;
2101 var tableRowElement = null;
2102 var title = stringBundle.getFormattedString("webdeveloper_viewMetaTagInformationTitle", [oldURL]);
2103
2104 generatedDocument.title = title;
2105
2106 webdeveloper_addGeneratedStyles(generatedDocument);
2107
2108 headerElement.appendChild(generatedDocument.createTextNode(title));
2109 bodyElement.appendChild(headerElement);
2110
2111 webdeveloper_addGeneratedTools(generatedDocument);
2112
2113 // Loop through the documents
2114 for(var i = 0; i < documentLength; i++)
2115 {
2116 divElement = generatedDocument.createElement("div");
2117 headerElement = generatedDocument.createElement("h2");
2118 linkElement = generatedDocument.createElement("a");
2119 pageDocument = documentList[i];
2120 documentURL = pageDocument.documentURI;
2121 metaTags = pageDocument.getElementsByTagName("meta");
2122 metaTagsLength = metaTags.length;
2123 spanElement = generatedDocument.createElement("span");
2124
2125 spanElement.setAttribute("class", "expanded pivot");
2126 headerElement.appendChild(spanElement);
2127 linkElement.setAttribute("href", documentURL);
2128 linkElement.appendChild(generatedDocument.createTextNode(documentURL));
2129 headerElement.appendChild(linkElement);
2130 bodyElement.appendChild(headerElement);
2131
2132 // If there are no meta tags
2133 if(metaTagsLength == 0)
2134 {
2135 pElement = generatedDocument.createElement("p");
2136
2137 pElement.appendChild(generatedDocument.createTextNode(stringBundle.getString("webdeveloper_noMetaTags")));
2138 divElement.appendChild(pElement);
2139 }
2140 else
2141 {
2142 tableElement = generatedDocument.createElement("table");
2143 tableRowElement = generatedDocument.createElement("tr");
2144
2145 // Name heading
2146 cellHeaderElement = generatedDocument.createElement("th");
2147
2148 cellHeaderElement.appendChild(generatedDocument.createTextNode(stringBundle.getString("webdeveloper_name")));
2149 tableRowElement.appendChild(cellHeaderElement);
2150
2151 // Content heading
2152 cellHeaderElement = generatedDocument.createElement("th");
2153
2154 cellHeaderElement.appendChild(generatedDocument.createTextNode(stringBundle.getString("webdeveloper_content")));
2155 tableRowElement.appendChild(cellHeaderElement);
2156 tableElement.appendChild(tableRowElement);
2157
2158 // Loop through the meta tags
2159 for(var j = 0; j < metaTagsLength; j++)
2160 {
2161 metaTag = metaTags[j];
2162 tableRowElement = generatedDocument.createElement("tr");
2163
2164 // If this is an even row
2165 if(j % 2 != 0)
2166 {
2167 tableRowElement.setAttribute("class", "shaded");
2168 }
2169
2170 cellDataElement = generatedDocument.createElement("td");
2171
2172 // If the meta tag has a name attribute
2173 if(metaTag.hasAttribute("name"))
2174 {
2175 cellDataElement.appendChild(generatedDocument.createTextNode(metaTag.getAttribute("name")));
2176 }
2177 else if(metaTag.hasAttribute("http-equiv"))
2178 {
2179 cellDataElement.appendChild(generatedDocument.createTextNode(metaTag.getAttribute("http-equiv")));
2180 }
2181
2182 tableRowElement.appendChild(cellDataElement);
2183
2184 // Content
2185 cellDataElement = generatedDocument.createElement("td");
2186
2187 cellDataElement.appendChild(generatedDocument.createTextNode(metaTag.getAttribute("content")));
2188 tableRowElement.appendChild(cellDataElement);
2189 tableElement.appendChild(tableRowElement);
2190 }
2191
2192 tableElement.setAttribute("class", "sortable");
2193 divElement.appendChild(tableElement);
2194 }
2195
2196 divElement.setAttribute("class", "output");
2197 bodyElement.appendChild(divElement);
2198 }
2199
2200 scriptElement.setAttribute("defer", "defer");
2201 scriptElement.setAttribute("src", "chrome://webdeveloper/content/common/dom.js");
2202 scriptElement.setAttribute("type", "text/javascript");
2203 headElement.appendChild(scriptElement);
2204
2205 scriptElement = generatedDocument.createElement("script");
2206
2207 scriptElement.setAttribute("defer", "defer");
2208 scriptElement.setAttribute("src", "chrome://webdeveloper/content/common/xpath.js");
2209 scriptElement.setAttribute("type", "text/javascript");
2210 headElement.appendChild(scriptElement);
2211
2212 scriptElement = generatedDocument.createElement("script");
2213
2214 scriptElement.setAttribute("defer", "defer");
2215 scriptElement.setAttribute("src", "chrome://webdeveloper/content/generated/output_pivot.js");
2216 scriptElement.setAttribute("type", "text/javascript");
2217 headElement.appendChild(scriptElement);
2218
2219 scriptElement = generatedDocument.createElement("script");
2220
2221 scriptElement.setAttribute("defer", "defer");
2222 scriptElement.setAttribute("src", "chrome://webdeveloper/content/generated/table_sort.js");
2223 scriptElement.setAttribute("type", "text/javascript");
2224 headElement.appendChild(scriptElement);
2225
2226 // If the open tabs in background preference is set to true
2227 if(webdeveloper_getBooleanPreference("webdeveloper.open.tabs.background", true))
2228 {
2229 getBrowser().selectedTab = oldTab;
2230 }
2231 }
2232
2233 // View page information
2234 function webdeveloper_viewPageInformation(chromeLocation)
2235 {
2236 window.openDialog(chromeLocation, "webdeveloper-page-information-dialog", "chrome,dialog=no,resizable");
2237 }
2238
2239 // View the response headers
2240 function webdeveloper_viewResponseHeaders()
2241 {
2242 var headerElement = null;
2243 var oldTab = getBrowser().selectedTab;
2244 var oldURL = getBrowser().currentURI.spec;
2245 var generatedDocument = webdeveloper_generateDocument("");
2246 var bodyElement = webdeveloper_getDocumentBodyElement(generatedDocument);
2247 var preElement = null;
2248 var request = new XMLHttpRequest();
2249 var responseHeaders = null;
2250 var title = document.getElementById("webdeveloper-string-bundle").getFormattedString("webdeveloper_viewResponseHeadersTitle", [oldURL]);
2251
2252 request.open("get", oldURL, false);
2253 request.send(null);
2254
2255 responseHeaders = request.getAllResponseHeaders();
2256 generatedDocument.title = title;
2257
2258 webdeveloper_addGeneratedStyles(generatedDocument);
2259
2260 headerElement = generatedDocument.createElement("h1");
2261 headerElement.appendChild(generatedDocument.createTextNode(title));
2262 bodyElement.appendChild(headerElement);
2263
2264 preElement = generatedDocument.createElement("pre");
2265 preElement.appendChild(generatedDocument.createTextNode(responseHeaders + "\n" + request.status + " " + request.statusText));
2266 bodyElement.appendChild(preElement);
2267
2268 // If the open tabs in background preference is set to true
2269 if(webdeveloper_getBooleanPreference("webdeveloper.open.tabs.background", true))
2270 {
2271 getBrowser().selectedTab = oldTab;
2272 }
2273 }