git-svn-id: svn://euphorik.ch/pompage@45 02bbb61a-6d21-0410-aba0-cb053bdfd66a
[pompage.git] / doc / webdeveloper / webdeveloper.js
1 var webdeveloper_appliedStyles = new Array();
2 var webdeveloper_javaScriptCurrentTime = null;
3 var webdeveloper_javaScriptPreviousTime = null;
4 var webdeveloper_outlineElement = null;
5 var webdeveloper_outlinedElements = new Array();
6 var webdeveloper_selectedTab = -1;
7
8 window.addEventListener("load", webdeveloper_initialize, false);
9 window.addEventListener("unload", webdeveloper_uninitialize, false);
10
11 // Displays the about dialog
12 function webdeveloper_about()
13 {
14 window.openDialog("chrome://webdeveloper/content/about/about.xul", "webdeveloper-about-dialog", "centerscreen,chrome,modal");
15 }
16
17 // Add applied style
18 function webdeveloper_addAppliedStyle(id)
19 {
20 // If the id is not in the applied styles
21 if(!webdeveloper_contains(webdeveloper_appliedStyles, id))
22 {
23 webdeveloper_appliedStyles.push(id);
24 webdeveloper_configureElement(document.getElementById("webdeveloper-statusbar-panel"), "hidden", false);
25 }
26 }
27
28 // Add applied style if the element exists
29 function webdeveloper_addAppliedStyleByElement(id)
30 {
31 var currentDocument = webdeveloper_getContentDocument();
32
33 // If the element exists
34 if(currentDocument.getElementById(id))
35 {
36 webdeveloper_addAppliedStyle(id);
37 }
38 }
39
40 // Outlines the element in the event
41 function webdeveloper_addElementOutline(event, currentElement)
42 {
43 var element = event.target;
44
45 // If the element is set and is not the same as the current outline element
46 if(element && element != currentElement)
47 {
48 webdeveloper_removeElementOutline(currentElement);
49
50 element.style.MozOutline = "1px solid #ff0000";
51
52 return element;
53 }
54
55 return null;
56 }
57
58 // Adds the generated styles to a page
59 function webdeveloper_addGeneratedStyles(generatedDocument)
60 {
61 var headElement = webdeveloper_getDocumentHeadElement(generatedDocument);
62 var linkElement = generatedDocument.createElement("link");
63 var styleElement = generatedDocument.createElement("style");
64
65 linkElement.setAttribute("href", "chrome://webdeveloper/content/stylesheets/generated/generated_content.css");
66 linkElement.setAttribute("id", "webdeveloper-generated-content-stylesheet");
67 linkElement.setAttribute("rel", "stylesheet");
68 linkElement.setAttribute("type", "text/css");
69 headElement.appendChild(linkElement);
70
71 styleElement.setAttribute("type", "text/css");
72 styleElement.appendChild(generatedDocument.createTextNode("body, td, th { font-size: " + webdeveloper_getIntegerPreference("webdeveloper.generated.content.font.size", true) + "px !important; }"));
73 headElement.appendChild(styleElement);
74 }
75
76 // Adds the generated tools to a page
77 function webdeveloper_addGeneratedTools(generatedDocument)
78 {
79 var linkElement = generatedDocument.createElement("a");
80 var listElement = generatedDocument.createElement("ul");
81 var listItemElement = generatedDocument.createElement("li");
82 var stringBundle = document.getElementById("webdeveloper-string-bundle");
83
84 linkElement.setAttribute("href", "#");
85 linkElement.setAttribute("id", "webdeveloper-generated-tool-collapse-all");
86 linkElement.appendChild(generatedDocument.createTextNode(stringBundle.getString("webdeveloper_collapseAll")));
87 listItemElement.appendChild(linkElement);
88 listElement.appendChild(listItemElement);
89
90 linkElement = generatedDocument.createElement("a");
91 listItemElement = generatedDocument.createElement("li");
92
93 linkElement.setAttribute("href", "#");
94 linkElement.setAttribute("id", "webdeveloper-generated-tool-expand-all");
95 linkElement.appendChild(generatedDocument.createTextNode(stringBundle.getString("webdeveloper_expandAll")));
96 listItemElement.appendChild(linkElement);
97 listElement.appendChild(listItemElement);
98
99 listElement.setAttribute("id", "tools");
100 webdeveloper_getDocumentBodyElement(generatedDocument).appendChild(listElement);
101 }
102
103 // Adds a status menu item
104 function webdeveloper_addStatusMenuItem(statusMenu, menuId)
105 {
106 var originalMenuItem = document.getElementById(menuId + "-menu");
107 var statusMenuItem = document.createElement("menuitem");
108
109 statusMenuItem.setAttribute("checked", true);
110 statusMenuItem.setAttribute("class", "webdeveloper-generated-menu");
111 statusMenuItem.setAttribute("label", originalMenuItem.getAttribute("label"));
112 statusMenuItem.setAttribute("oncommand", originalMenuItem.getAttribute("oncommand"));
113 statusMenuItem.setAttribute("type", "checkbox");
114
115 statusMenu.insertBefore(statusMenuItem, document.getElementById("webdeveloper-separator-statusbar"));
116 }
117
118 // Adds the style sheet at the given location with the given id
119 function webdeveloper_addStyleSheet(location, id)
120 {
121 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
122 var documentLength = documentList.length;
123 var linkElement = null;
124 var pageDocument = null;
125
126 // Loop through the documents
127 for(var i = 0; i < documentLength; i++)
128 {
129 pageDocument = documentList[i];
130 linkElement = pageDocument.createElement("link");
131
132 linkElement.setAttribute("href", location);
133 linkElement.setAttribute("id", id);
134 linkElement.setAttribute("rel", "stylesheet");
135 linkElement.setAttribute("type", "text/css");
136
137 webdeveloper_getDocumentHeadElement(pageDocument).appendChild(linkElement);
138 }
139
140 webdeveloper_addAppliedStyle(id);
141 }
142
143 // Adjusts the position of the given element
144 function webdeveloper_adjustElementPosition(element, xPosition, yPosition, offset)
145 {
146 // If the element is set
147 if(element)
148 {
149 var clientHeight = element.clientHeight;
150 var clientWidth = element.clientWidth;
151 var contentWindow = webdeveloper_getContentWindow();
152 var innerHeight = contentWindow.innerHeight;
153 var innerWidth = contentWindow.innerWidth;
154 var offsetX = contentWindow.pageXOffset;
155 var offsetY = contentWindow.pageYOffset;
156
157 // If the x position is less than 0
158 if(xPosition < 0)
159 {
160 xPosition = 0;
161 }
162
163 // If the y position is less than 0
164 if(yPosition < 0)
165 {
166 yPosition = 0;
167 }
168
169 // If the element will fit at the x position
170 if((xPosition + clientWidth + offset + 5) < (innerWidth + offsetX))
171 {
172 element.style.left = xPosition + offset + "px";
173 }
174 else
175 {
176 element.style.left = (innerWidth + offsetX - clientWidth - offset) + "px";
177 }
178
179 // If the element will fit at the y position
180 if((yPosition + clientHeight + offset + 5) < (innerHeight + offsetY))
181 {
182 element.style.top = yPosition + offset + "px";
183 }
184 else
185 {
186 element.style.top = (innerHeight + offsetY - clientHeight - offset) + "px";
187 }
188 }
189 }
190
191 // Applies all selected style sheets
192 function webdeveloper_applyStyleSheets(reset)
193 {
194 var appliedStyle = null;
195 var appliedStyles = webdeveloper_appliedStyles.slice(0);
196 var appliedStylesLength = appliedStyles.length;
197 var element = null;
198
199 // Loop through the duplicated applied styles
200 for(var i = 0; i < appliedStylesLength; i++)
201 {
202 appliedStyle = appliedStyles[i];
203
204 // Switch on the style
205 switch(appliedStyle)
206 {
207 case "webdeveloper-add-user-style-sheet":
208 element = document.getElementById("webdeveloper-add-user-style-sheet-menu");
209 webdeveloper_configureElement(element, "checked", !reset);
210 webdeveloper_addUserStyleSheet(element);
211 break;
212 case "webdeveloper-disable-all-styles":
213 element = document.getElementById("webdeveloper-disable-all-styles-menu");
214 webdeveloper_configureElement(element, "checked", !reset);
215 webdeveloper_toggleStyles(element);
216 break;
217 case "webdeveloper-disable-browser-default-styles":
218 element = document.getElementById("webdeveloper-disable-browser-default-styles-menu");
219 webdeveloper_configureElement(element, "checked", !reset);
220 webdeveloper_toggleBrowserDefaultStyles(element);
221 break;
222 case "webdeveloper-disable-embedded-styles":
223 element = document.getElementById("webdeveloper-disable-embedded-styles-menu");
224 webdeveloper_configureElement(element, "checked", !reset);
225 webdeveloper_toggleEmbeddedStyles(element);
226 break;
227 case "webdeveloper-disable-inline-styles":
228 element = document.getElementById("webdeveloper-disable-inline-styles-menu");
229 webdeveloper_configureElement(element, "checked", !reset);
230 webdeveloper_toggleInlineStyles(element);
231 break;
232 case "webdeveloper-disable-linked-styles":
233 element = document.getElementById("webdeveloper-disable-linked-styles-menu");
234 webdeveloper_configureElement(element, "checked", !reset);
235 webdeveloper_toggleLinkedStyles(element);
236 break;
237 case "webdeveloper-disable-print-styles":
238 element = document.getElementById("webdeveloper-disable-print-styles-menu");
239 webdeveloper_configureElement(element, "checked", !reset);
240 webdeveloper_togglePrintStyles(element);
241 break;
242 case "webdeveloper-display-abbreviations":
243 element = document.getElementById("webdeveloper-display-abbreviations-menu");
244 webdeveloper_configureElement(element, "checked", !reset);
245 webdeveloper_displayAbbreviations(element);
246 break;
247 case "webdeveloper-display-access-keys":
248 element = document.getElementById("webdeveloper-display-access-keys-menu");
249 webdeveloper_configureElement(element, "checked", !reset);
250 webdeveloper_displayAccessKeys(element);
251 break;
252 case "webdeveloper-display-alt-attributes":
253 element = document.getElementById("webdeveloper-display-alt-attributes-menu");
254 webdeveloper_configureElement(element, "checked", !reset);
255 webdeveloper_displayAltAttributes(element);
256 break;
257 case "webdeveloper-display-anchors":
258 element = document.getElementById("webdeveloper-display-anchors-menu");
259 webdeveloper_configureElement(element, "checked", !reset);
260 webdeveloper_displayAnchors(element);
261 break;
262 case "webdeveloper-display-block-size":
263 element = document.getElementById("webdeveloper-display-block-size-menu");
264 webdeveloper_configureElement(element, "checked", !reset);
265 webdeveloper_displayBlockSize(element);
266 break;
267 case "webdeveloper-display-div-order":
268 element = document.getElementById("webdeveloper-display-div-order-menu");
269 webdeveloper_configureElement(element, "checked", !reset);
270 webdeveloper_displayDivOrder(element);
271 break;
272 case "webdeveloper-display-element-information":
273 element = document.getElementById("webdeveloper-display-element-information-menu");
274 webdeveloper_configureElement(element, "checked", !reset);
275 webdeveloper_displayElementInformation(element);
276 break;
277 case "webdeveloper-display-current-size-title":
278 element = document.getElementById("webdeveloper-display-current-size-title-menu");
279 webdeveloper_configureElement(element, "checked", !reset);
280 webdeveloper_displayWindowSizeInTitle(element);
281 break;
282 case "webdeveloper-display-form-details":
283 element = document.getElementById("webdeveloper-display-form-details-menu");
284 webdeveloper_configureElement(element, "checked", !reset);
285 webdeveloper_displayFormDetails(element);
286 break;
287 case "webdeveloper-display-handheld-css":
288 element = document.getElementById("webdeveloper-display-handheld-css-menu");
289 webdeveloper_configureElement(element, "checked", !reset);
290 webdeveloper_displayHandheldCSS(element);
291 break;
292 case "webdeveloper-display-id-class-details":
293 element = document.getElementById("webdeveloper-display-id-class-details-menu");
294 webdeveloper_configureElement(element, "checked", !reset);
295 webdeveloper_displayIdClassDetails(element);
296 break;
297 case "webdeveloper-display-image-dimensions":
298 element = document.getElementById("webdeveloper-display-image-dimensions-menu");
299 webdeveloper_configureElement(element, "checked", !reset);
300 webdeveloper_displayImageDimensions(element);
301 break;
302 case "webdeveloper-display-image-file-sizes":
303 element = document.getElementById("webdeveloper-display-image-file-sizes-menu");
304 webdeveloper_configureElement(element, "checked", !reset);
305 webdeveloper_displayImageFileSizes(element);
306 break;
307 case "webdeveloper-display-image-paths":
308 element = document.getElementById("webdeveloper-display-image-paths-menu");
309 webdeveloper_configureElement(element, "checked", !reset);
310 webdeveloper_displayImagePaths(element);
311 break;
312 case "webdeveloper-display-line-guides":
313 element = document.getElementById("webdeveloper-display-line-guides-menu");
314 webdeveloper_configureElement(element, "checked", !reset);
315 webdeveloper_displayLineGuides(element);
316 break;
317 case "webdeveloper-display-link-details":
318 element = document.getElementById("webdeveloper-display-link-details-menu");
319 webdeveloper_configureElement(element, "checked", !reset);
320 webdeveloper_displayLinkDetails(element);
321 break;
322 case "webdeveloper-display-object-information":
323 element = document.getElementById("webdeveloper-display-object-information-menu");
324 webdeveloper_configureElement(element, "checked", !reset);
325 webdeveloper_displayObjectInformation(element);
326 break;
327 case "webdeveloper-display-print-css":
328 element = document.getElementById("webdeveloper-display-print-css-menu");
329 webdeveloper_configureElement(element, "checked", !reset);
330 webdeveloper_displayPrintCSS(element);
331 break;
332 case "webdeveloper-display-ruler":
333 element = document.getElementById("webdeveloper-display-ruler-menu");
334 webdeveloper_configureElement(element, "checked", !reset);
335 webdeveloper_displayRuler(element);
336 break;
337 case "webdeveloper-display-stack-levels":
338 element = document.getElementById("webdeveloper-display-stack-levels-menu");
339 webdeveloper_configureElement(element, "checked", !reset);
340 webdeveloper_displayStackLevels(element);
341 break;
342 case "webdeveloper-display-tab-index":
343 element = document.getElementById("webdeveloper-display-tab-index-menu");
344 webdeveloper_configureElement(element, "checked", !reset);
345 webdeveloper_displayTabIndex(element);
346 break;
347 case "webdeveloper-display-table-depth":
348 element = document.getElementById("webdeveloper-display-table-depth-menu");
349 webdeveloper_configureElement(element, "checked", !reset);
350 webdeveloper_displayTableDepth(element);
351 break;
352 case "webdeveloper-display-table-information":
353 element = document.getElementById("webdeveloper-display-table-information-menu");
354 webdeveloper_configureElement(element, "checked", !reset);
355 webdeveloper_displayTableInformation(element);
356 break;
357 case "webdeveloper-display-title-attributes":
358 element = document.getElementById("webdeveloper-display-title-attributes-menu");
359 webdeveloper_configureElement(element, "checked", !reset);
360 webdeveloper_displayTitleAttributes(element);
361 break;
362 case "webdeveloper-display-topographic-information":
363 element = document.getElementById("webdeveloper-display-topographic-information-menu");
364 webdeveloper_configureElement(element, "checked", !reset);
365 webdeveloper_displayTopographicInformation(element);
366 break;
367 case "webdeveloper-display-window-size-title":
368 element = document.getElementById("webdeveloper-display-window-size-title-menu");
369 webdeveloper_configureElement(element, "checked", !reset);
370 webdeveloper_displayWindowSizeInTitle(element);
371 break;
372 case "webdeveloper-hide-background-images":
373 element = document.getElementById("webdeveloper-hide-background-images-menu");
374 webdeveloper_configureElement(element, "checked", !reset);
375 webdeveloper_hideBackgroundImages(element);
376 break;
377 case "webdeveloper-hide-images":
378 element = document.getElementById("webdeveloper-hide-images-menu");
379 webdeveloper_configureElement(element, "checked", !reset);
380 webdeveloper_hideImages(element, "webdeveloper-hide-images");
381 break;
382 case "webdeveloper-linearize-page":
383 element = document.getElementById("webdeveloper-linearize-page-menu");
384 webdeveloper_configureElement(element, "checked", !reset);
385 webdeveloper_linearizePage(element);
386 break;
387 case "webdeveloper-make-images-invisible":
388 element = document.getElementById("webdeveloper-make-images-invisible-menu");
389 webdeveloper_configureElement(element, "checked", !reset);
390 webdeveloper_makeImagesInvisible(element, "webdeveloper-make-images-invisible");
391 break;
392 case "webdeveloper-outline-absolute-positioned-elements":
393 element = document.getElementById("webdeveloper-outline-absolute-positioned-elements-menu");
394 webdeveloper_configureElement(element, "checked", !reset);
395 webdeveloper_outlinePositionedElements("absolute", element);
396 break;
397 case "webdeveloper-outline-all-images":
398 element = document.getElementById("webdeveloper-outline-all-images-menu");
399 webdeveloper_configureElement(element, "checked", !reset);
400 webdeveloper_outlineAllImages(element);
401 break;
402 case "webdeveloper-outline-all-tables":
403 element = document.getElementById("webdeveloper-outline-all-tables-menu");
404 webdeveloper_configureElement(element, "checked", !reset);
405 webdeveloper_outlineTables(element);
406 break;
407 case "webdeveloper-outline-background-images":
408 element = document.getElementById("webdeveloper-outline-background-images-menu");
409 webdeveloper_configureElement(element, "checked", !reset);
410 webdeveloper_outlineBackgroundImages(element, true);
411 break;
412 case "webdeveloper-outline-block-level-elements":
413 element = document.getElementById("webdeveloper-outline-block-level-elements-menu");
414 webdeveloper_configureElement(element, "checked", !reset);
415 webdeveloper_outlineBlockLevelElements(element);
416 break;
417 case "webdeveloper-outline-current-element":
418 element = document.getElementById("webdeveloper-outline-current-element-menu");
419 webdeveloper_configureElement(element, "checked", !reset);
420 webdeveloper_outlineCurrentElement(element);
421 break;
422 case "webdeveloper-outline-custom-elements":
423 element = document.getElementById("webdeveloper-outline-custom-elements-menu");
424 webdeveloper_configureElement(element, "checked", !reset);
425 webdeveloper_outlineElements(element);
426 break;
427 case "webdeveloper-outline-deprecated-elements":
428 element = document.getElementById("webdeveloper-outline-deprecated-elements-menu");
429 webdeveloper_configureElement(element, "checked", !reset);
430 webdeveloper_outlineDeprecatedElements(element);
431 break;
432 case "webdeveloper-outline-external-links":
433 element = document.getElementById("webdeveloper-outline-external-links-menu");
434 webdeveloper_configureElement(element, "checked", !reset);
435 webdeveloper_outlineExternalLinks(element);
436 break;
437 case "webdeveloper-outline-fixed-positioned-elements":
438 element = document.getElementById("webdeveloper-outline-fixed-positioned-elements-menu");
439 webdeveloper_configureElement(element, "checked", !reset);
440 webdeveloper_outlinePositionedElements("fixed", element);
441 break;
442 case "webdeveloper-outline-floated-elements":
443 element = document.getElementById("webdeveloper-outline-floated-elements-menu");
444 webdeveloper_configureElement(element, "checked", !reset);
445 webdeveloper_outlineFloatedElements(element);
446 break;
447 case "webdeveloper-outline-frames":
448 element = document.getElementById("webdeveloper-outline-frames-menu");
449 webdeveloper_configureElement(element, "checked", !reset);
450 webdeveloper_outlineFrames(element);
451 break;
452 case "webdeveloper-outline-headings":
453 element = document.getElementById("webdeveloper-outline-headings-menu");
454 webdeveloper_configureElement(element, "checked", !reset);
455 webdeveloper_outlineHeadings(element);
456 break;
457 case "webdeveloper-outline-images-with-adjusted-dimensions":
458 element = document.getElementById("webdeveloper-outline-images-with-adjusted-dimensions-menu");
459 webdeveloper_configureElement(element, "checked", !reset);
460 webdeveloper_outlineImagesWithAdjustedDimensions(element);
461 break;
462 case "webdeveloper-outline-images-with-empty-alt-attributes":
463 element = document.getElementById("webdeveloper-outline-images-with-empty-alt-attributes-menu");
464 webdeveloper_configureElement(element, "checked", !reset);
465 webdeveloper_outlineImagesWithEmptyAltAttributes(element);
466 break;
467 case "webdeveloper-outline-images-with-oversized-dimensions":
468 element = document.getElementById("webdeveloper-outline-images-with-oversized-dimensions-menu");
469 webdeveloper_configureElement(element, "checked", !reset);
470 webdeveloper_outlineImagesWithOversizedDimensions(element);
471 break;
472 case "webdeveloper-outline-images-without-alt-attributes":
473 element = document.getElementById("webdeveloper-outline-images-without-alt-attributes-menu");
474 webdeveloper_configureElement(element, "checked", !reset);
475 webdeveloper_outlineImagesWithoutAltAttributes(element);
476 break;
477 case "webdeveloper-outline-images-without-dimensions":
478 element = document.getElementById("webdeveloper-outline-images-without-dimensions-menu");
479 webdeveloper_configureElement(element, "checked", !reset);
480 webdeveloper_outlineImagesWithoutDimensions(element);
481 break;
482 case "webdeveloper-outline-images-without-title-attributes":
483 element = document.getElementById("webdeveloper-outline-images-without-title-attributes-menu");
484 webdeveloper_configureElement(element, "checked", !reset);
485 webdeveloper_outlineImagesWithoutTitleAttributes(element);
486 break;
487 case "webdeveloper-outline-links-with-ping-attributes":
488 element = document.getElementById("webdeveloper-outline-links-with-ping-attributes-menu");
489 webdeveloper_configureElement(element, "checked", !reset);
490 webdeveloper_outlineLinksWithPingAttributes(element);
491 break;
492 case "webdeveloper-outline-links-without-title-attributes":
493 element = document.getElementById("webdeveloper-outline-links-without-title-attributes-menu");
494 webdeveloper_configureElement(element, "checked", !reset);
495 webdeveloper_outlineLinksWithoutTitleAttributes(element);
496 break;
497 case "webdeveloper-outline-relative-positioned-elements":
498 element = document.getElementById("webdeveloper-outline-relative-positioned-elements-menu");
499 webdeveloper_configureElement(element, "checked", !reset);
500 webdeveloper_outlinePositionedElements("relative", element);
501 break;
502 case "webdeveloper-outline-table-cells":
503 element = document.getElementById("webdeveloper-outline-table-cells-menu");
504 webdeveloper_configureElement(element, "checked", !reset);
505 webdeveloper_outlineTableCells(element);
506 break;
507 case "webdeveloper-replace-images-with-alt-attributes":
508 element = document.getElementById("webdeveloper-replace-images-with-alt-attributes-menu");
509 webdeveloper_configureElement(element, "checked", !reset);
510 webdeveloper_replaceImagesWithAltAttributes(element);
511 break;
512 case "webdeveloper-show-comments":
513 element = document.getElementById("webdeveloper-show-comments-menu");
514 webdeveloper_configureElement(element, "checked", !reset);
515 webdeveloper_toggleComments(element);
516 break;
517 case "webdeveloper-small-screen-rendering":
518 element = document.getElementById("webdeveloper-small-screen-rendering-menu");
519 webdeveloper_configureElement(element, "checked", !reset);
520 webdeveloper_smallScreenRendering(element);
521 break;
522 case "webdeveloper-use-border-box-model":
523 element = document.getElementById("webdeveloper-use-border-box-model-menu");
524 webdeveloper_configureElement(element, "checked", !reset);
525 webdeveloper_toggleBorderBoxModel(element);
526 break;
527 case "webdeveloper-view-style-information":
528 element = document.getElementById("webdeveloper-view-style-information-menu");
529 webdeveloper_configureElement(element, "checked", !reset);
530 webdeveloper_viewStyleInformation(element);
531 break;
532 }
533 }
534 }
535
536 // Changes the options
537 function webdeveloper_changeOptions()
538 {
539 var element = null;
540 var hideContextMenuPreference = webdeveloper_getBooleanPreference("webdeveloper.context.hide", true);
541 var hideMenuPreference = webdeveloper_getBooleanPreference("webdeveloper.menu.hide", true);
542 var toolbar = document.getElementById("webdeveloper-toolbar");
543
544 // If the toolbar exists
545 if(toolbar)
546 {
547 var toolbarVisible = window.toolbar.visible;
548
549 // If the toolbar is visible
550 if(toolbarVisible)
551 {
552 var toolbarButtons = toolbar.getElementsByTagName("toolbarbutton");
553 var toolbarButtonsLength = toolbarButtons.length;
554 var toolbarPreference = webdeveloper_getStringPreference("webdeveloper.toolbar.icons", true);
555
556 toolbar.setAttribute("mode", toolbarPreference);
557
558 // If the toolbar preference is set to icons
559 if(toolbarPreference == "icons")
560 {
561 toolbarPreference = "pictures";
562 }
563
564 toolbar.setAttribute("buttonstyle", toolbarPreference);
565
566 // Loop through the toolbar buttons
567 for(var i = 0; i < toolbarButtonsLength; i++)
568 {
569 toolbarButtons[i].setAttribute("buttonstyle", toolbarPreference);
570 }
571
572 // If the toolbar preference is not set to text
573 if(toolbarPreference != "text")
574 {
575 element = document.getElementById("webdeveloper-javascript-statusbar");
576
577 // If the element exists
578 if(element)
579 {
580 element.removeAttribute("label");
581 }
582
583 element = document.getElementById("webdeveloper-render-mode-statusbar");
584
585 // If the element exists
586 if(element)
587 {
588 element.removeAttribute("label");
589 }
590 }
591 }
592 }
593
594 element = document.getElementById("webdeveloper-menu");
595
596 // If the element exists
597 if(element)
598 {
599 element.setAttribute("hidden", hideMenuPreference);
600 }
601
602 element = document.getElementById("webdeveloper-context");
603
604 // If the element exists
605 if(element)
606 {
607 element.setAttribute("hidden", hideContextMenuPreference);
608 }
609
610 element = document.getElementById("webdeveloper-context-separator1");
611
612 // If the element exists
613 if(element)
614 {
615 element.setAttribute("hidden", hideContextMenuPreference);
616 }
617 }
618
619 // Clears the applied styles
620 function webdeveloper_clearAppliedStyles()
621 {
622 webdeveloper_appliedStyles = new Array();
623
624 webdeveloper_configureElement(document.getElementById("webdeveloper-statusbar-panel"), "hidden", true);
625 }
626
627 // Configures the element with the given attribute and value
628 function webdeveloper_configureElement(element, attribute, value)
629 {
630 // If the element exists
631 if(element)
632 {
633 // If the value is set
634 if(value)
635 {
636 element.setAttribute(attribute, value);
637 }
638 else
639 {
640 element.removeAttribute(attribute);
641 }
642 }
643 }
644
645 // Configures the element based on whether the applied style exists
646 function webdeveloper_configureElementByAppliedStyle(element, attribute, id)
647 {
648 webdeveloper_configureElement(element, attribute, webdeveloper_contains(webdeveloper_appliedStyles, id));
649 }
650
651 // Configure the keyboard shortcuts
652 function webdeveloper_configureKeyboardShortcuts(reset)
653 {
654 var bookmarklet = null;
655 var id = null;
656 var key = null;
657 var keyElement = null;
658 var keyPreference = null;
659 var keyPreferenceValue = null;
660 var keys = null;
661 var keySet = null;
662 var keysLength = null;
663 var mainDocument = null;
664 var path = null;
665 var success = false;
666 var toolCount = webdeveloper_getIntegerPreference("webdeveloper.tool.count", true);
667 var url = null;
668 var viewSourceWithCount = webdeveloper_getIntegerPreference("webdeveloper.view.source.with.count", true);
669 var windowEnumeration = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator).getEnumerator("navigator:browser");
670
671 // Loop through the open windows
672 while(windowEnumeration.hasMoreElements())
673 {
674 mainDocument = windowEnumeration.getNext().document;
675
676 // If a main document was found
677 if(mainDocument)
678 {
679 keySet = mainDocument.getElementById("mainKeyset");
680
681 // If the key set was not found
682 if(!keySet)
683 {
684 keySet = mainDocument.getElementById("navKeys");
685 }
686
687 // If the key set was found
688 if(keySet)
689 {
690 keys = keySet.childNodes;
691 keysLength = keys.length;
692
693 // Loop through the keys
694 for(var i = 0; i < keysLength; i++)
695 {
696 key = keys.item(i);
697
698 // If the key has an id starting with webdeveloper
699 if(key.hasAttribute("id") && key.getAttribute("id").indexOf("webdeveloper-") == 0)
700 {
701 id = key.getAttribute("id").split("-").join(".");
702
703 // If the key preference is set
704 if(webdeveloper_isPreferenceSet(id))
705 {
706 keyPreferenceValue = webdeveloper_getStringPreference(id, true);
707
708 key.setAttribute("key", keyPreferenceValue);
709
710 // If the key preference value is set
711 if(keyPreferenceValue)
712 {
713 key.setAttribute("disabled", false);
714 }
715 else
716 {
717 key.setAttribute("disabled", true);
718 }
719 }
720 else if(!reset)
721 {
722 webdeveloper_setStringPreference(id, key.getAttribute("key"));
723 }
724
725 success = true;
726 }
727 }
728
729 // Loop through the possible tools
730 for(i = 1; i <= toolCount; i++)
731 {
732 bookmarklet = "webdeveloper.tool." + i + ".bookmarklet";
733 keyPreference = "webdeveloper.tool." + i + ".key";
734 keyElement = mainDocument.getElementById(keyPreference);
735 path = "webdeveloper.tool." + i + ".path";
736 url = "webdeveloper.tool." + i + ".url";
737
738 // If the bookmarklet, path or URL preference and key preference is set
739 if((webdeveloper_isPreferenceSet(bookmarklet) || webdeveloper_isPreferenceSet(path) || webdeveloper_isPreferenceSet(url)) && webdeveloper_isPreferenceSet(keyPreference))
740 {
741 keyPreferenceValue = webdeveloper_getStringPreference(keyPreference, true);
742
743 // If the key preference value is set
744 if(keyPreferenceValue)
745 {
746 key = mainDocument.createElement("key");
747
748 key.setAttribute("id", keyPreference);
749 key.setAttribute("key", keyPreferenceValue);
750 key.setAttribute("modifiers", "accel,shift");
751
752 // If the bookmarklet preference is set
753 if(webdeveloper_getStringPreference(bookmarklet, true))
754 {
755 key.setAttribute("oncommand", "webdeveloper_runBookmarklet('" + encodeURIComponent(webdeveloper_getStringPreference(bookmarklet, true)).replace(new RegExp("'", "gi"), "\\'") + "')");
756 }
757 else if(webdeveloper_getStringPreference(path, true))
758 {
759 key.setAttribute("oncommand", "webdeveloper_loadApplicationWithURL('" + webdeveloper_getStringPreference(path, true).replace(/\\/gi, "\\\\") + "', getBrowser().currentURI.spec)");
760 }
761 else
762 {
763 key.setAttribute("oncommand", "webdeveloper_loadURL('" + webdeveloper_getStringPreference(url, true) + "' + encodeURIComponent(getBrowser().currentURI.spec))");
764 }
765
766 keySet.appendChild(key);
767 }
768 }
769 else
770 {
771 webdeveloper_removeElement(keyElement);
772 }
773 }
774
775 // Loop through the possible view source with options
776 for(i = 1; i <= viewSourceWithCount; i++)
777 {
778 keyPreference = "webdeveloper.view.source.with." + i + ".key";
779 keyElement = mainDocument.getElementById(keyPreference);
780 path = "webdeveloper.view.source.with." + i + ".path";
781
782 // If the path and key preferences are set
783 if(webdeveloper_isPreferenceSet(path) && webdeveloper_isPreferenceSet(keyPreference))
784 {
785 keyPreferenceValue = webdeveloper_getStringPreference(keyPreference, true);
786
787 // If the key preference value is set
788 if(keyPreferenceValue)
789 {
790 key = mainDocument.createElement("key");
791
792 key.setAttribute("id", keyPreference);
793 key.setAttribute("key", keyPreferenceValue);
794 key.setAttribute("modifiers", "accel,shift");
795 key.setAttribute("oncommand", "webdeveloper_loadApplicationWithSource('" + webdeveloper_getStringPreference(path, true).replace(/\\/gi, "\\\\") + "')");
796 keySet.appendChild(key);
797 }
798 }
799 else
800 {
801 webdeveloper_removeElement(keyElement);
802 }
803 }
804 }
805 }
806 }
807
808 return success;
809 }
810
811 // Copies the elements ancestors to the clipboard
812 function webdeveloper_copyElementAncestors(event)
813 {
814 var informationElement = document.getElementById("webdeveloper-information");
815 var keyCode = event.charCode;
816
817 // If the information element is set and the key code is set and is 99
818 if(informationElement && keyCode && keyCode == 99)
819 {
820 Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper).copyString(informationElement.value);
821
822 event.preventDefault();
823 }
824 }
825
826 // Disables the given preference
827 function webdeveloper_disablePreference(element, preference)
828 {
829 // If the element and preference are set
830 if(element && preference)
831 {
832 webdeveloper_setBooleanPreference(preference, !element.getAttribute("checked"));
833 }
834 }
835
836 // Displays the elements ancestors in the information bar
837 function webdeveloper_displayElementAncestors(event)
838 {
839 var eventTarget = event.target;
840 var informationElement = document.getElementById("webdeveloper-information");
841
842 // If there is a target and the information element is set
843 if(eventTarget && informationElement)
844 {
845 var tagName = eventTarget.tagName;
846
847 // If the tag name is set and does not equal scrollbar
848 if(tagName && tagName != "scrollbar")
849 {
850 var ancestorList = webdeveloper_getElementAncestors(eventTarget);
851 var ancestorLength = ancestorList.length;
852 var ancestorText = "";
853
854 // Loop through the ancestors
855 for(var i = 0; i < ancestorLength; i++)
856 {
857 ancestorText += webdeveloper_getElementDescription(ancestorList[i]) + " > ";
858 }
859
860 informationElement.value = ancestorText + webdeveloper_getElementDescription(eventTarget);
861
862 webdeveloper_configureElement(document.getElementById("webdeveloper-information-text-toolbar"), "hidden", false);
863
864 event.preventDefault();
865 }
866 }
867 }
868
869 // Enables the given preference
870 function webdeveloper_enablePreference(element, preference)
871 {
872 // If the element and preference are set
873 if(element && preference)
874 {
875 var checked = element.getAttribute("checked");
876
877 // If the element is checked (explicit check required)
878 if(checked)
879 {
880 webdeveloper_setBooleanPreference(preference, true);
881 }
882 else
883 {
884 webdeveloper_setBooleanPreference(preference, false);
885 }
886 }
887 }
888
889 // Formats a file size
890 function webdeveloper_formatFileSize(fileSize)
891 {
892 // If the file size is set
893 if(fileSize)
894 {
895 var stringBundle = document.getElementById("webdeveloper-string-bundle");
896
897 // If the file size is greater than a kilobyte
898 if(fileSize > 1024)
899 {
900 return Math.round(fileSize / 1024) + " " + stringBundle.getString("webdeveloper_kilobytes");
901 }
902 else
903 {
904 return fileSize + " " + stringBundle.getString("webdeveloper_bytes");
905 }
906 }
907 else
908 {
909 return "";
910 }
911 }
912
913 // Generates a document in a new tab or window
914 function webdeveloper_generateDocument(url)
915 {
916 var generatedPage = null;
917 var request = new XMLHttpRequest();
918
919 // If the open tabs preference is set to true
920 if(webdeveloper_getBooleanPreference("webdeveloper.open.tabs", true))
921 {
922 getBrowser().selectedTab = getBrowser().addTab(url);
923
924 generatedPage = window;
925 }
926 else
927 {
928 generatedPage = window.open(url);
929 }
930
931 // This must be done to make generated content render
932 request.open("get", "about:blank", false);
933 request.send(null);
934
935 return generatedPage.content.document;
936 }
937
938 // Returns a description for an element
939 function webdeveloper_getElementDescription(element)
940 {
941 var description = null;
942
943 // If the element and tag name are set
944 if(element && element.tagName)
945 {
946 description = element.tagName.toLowerCase();
947
948 // If the element has an id attribute
949 if(element.hasAttribute("id"))
950 {
951 description += " #" + element.getAttribute("id");
952 }
953
954 // If the element has a class attribute
955 if(element.hasAttribute("class"))
956 {
957 description += " ." + element.getAttribute("class");
958 }
959 }
960
961 return description;
962 }
963
964 // Opens the help
965 function webdeveloper_help()
966 {
967 webdeveloper_loadURL("http://chrispederick.com/work/web-developer/documentation/");
968 }
969
970 // Initializes the extension
971 function webdeveloper_initialize(event)
972 {
973 var windowContent = window.document.getElementById("content");
974
975 // If the window content is set
976 if(windowContent)
977 {
978 var consoleService = Components.classes["@mozilla.org/consoleservice;1"].getService().QueryInterface(Components.interfaces.nsIConsoleService);
979 var dashboard = document.getElementById("webdeveloper-dashboard");
980 var tabBox = windowContent.mTabBox;
981
982 webdeveloper_upgrade();
983 webdeveloper_setupDefaultOptions();
984 webdeveloper_setupLocalizedOptions();
985 webdeveloper_configureKeyboardShortcuts(false);
986 webdeveloper_changeOptions();
987
988 windowContent.addEventListener("load", webdeveloper_pageLoad, true);
989 windowContent.addEventListener("unload", webdeveloper_pageUnload, true);
990
991 // If the dashboard is set
992 if(dashboard)
993 {
994 webdeveloper_setupDashboardPosition(webdeveloper_getStringPreference("webdeveloper.dashboard.position", true));
995 }
996
997 // If the console service is set
998 if(consoleService)
999 {
1000 consoleService.registerListener(WebDeveloperErrorConsoleListener);
1001 }
1002
1003 // If the tab box is set
1004 if(tabBox)
1005 {
1006 tabBox.addEventListener("select", webdeveloper_tabSelect, false);
1007 }
1008
1009 // Try to remove the event listener
1010 try
1011 {
1012 window.removeEventListener("load", webdeveloper_initialize, false);
1013 }
1014 catch(exception)
1015 {
1016 // Do nothing
1017 }
1018 }
1019 }
1020
1021 // Returns true if the DOM Inspector is available
1022 function webdeveloper_isDOMInspectorAvailable()
1023 {
1024 try
1025 {
1026 Components.classes["@mozilla.org/inspector/dom-utils;1"].getService(Components.interfaces.inIDOMUtils);
1027
1028 return true;
1029 }
1030 catch(exception)
1031 {
1032 return false;
1033 }
1034 }
1035
1036 // Returns true if the information text toolbar is in use
1037 function webdeveloper_isInformationTextToolbarInUse()
1038 {
1039 // If one of the features that use the information text toolbar is enabled
1040 if(webdeveloper_contains(webdeveloper_appliedStyles, "webdeveloper-display-element-information") || webdeveloper_contains(webdeveloper_appliedStyles, "webdeveloper-outline-current-element") || webdeveloper_contains(webdeveloper_appliedStyles, "webdeveloper-view-style-information"))
1041 {
1042 return true;
1043 }
1044
1045 return false;
1046 }
1047
1048 // Loads the given URL
1049 function webdeveloper_loadURL(url)
1050 {
1051 var oldTab = getBrowser().selectedTab;
1052
1053 webdeveloper_generateDocument(url);
1054
1055 // If the open tabs in background preference is set to true
1056 if(webdeveloper_getBooleanPreference("webdeveloper.open.tabs.background", true))
1057 {
1058 getBrowser().selectedTab = oldTab;
1059 }
1060 }
1061
1062 // Logs a debug message to the error console
1063 function webdeveloper_logDebug(message)
1064 {
1065 // If the debug preference is set
1066 if(webdeveloper_getBooleanPreference("webdeveloper.debug", true))
1067 {
1068 Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService).logStringMessage("Web Developer: " + message);
1069 webdeveloper_openErrorConsole(false);
1070 }
1071 }
1072
1073 // Opens the error console
1074 function webdeveloper_openErrorConsole(toggle)
1075 {
1076 // If the open error console in dashboard preference is set to true
1077 if(webdeveloper_getBooleanPreference("webdeveloper.error.console.dashboard", true))
1078 {
1079 var errorConsole = document.getElementById("webdeveloper-string-bundle").getString("webdeveloper_errorConsole");
1080
1081 // If the error console is already open in the dashboard
1082 if(webdeveloper_isOpenInDashboard(errorConsole))
1083 {
1084 // If toggling the console
1085 if(toggle)
1086 {
1087 webdeveloper_closeInDashboard(errorConsole);
1088 }
1089 else
1090 {
1091 webdeveloper_selectInDashboard(errorConsole);
1092 }
1093 }
1094 else
1095 {
1096 webdeveloper_openInDashboard(errorConsole, "chrome://global/content/console.xul");
1097 }
1098 }
1099 else
1100 {
1101 webdeveloper_javaScriptPreviousTime = webdeveloper_javaScriptCurrentTime;
1102 webdeveloper_javaScriptCurrentTime = new Date().getTime();
1103
1104 // If the previous time is not set or the current time is greater than a second different from the previous time
1105 if(!webdeveloper_javaScriptPreviousTime || webdeveloper_javaScriptCurrentTime - webdeveloper_javaScriptPreviousTime > 1500)
1106 {
1107 toJavaScriptConsole();
1108 }
1109 }
1110 }
1111
1112 // Opens a toolbar button automatically if another toolbar button is open on the toolbar
1113 function webdeveloper_openToolbarButton(currentToolbarButton)
1114 {
1115 // If the toolbar button is set and is not open
1116 if(currentToolbarButton && !currentToolbarButton.open)
1117 {
1118 var toolbarButton = null;
1119 var toolbarButtons = currentToolbarButton.parentNode.getElementsByTagName("toolbarbutton");
1120 var toolbarButtonsLength = toolbarButtons.length;
1121
1122 // Loop through the toolbar buttons
1123 for(var i = 0; i < toolbarButtonsLength; i++)
1124 {
1125 toolbarButton = toolbarButtons.item(i);
1126
1127 // If the toolbar button is set, is not the same toolbar button and is open
1128 if(toolbarButton && toolbarButton != currentToolbarButton && toolbarButton.open)
1129 {
1130 toolbarButton.open = false;
1131 currentToolbarButton.open = true;
1132
1133 break;
1134 }
1135 }
1136 }
1137 }
1138
1139 // Displays the options dialog
1140 function webdeveloper_options(openPage)
1141 {
1142 // If an open page is set
1143 if(openPage)
1144 {
1145 window.openDialog("chrome://webdeveloper/content/options/options.xul", "webdeveloper-options-dialog", "centerscreen,chrome,modal,resizable", openPage);
1146 }
1147 else
1148 {
1149 window.openDialog("chrome://webdeveloper/content/options/options.xul", "webdeveloper-options-dialog", "centerscreen,chrome,modal,resizable");
1150 }
1151
1152 webdeveloper_changeOptions();
1153 }
1154
1155 // Handles the page being loaded
1156 function webdeveloper_pageLoad(event)
1157 {
1158 var eventTarget = event.target;
1159
1160 // If the browser is the target
1161 if(eventTarget && eventTarget == getBrowser())
1162 {
1163 var contentDocument = eventTarget.contentDocument;
1164
1165 // If the content document is set
1166 if(contentDocument)
1167 {
1168 // Try to get the original target
1169 try
1170 {
1171 var loadedDocument = event.originalTarget;
1172
1173 // If the loaded document is set and has the same URI as the content document
1174 if(loadedDocument && contentDocument.documentURI == loadedDocument.documentURI)
1175 {
1176 // Reset the display line guides and display ruler features
1177 webdeveloper_configureElement(document.getElementById("webdeveloper-line-guides-toolbar"), "hidden", true);
1178 webdeveloper_configureElement(document.getElementById("webdeveloper-ruler-toolbar"), "hidden", true);
1179 webdeveloper_removeAppliedStyle("webdeveloper-display-line-guides");
1180 webdeveloper_removeAppliedStyle("webdeveloper-display-ruler");
1181
1182 webdeveloper_updateMetaRedirects(eventTarget.selectedBrowser);
1183 webdeveloper_updateRenderMode(contentDocument);
1184
1185 // If the persist features preference is set and is true
1186 if(webdeveloper_getBooleanPreference("webdeveloper.persist.features", true))
1187 {
1188 webdeveloper_applyStyleSheets(false);
1189 }
1190 else
1191 {
1192 // Reset the information text toolbar
1193 webdeveloper_configureElement(document.getElementById("webdeveloper-information-text-toolbar"), "hidden", true);
1194
1195 webdeveloper_clearAppliedStyles();
1196 }
1197 }
1198 }
1199 catch(exception)
1200 {
1201 // Do nothing
1202 }
1203 }
1204 }
1205 }
1206
1207 // Handles the page being unloaded
1208 function webdeveloper_pageUnload(event)
1209 {
1210 var eventTarget = event.target;
1211
1212 // Try to get the original target
1213 try
1214 {
1215 var originalTarget = event.originalTarget;
1216
1217 // If the page is the target and the URI matches
1218 if(eventTarget && originalTarget && eventTarget.contentDocument && eventTarget == getBrowser() && eventTarget.contentDocument.documentURI == originalTarget.documentURI)
1219 {
1220 webdeveloper_updateCSSStatus();
1221 webdeveloper_updateJavaScriptStatus();
1222 }
1223 }
1224 catch(exception)
1225 {
1226 // Do nothing
1227 }
1228 }
1229
1230 // Remove applied style
1231 function webdeveloper_removeAppliedStyle(id)
1232 {
1233 // If the id is in the applied styles
1234 if(webdeveloper_contains(webdeveloper_appliedStyles, id))
1235 {
1236 var appliedStylesLength = webdeveloper_appliedStyles.length;
1237
1238 // Loop through the applied styles
1239 for(var i = 0; i < appliedStylesLength; i++)
1240 {
1241 // If this style sheet is in the applied styles
1242 if(webdeveloper_appliedStyles[i] == id)
1243 {
1244 webdeveloper_appliedStyles.splice(i, 1);
1245 break;
1246 }
1247 }
1248
1249 // If the only applied style has been removed
1250 if(webdeveloper_appliedStyles.length == 0)
1251 {
1252 webdeveloper_configureElement(document.getElementById("webdeveloper-statusbar-panel"), "hidden", true);
1253 }
1254 }
1255 }
1256
1257 // Removes the outline from an element
1258 function webdeveloper_removeElementOutline(element)
1259 {
1260 // If the element is set
1261 if(element)
1262 {
1263 element.style.MozOutline = "";
1264
1265 // If the element has an empty style attribute
1266 if(element.hasAttribute("style") && element.getAttribute("style") == "")
1267 {
1268 element.removeAttribute("style");
1269 }
1270 }
1271 }
1272
1273 // Removes all the generated menu items from the menu
1274 function webdeveloper_removeGeneratedMenuItems(menu)
1275 {
1276 var generatedMenuItems = new Array();
1277 var menuItem = null;
1278 var menuItems = menu.childNodes;
1279 var menuItemsLength = menuItems.length;
1280
1281 // Loop through the menu items
1282 for(var i = 0; i < menuItemsLength; i++)
1283 {
1284 menuItem = menuItems.item(i);
1285
1286 // If this is a generated menu item
1287 if(menuItem && menuItem.hasAttribute("class") && menuItem.getAttribute("class") == "webdeveloper-generated-menu")
1288 {
1289 generatedMenuItems.push(menuItem);
1290 }
1291 }
1292
1293 menuItemsLength = generatedMenuItems.length;
1294
1295 // Loop through the generated menu items
1296 for(i = 0; i < menuItemsLength; i++)
1297 {
1298 menu.removeChild(generatedMenuItems[i]);
1299 }
1300 }
1301
1302 // Removes the style sheet with the given id
1303 function webdeveloper_removeStyleSheet(id)
1304 {
1305 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
1306 var documentLength = documentList.length;
1307
1308 // Loop through the documents
1309 for(var i = 0; i < documentLength; i++)
1310 {
1311 webdeveloper_removeElement(documentList[i].getElementById(id));
1312 }
1313
1314 webdeveloper_removeAppliedStyle(id);
1315 }
1316
1317 // Resets the CSS status button
1318 function webdeveloper_resetCSSStatus()
1319 {
1320 var cssButton = document.getElementById("webdeveloper-css-statusbar");
1321
1322 webdeveloper_javaScriptCurrentTime = null;
1323 webdeveloper_javaScriptPreviousTime = null;
1324
1325 // If the CSS button exists
1326 if(cssButton)
1327 {
1328 // If the CSS button has a class attribute
1329 if(cssButton.hasAttribute("class"))
1330 {
1331 cssButton.removeAttribute("class");
1332 }
1333
1334 // If the CSS button has a tooltip text attribute
1335 if(cssButton.hasAttribute("tooltiptext"))
1336 {
1337 cssButton.removeAttribute("tooltiptext");
1338 }
1339
1340 // If the toolbar preference is set to text and the CSS button has a label attribute
1341 if(webdeveloper_getStringPreference("webdeveloper.toolbar.icons", true) == "text" && cssButton.hasAttribute("label"))
1342 {
1343 cssButton.removeAttribute("label");
1344 }
1345 }
1346 }
1347
1348 // Resets the JavaScript status button
1349 function webdeveloper_resetJavaScriptStatus()
1350 {
1351 var javaScriptButton = document.getElementById("webdeveloper-javascript-statusbar");
1352
1353 webdeveloper_javaScriptCurrentTime = null;
1354 webdeveloper_javaScriptPreviousTime = null;
1355
1356 // If the JavaScript button exists
1357 if(javaScriptButton)
1358 {
1359 // If JavaScript is enabled
1360 if(webdeveloper_getBooleanPreference("javascript.enabled", false))
1361 {
1362 // If the JavaScript button has a class attribute
1363 if(javaScriptButton.hasAttribute("class"))
1364 {
1365 javaScriptButton.removeAttribute("class");
1366 }
1367
1368 // If the JavaScript button has a tooltip text attribute
1369 if(javaScriptButton.hasAttribute("tooltiptext"))
1370 {
1371 javaScriptButton.removeAttribute("tooltiptext");
1372 }
1373
1374 // If the toolbar preference is set to text and the JavaScript button has a label attribute
1375 if(webdeveloper_getStringPreference("webdeveloper.toolbar.icons", true) == "text" && javaScriptButton.hasAttribute("label"))
1376 {
1377 javaScriptButton.removeAttribute("label");
1378 }
1379 }
1380 else
1381 {
1382 var stringBundle = document.getElementById("webdeveloper-string-bundle");
1383
1384 // If the JavaScript button does not have a class attribute or it is not set to disabled
1385 if(!javaScriptButton.hasAttribute("class") || javaScriptButton.getAttribute("class") != "disabled")
1386 {
1387 javaScriptButton.setAttribute("class", "disabled");
1388 javaScriptButton.setAttribute("tooltiptext", stringBundle.getString("webdeveloper_javaScriptDisabledTooltip"));
1389
1390 // If the toolbar preference is set to text
1391 if(webdeveloper_getStringPreference("webdeveloper.toolbar.icons", true) == "text")
1392 {
1393 javaScriptButton.setAttribute("label", stringBundle.getString("webdeveloper_javaScriptDisabledLabel"));
1394 }
1395 }
1396 }
1397 }
1398 }
1399
1400 // Resets the page
1401 function webdeveloper_resetPage()
1402 {
1403 webdeveloper_applyStyleSheets(true);
1404 webdeveloper_clearAppliedStyles();
1405
1406 webdeveloper_outlinedElements = new Array();
1407 }
1408
1409 // Runs the given bookmarklet
1410 function webdeveloper_runBookmarklet(bookmarklet)
1411 {
1412 eval(decodeURIComponent(bookmarklet));
1413 }
1414
1415 // Sets up the default options
1416 function webdeveloper_setupDefaultOptions()
1417 {
1418 // Set default custom colors
1419 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.custom.1.color", "#ff0000");
1420 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.custom.2.color", "#33ff33");
1421 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.custom.3.color", "#3333ff");
1422 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.custom.4.color", "#ff0000");
1423 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.custom.5.color", "#33ff33");
1424
1425 // Set default dashboard position
1426 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.dashboard.position", "bottom");
1427
1428 // Set default edit CSS preferences
1429 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.edit.color.background", "#ffffff");
1430 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.edit.color.text", "#000000");
1431 webdeveloper_setIntegerPreferenceIfNotSet("webdeveloper.edit.font.size", 12);
1432 webdeveloper_setIntegerPreferenceIfNotSet("webdeveloper.edit.update.frequency", 2000);
1433
1434 // Set default feature tooltip colors
1435 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.feature.tooltip.color.background", "#ffff99");
1436 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.feature.tooltip.color.border", "#ffcc66");
1437 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.feature.tooltip.color.text", "#000000");
1438 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.feature.tooltip.opacity", "0.9");
1439
1440 // Set default generated content font size
1441 webdeveloper_setIntegerPreferenceIfNotSet("webdeveloper.generated.content.font.size", 12);
1442
1443 // Set default information preference
1444 webdeveloper_setBooleanPreferenceIfNotSet("webdeveloper.information.tidy", true);
1445
1446 // Set default line guides preference
1447 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.line.guides.color", "#000000");
1448
1449 // Set default magnification preference
1450 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.magnification.level", "2");
1451
1452 // Set default open tabs preference
1453 webdeveloper_setBooleanPreferenceIfNotSet("webdeveloper.open.tabs", true);
1454
1455 // Set default populate form fields email
1456 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.populate.form.fields.email", "example@example.com");
1457
1458 // Set default style information preference
1459 webdeveloper_setBooleanPreferenceIfNotSet("webdeveloper.style.information.dashboard", true);
1460
1461 // Set default accessibility preferences
1462 webdeveloper_setBooleanPreferenceIfNotSet("webdeveloper.validate.local.accessibility.section508", true);
1463 webdeveloper_setBooleanPreferenceIfNotSet("webdeveloper.validate.local.accessibility.wai.priority1", true);
1464
1465 // Set default CSS profile preference
1466 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.validate.local.css.profile", "css21");
1467 }
1468
1469 // Sets up the localized options
1470 function webdeveloper_setupLocalizedOptions()
1471 {
1472 var stringBundle = document.getElementById("webdeveloper-string-bundle");
1473
1474 // If the string bundle is set
1475 if(stringBundle)
1476 {
1477 // Set default resize count
1478 webdeveloper_setIntegerPreferenceIfNotSet("webdeveloper.resize.count", 1);
1479
1480 // Set 800x600
1481 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.resize.1.description", stringBundle.getString("webdeveloper_resize800x600"));
1482 webdeveloper_setIntegerPreferenceIfNotSet("webdeveloper.resize.1.width", 800);
1483 webdeveloper_setIntegerPreferenceIfNotSet("webdeveloper.resize.1.height", 600);
1484
1485 // Set default tool count
1486 webdeveloper_setIntegerPreferenceIfNotSet("webdeveloper.tool.count", 8);
1487
1488 // Set CSS validator
1489 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.tool.1.description", stringBundle.getString("webdeveloper_validateCSS"));
1490 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.tool.1.url", "http://jigsaw.w3.org/css-validator/validator?profile=css21&warning=0&uri=");
1491
1492 // Set feed validator
1493 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.tool.2.description", stringBundle.getString("webdeveloper_validateFeed"));
1494 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.tool.2.url", "http://validator.w3.org/feed/check.cgi?url=");
1495
1496 // Set HTML validator
1497 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.tool.3.description", stringBundle.getString("webdeveloper_validateHTML"));
1498 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.tool.3.key", "H");
1499 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.tool.3.url", "http://validator.w3.org/check?verbose=1&uri=");
1500
1501 // Set links validator
1502 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.tool.4.description", stringBundle.getString("webdeveloper_validateLinks"));
1503 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.tool.4.url", "http://validator.w3.org/checklink?check=Check&hide_type=all&summary=on&uri=");
1504
1505 // Set section 508 validator
1506 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.tool.5.description", stringBundle.getString("webdeveloper_validateSection508"));
1507 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.tool.5.url", "http://www.cynthiasays.com/mynewtester/cynthia.exe?rptmode=-1&url1=");
1508
1509 // Set WAI validator
1510 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.tool.6.description", stringBundle.getString("webdeveloper_validateWAI"));
1511 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.tool.6.url", "http://www.cynthiasays.com/mynewtester/cynthia.exe?rptmode=2&url1=");
1512
1513 // Set separator
1514 webdeveloper_setBooleanPreferenceIfNotSet("webdeveloper.tool.7.separator", true);
1515
1516 // Set speed report
1517 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.tool.8.description", stringBundle.getString("webdeveloper_viewSpeedReport"));
1518 webdeveloper_setStringPreferenceIfNotSet("webdeveloper.tool.8.url", "http://www.websiteoptimization.com/cgi-bin/wso/wso.pl?url=");
1519 }
1520 }
1521
1522 // Sorts two images
1523 function webdeveloper_sortImages(imageOne, imageTwo)
1524 {
1525 // If both images are set
1526 if(imageOne && imageTwo)
1527 {
1528 var imageOneSrc = imageOne.src;
1529 var imageTwoSrc = imageTwo.src;
1530
1531 // If the images are equal
1532 if(imageOneSrc == imageTwoSrc)
1533 {
1534 return 0;
1535 }
1536 else if(imageOneSrc < imageTwoSrc)
1537 {
1538 return -1;
1539 }
1540 }
1541
1542 return 1;
1543 }
1544
1545 // Handles a tab being selected
1546 function webdeveloper_tabSelect(event)
1547 {
1548 var selectedTab = getBrowser().mTabBox.selectedIndex;
1549
1550 // If the selected tab is different
1551 if(selectedTab != webdeveloper_selectedTab)
1552 {
1553 webdeveloper_selectedTab = selectedTab;
1554
1555 webdeveloper_resetCSSStatus();
1556 webdeveloper_resetJavaScriptStatus();
1557 webdeveloper_updateAppliedStyles();
1558 webdeveloper_updateRenderMode(webdeveloper_getContentDocument());
1559
1560 // Reset the display line guides and display ruler toolbars
1561 webdeveloper_configureElement(document.getElementById("webdeveloper-line-guides-toolbar"), "hidden", !webdeveloper_contains(webdeveloper_appliedStyles, "webdeveloper-display-line-guides"));
1562 webdeveloper_configureElement(document.getElementById("webdeveloper-ruler-toolbar"), "hidden", !webdeveloper_contains(webdeveloper_appliedStyles, "webdeveloper-display-ruler"));
1563
1564 // Reset the information text toolbar
1565 webdeveloper_configureElement(document.getElementById("webdeveloper-information-text-toolbar"), "hidden", !webdeveloper_isInformationTextToolbarInUse());
1566 }
1567 }
1568
1569 // Tidies a list of images by removing duplicates and sorting
1570 function webdeveloper_tidyImages(imageList)
1571 {
1572 var image = null;
1573 var imageListLength = imageList.length;
1574 var imageSrc = null;
1575 var newImageList = new Array();
1576 var newImageListLength = null;
1577 var tidiedImageList = new Array();
1578
1579 // Loop through the images
1580 for(var i = 0; i < imageListLength; i++)
1581 {
1582 image = imageList[i];
1583 imageSrc = image.src;
1584
1585 // If the image src is set and does not end in '.xul'
1586 if(imageSrc && !imageSrc.endsWith(".xul"))
1587 {
1588 newImageList.push(image);
1589 }
1590 }
1591
1592 newImageList.sort(webdeveloper_sortImages);
1593
1594 newImageListLength = newImageList.length;
1595
1596 // Loop through the images
1597 for(i = 0; i < newImageListLength; i++)
1598 {
1599 image = newImageList[i];
1600
1601 // If this is not the last image and the image is the same as the next image
1602 if(i + 1 < newImageListLength && image.src == newImageList[i + 1].src)
1603 {
1604 continue;
1605 }
1606
1607 tidiedImageList.push(image);
1608 }
1609
1610 return tidiedImageList;
1611 }
1612
1613 // Toggles the applied style with the given id
1614 function webdeveloper_toggleAppliedStyle(element, id)
1615 {
1616 webdeveloper_removeAppliedStyle(id);
1617
1618 // If the menu is checked
1619 if(element && element.getAttribute("checked"))
1620 {
1621 webdeveloper_addAppliedStyle(id);
1622 }
1623 }
1624
1625 // Toggles the feature tooltip styles
1626 function webdeveloper_toggleFeatureTooltipStyles(element, styleSheetId, selectors)
1627 {
1628 webdeveloper_removeStyleSheet(styleSheetId, false);
1629
1630 // If the menu is checked
1631 if(element.getAttribute("checked"))
1632 {
1633 var colors = " background-color: " + webdeveloper_getStringPreference("webdeveloper.feature.tooltip.color.background", true) + " !important; border-color: " + webdeveloper_getStringPreference("webdeveloper.feature.tooltip.color.border", true) + " !important; color: " + webdeveloper_getStringPreference("webdeveloper.feature.tooltip.color.text", true) + " !important; ";
1634 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
1635 var documentLength = documentList.length;
1636 var opacityValue = webdeveloper_getStringPreference("webdeveloper.feature.tooltip.opacity", true);
1637 var opacity = " -moz-opacity: " + opacityValue + " !important; opacity: " + opacityValue + " !important; ";
1638 var pageDocument = null;
1639 var styleElement = null;
1640
1641 // Loop through the documents
1642 for(var i = 0; i < documentLength; i++)
1643 {
1644 pageDocument = documentList[i];
1645 styleElement = pageDocument.createElement("style");
1646
1647 styleElement.appendChild(pageDocument.createTextNode(selectors + " {" + colors + opacity + "}"));
1648 styleElement.setAttribute("id", styleSheetId);
1649 styleElement.setAttribute("type", "text/css");
1650
1651 webdeveloper_getDocumentHeadElement(pageDocument).appendChild(styleElement);
1652 }
1653 }
1654 }
1655
1656 // Toggles an individual style sheet
1657 function webdeveloper_toggleIndividualStyleSheet(selectedStyleSheetHref)
1658 {
1659 var currentDocument = webdeveloper_getContentDocument();
1660 var styleSheet = null;
1661 var styleSheetHref = null;
1662 var styleSheetList = currentDocument.styleSheets;
1663 var styleSheetLength = styleSheetList.length;
1664
1665 // Loop through the style sheets
1666 for(var i = 0; i < styleSheetLength; i++)
1667 {
1668 styleSheet = styleSheetList[i];
1669 styleSheetHref = styleSheet.href;
1670
1671 // If this is the selected style sheet
1672 if(styleSheetHref == selectedStyleSheetHref)
1673 {
1674 styleSheet.disabled = !styleSheet.disabled;
1675 }
1676 }
1677 }
1678
1679 // Toggles the style sheet with the given id
1680 function webdeveloper_toggleStyleSheet(element, location, id)
1681 {
1682 webdeveloper_removeStyleSheet(id);
1683
1684 // If the menu is checked
1685 if(element && element.getAttribute("checked"))
1686 {
1687 webdeveloper_addStyleSheet(location, id);
1688 }
1689 }
1690
1691 // Toggles the toolbar
1692 function webdeveloper_toggleToolbar()
1693 {
1694 var toolbar = document.getElementById("webdeveloper-toolbar");
1695
1696 toolbar.collapsed = !toolbar.collapsed;
1697
1698 document.persist("webdeveloper-toolbar", "collapsed");
1699 }
1700
1701 // Uninitializes the extension
1702 function webdeveloper_uninitialize(event)
1703 {
1704 var windowContent = window.document.getElementById("content");
1705
1706 // If the window content is set
1707 if(windowContent)
1708 {
1709 var consoleService = Components.classes["@mozilla.org/consoleservice;1"].getService().QueryInterface(Components.interfaces.nsIConsoleService);
1710 var tabBox = windowContent.mTabBox;
1711
1712 // Try to remove the event listener
1713 try
1714 {
1715 windowContent.removeEventListener("load", webdeveloper_pageLoad, true);
1716 }
1717 catch(exception)
1718 {
1719 // Do nothing
1720 }
1721
1722 // Try to remove the event listener
1723 try
1724 {
1725 windowContent.removeEventListener("unload", webdeveloper_pageUnload, true);
1726 }
1727 catch(exception)
1728 {
1729 // Do nothing
1730 }
1731
1732 // If the console service is set
1733 if(consoleService)
1734 {
1735 // Try to remove the console listener
1736 try
1737 {
1738 consoleService.unregisterListener(WebDeveloperErrorConsoleListener);
1739 }
1740 catch(exception)
1741 {
1742 // Do nothing
1743 }
1744 }
1745
1746 // If the tab box is set
1747 if(tabBox)
1748 {
1749 // Try to remove the event listener
1750 try
1751 {
1752 tabBox.removeEventListener("select", webdeveloper_tabSelect, false);
1753 }
1754 catch(exception)
1755 {
1756 // Do nothing
1757 }
1758 }
1759
1760 // Try to remove the event listener
1761 try
1762 {
1763 window.removeEventListener("close", webdeveloper_uninitialize, false);
1764 }
1765 catch(exception)
1766 {
1767 // Do nothing
1768 }
1769 }
1770 }
1771
1772 // Updates the applied styles
1773 function webdeveloper_updateAppliedStyles()
1774 {
1775 webdeveloper_clearAppliedStyles();
1776 webdeveloper_addAppliedStyleByElement("webdeveloper-add-user-style-sheet");
1777 webdeveloper_addAppliedStyleByElement("webdeveloper-disable-all-styles");
1778 webdeveloper_addAppliedStyleByElement("webdeveloper-disable-browser-default-styles");
1779 webdeveloper_addAppliedStyleByElement("webdeveloper-disable-all-styles");
1780 webdeveloper_addAppliedStyleByElement("webdeveloper-disable-embedded-styles");
1781 webdeveloper_addAppliedStyleByElement("webdeveloper-disable-inline-styles");
1782 webdeveloper_addAppliedStyleByElement("webdeveloper-disable-linked-styles");
1783 webdeveloper_addAppliedStyleByElement("webdeveloper-disable-print-styles");
1784 webdeveloper_addAppliedStyleByElement("webdeveloper-display-abbreviations");
1785 webdeveloper_addAppliedStyleByElement("webdeveloper-display-access-keys");
1786 webdeveloper_addAppliedStyleByElement("webdeveloper-display-alt-attributes");
1787 webdeveloper_addAppliedStyleByElement("webdeveloper-display-anchors");
1788 webdeveloper_addAppliedStyleByElement("webdeveloper-display-block-size");
1789 webdeveloper_addAppliedStyleByElement("webdeveloper-display-div-order");
1790 webdeveloper_addAppliedStyleByElement("webdeveloper-display-element-information");
1791 webdeveloper_addAppliedStyleByElement("webdeveloper-display-form-details");
1792 webdeveloper_addAppliedStyleByElement("webdeveloper-display-handheld-css");
1793 webdeveloper_addAppliedStyleByElement("webdeveloper-display-id-class-details");
1794 webdeveloper_addAppliedStyleByElement("webdeveloper-display-image-dimensions");
1795 webdeveloper_addAppliedStyleByElement("webdeveloper-display-image-file-sizes");
1796 webdeveloper_addAppliedStyleByElement("webdeveloper-display-image-paths");
1797 webdeveloper_addAppliedStyleByElement("webdeveloper-display-line-guides");
1798 webdeveloper_addAppliedStyleByElement("webdeveloper-display-link-details");
1799 webdeveloper_addAppliedStyleByElement("webdeveloper-display-object-information");
1800 webdeveloper_addAppliedStyleByElement("webdeveloper-display-print-css");
1801 webdeveloper_addAppliedStyleByElement("webdeveloper-display-ruler");
1802 webdeveloper_addAppliedStyleByElement("webdeveloper-display-stack-levels");
1803 webdeveloper_addAppliedStyleByElement("webdeveloper-display-tab-index");
1804 webdeveloper_addAppliedStyleByElement("webdeveloper-display-table-depth");
1805 webdeveloper_addAppliedStyleByElement("webdeveloper-display-table-information");
1806 webdeveloper_addAppliedStyleByElement("webdeveloper-display-title-attributes");
1807 webdeveloper_addAppliedStyleByElement("webdeveloper-display-topographic-information");
1808 webdeveloper_addAppliedStyleByElement("webdeveloper-display-window-size-title");
1809 webdeveloper_addAppliedStyleByElement("webdeveloper-hide-background-images");
1810 webdeveloper_addAppliedStyleByElement("webdeveloper-hide-images");
1811 webdeveloper_addAppliedStyleByElement("webdeveloper-linearize-page");
1812 webdeveloper_addAppliedStyleByElement("webdeveloper-make-images-invisible");
1813 webdeveloper_addAppliedStyleByElement("webdeveloper-outline-absolute-positioned-elements");
1814 webdeveloper_addAppliedStyleByElement("webdeveloper-outline-all-images");
1815 webdeveloper_addAppliedStyleByElement("webdeveloper-outline-background-images");
1816 webdeveloper_addAppliedStyleByElement("webdeveloper-outline-block-level-elements");
1817 webdeveloper_addAppliedStyleByElement("webdeveloper-outline-current-element");
1818 webdeveloper_addAppliedStyleByElement("webdeveloper-outline-custom-elements");
1819 webdeveloper_addAppliedStyleByElement("webdeveloper-outline-deprecated-elements");
1820 webdeveloper_addAppliedStyleByElement("webdeveloper-outline-external-links");
1821 webdeveloper_addAppliedStyleByElement("webdeveloper-outline-fixed-positioned-elements");
1822 webdeveloper_addAppliedStyleByElement("webdeveloper-outline-floated-elements");
1823 webdeveloper_addAppliedStyleByElement("webdeveloper-outline-frames");
1824 webdeveloper_addAppliedStyleByElement("webdeveloper-outline-headings");
1825 webdeveloper_addAppliedStyleByElement("webdeveloper-outline-images-with-adjusted-dimensions");
1826 webdeveloper_addAppliedStyleByElement("webdeveloper-outline-images-with-empty-alt-attributes");
1827 webdeveloper_addAppliedStyleByElement("webdeveloper-outline-images-without-alt-attributes");
1828 webdeveloper_addAppliedStyleByElement("webdeveloper-outline-images-without-dimensions");
1829 webdeveloper_addAppliedStyleByElement("webdeveloper-outline-images-without-title-attributes");
1830 webdeveloper_addAppliedStyleByElement("webdeveloper-outline-links-with-ping-attributes");
1831 webdeveloper_addAppliedStyleByElement("webdeveloper-outline-links-without-title-attributes");
1832 webdeveloper_addAppliedStyleByElement("webdeveloper-outline-relative-positioned-elements");
1833 webdeveloper_addAppliedStyleByElement("webdeveloper-outline-table-captions");
1834 webdeveloper_addAppliedStyleByElement("webdeveloper-outline-table-cells");
1835 webdeveloper_addAppliedStyleByElement("webdeveloper-outline-all-tables");
1836 webdeveloper_addAppliedStyleByElement("webdeveloper-replace-images-with-alt-attributes");
1837 webdeveloper_addAppliedStyleByElement("webdeveloper-show-comments");
1838 webdeveloper_addAppliedStyleByElement("webdeveloper-small-screen-rendering");
1839 webdeveloper_addAppliedStyleByElement("webdeveloper-use-border-box-model");
1840 webdeveloper_addAppliedStyleByElement("webdeveloper-view-style-information");
1841 }
1842
1843 // Updates the CSS status button
1844 function webdeveloper_updateCSSStatus(error)
1845 {
1846 var cssButton = document.getElementById("webdeveloper-css-statusbar");
1847
1848 // If the CSS button is set
1849 if(cssButton)
1850 {
1851 var stringBundle = document.getElementById("webdeveloper-string-bundle");
1852
1853 // If the error is set
1854 if(error)
1855 {
1856 var errorMessage = error.errorMessage;
1857
1858 cssButton.setAttribute("tooltiptext", stringBundle.getFormattedString("webdeveloper_cssErrorTooltip", [errorMessage]));
1859
1860 // If the CSS button does not have a class attribute or it is not set to error
1861 if(!cssButton.hasAttribute("class") || cssButton.getAttribute("class") != "error")
1862 {
1863 cssButton.setAttribute("class", "error");
1864
1865 // If the toolbar preference is set to text
1866 if(webdeveloper_getStringPreference("webdeveloper.toolbar.icons", true) == "text")
1867 {
1868 cssButton.setAttribute("label", stringBundle.getString("webdeveloper_cssErrorLabel"));
1869 }
1870 }
1871
1872 // If the open CSS console error preference is set
1873 if(webdeveloper_getBooleanPreference("webdeveloper.open.css.console.error", true))
1874 {
1875 webdeveloper_openErrorConsole(false);
1876 }
1877 }
1878 else if(!cssButton.hasAttribute("class") || cssButton.getAttribute("class") != "valid")
1879 {
1880 cssButton.setAttribute("class", "valid");
1881 cssButton.setAttribute("tooltiptext", stringBundle.getString("webdeveloper_cssNoErrorsTooltip"));
1882
1883 // If the toolbar preference is set to text
1884 if(webdeveloper_getStringPreference("webdeveloper.toolbar.icons", true) == "text")
1885 {
1886 cssButton.setAttribute("label", stringBundle.getString("webdeveloper_cssNoErrorsLabel"));
1887 }
1888 }
1889 }
1890 }
1891
1892 // Updates the JavaScript status button
1893 function webdeveloper_updateJavaScriptStatus(error)
1894 {
1895 var javaScriptButton = document.getElementById("webdeveloper-javascript-statusbar");
1896
1897 // If the JavaScript button is set
1898 if(javaScriptButton)
1899 {
1900 var stringBundle = document.getElementById("webdeveloper-string-bundle");
1901
1902 // If the error is set
1903 if(error)
1904 {
1905 var errorMessage = error.errorMessage;
1906 var warning = error.flags & error.warningFlag != 0;
1907
1908 // If this is a warning
1909 if(warning)
1910 {
1911 javaScriptButton.setAttribute("tooltiptext", stringBundle.getFormattedString("webdeveloper_javaScriptWarningTooltip", [errorMessage]));
1912
1913 // If the JavaScript button does not have a class attribute or it is not set to warning
1914 if(!javaScriptButton.hasAttribute("class") || javaScriptButton.getAttribute("class") != "warning")
1915 {
1916 javaScriptButton.setAttribute("class", "warning");
1917
1918 // If the toolbar preference is set to text
1919 if(webdeveloper_getStringPreference("webdeveloper.toolbar.icons", true) == "text")
1920 {
1921 javaScriptButton.setAttribute("label", stringBundle.getString("webdeveloper_javaScriptWarningLabel"));
1922 }
1923 }
1924
1925 // If the open JavaScript console warning preference is set
1926 if(webdeveloper_getBooleanPreference("webdeveloper.open.javascript.console.warning", true))
1927 {
1928 webdeveloper_openErrorConsole(false);
1929 }
1930 }
1931 else
1932 {
1933 javaScriptButton.setAttribute("tooltiptext", stringBundle.getFormattedString("webdeveloper_javaScriptErrorTooltip", [errorMessage]));
1934
1935 // If the JavaScript button does not have a class attribute or it is not set to error
1936 if(!javaScriptButton.hasAttribute("class") || javaScriptButton.getAttribute("class") != "error")
1937 {
1938 javaScriptButton.setAttribute("class", "error");
1939
1940 // If the toolbar preference is set to text
1941 if(webdeveloper_getStringPreference("webdeveloper.toolbar.icons", true) == "text")
1942 {
1943 javaScriptButton.setAttribute("label", stringBundle.getString("webdeveloper_javaScriptErrorLabel"));
1944 }
1945 }
1946
1947 // If the open JavaScript console error preference is set
1948 if(webdeveloper_getBooleanPreference("webdeveloper.open.javascript.console.error", true))
1949 {
1950 webdeveloper_openErrorConsole(false);
1951 }
1952 }
1953 }
1954 else if(!javaScriptButton.hasAttribute("class") || javaScriptButton.getAttribute("class") != "valid")
1955 {
1956 javaScriptButton.setAttribute("class", "valid");
1957 javaScriptButton.setAttribute("tooltiptext", stringBundle.getString("webdeveloper_javaScriptNoErrorsTooltip"));
1958
1959 // If the toolbar preference is set to text
1960 if(webdeveloper_getStringPreference("webdeveloper.toolbar.icons", true) == "text")
1961 {
1962 javaScriptButton.setAttribute("label", stringBundle.getString("webdeveloper_javaScriptNoErrorsLabel"));
1963 }
1964 }
1965 }
1966 }
1967
1968 // Updates the meta redirects status
1969 function webdeveloper_updateMetaRedirects(browser)
1970 {
1971 browser.docShell.allowMetaRedirects = !webdeveloper_getBooleanPreference("webdeveloper.meta.redirects.disable", true);
1972 }
1973
1974 // Updates the options menu
1975 function webdeveloper_updateOptionsMenu(suffix)
1976 {
1977 var appliedStyles = true;
1978
1979 // If there are no applied styles
1980 if(webdeveloper_appliedStyles.length == 0)
1981 {
1982 appliedStyles = false;
1983 }
1984
1985 webdeveloper_configureElement(document.getElementById("webdeveloper-persist-features-" + suffix), "checked", webdeveloper_getBooleanPreference("webdeveloper.persist.features", true));
1986 webdeveloper_configureElement(document.getElementById("webdeveloper-reset-page-" + suffix), "disabled", !appliedStyles);
1987 }
1988
1989 // Updates the render mode status button
1990 function webdeveloper_updateRenderMode(currentDocument)
1991 {
1992 var element = document.getElementById("webdeveloper-render-mode-statusbar");
1993
1994 // If the render mode button exists
1995 if(element)
1996 {
1997 var renderMode = currentDocument.compatMode;
1998 var stringBundle = document.getElementById("webdeveloper-string-bundle");
1999 var textToolbar = false;
2000
2001 // If the toolbar preference has a value and is set to text
2002 if(webdeveloper_getStringPreference("webdeveloper.toolbar.icons", true) == "text")
2003 {
2004 textToolbar = true;
2005 }
2006
2007 // If the render mode is quirks mode
2008 if(renderMode == "BackCompat")
2009 {
2010 element.setAttribute("class", "quirks");
2011 element.setAttribute("tooltiptext", stringBundle.getString("webdeveloper_quirksModeTooltip"));
2012
2013 // If the toolbar is in text mode
2014 if(textToolbar)
2015 {
2016 element.setAttribute("label", stringBundle.getString("webdeveloper_quirksModeLabel"));
2017 }
2018 }
2019 else
2020 {
2021 // If the render mode button has a class attribute
2022 if(element.hasAttribute("class"))
2023 {
2024 element.removeAttribute("class");
2025 }
2026
2027 element.setAttribute("tooltiptext", stringBundle.getString("webdeveloper_standardsComplianceModeTooltip"));
2028
2029 // If the toolbar is in text mode
2030 if(textToolbar)
2031 {
2032 element.setAttribute("label", stringBundle.getString("webdeveloper_standardsComplianceModeLabel"));
2033 }
2034 }
2035 }
2036 }
2037
2038 // Updates the status menu
2039 function webdeveloper_updateStatusMenu(statusMenu)
2040 {
2041 var appliedStylesLength = webdeveloper_appliedStyles.length;
2042
2043 webdeveloper_removeGeneratedMenuItems(statusMenu);
2044
2045 // Loop through the applied styles
2046 for(var i = 0; i < appliedStylesLength; i++)
2047 {
2048 webdeveloper_addStatusMenuItem(statusMenu,webdeveloper_appliedStyles[i]);
2049 }
2050
2051 // If the status menu has only two children
2052 if(statusMenu.childNodes.length == 2)
2053 {
2054 return false;
2055 }
2056
2057 return true;
2058 }
2059
2060 // Error console listener
2061 var WebDeveloperErrorConsoleListener =
2062 {
2063 // Observes changes in the console
2064 observe: function(error)
2065 {
2066 // If the document and error are set
2067 if(document && error)
2068 {
2069 // Try to convert the error to a script error
2070 try
2071 {
2072 error = error.QueryInterface(Components.interfaces.nsIScriptError);
2073
2074 var errorCategory = error.category;
2075 var sourceName = error.sourceName;
2076
2077 // If the error category is set and is content javascript
2078 if(errorCategory && errorCategory == "content javascript")
2079 {
2080 webdeveloper_updateJavaScriptStatus(error);
2081 }
2082 else if(errorCategory && errorCategory == "CSS Parser")
2083 {
2084 webdeveloper_updateCSSStatus(error);
2085 }
2086 else if(sourceName && sourceName.indexOf("chrome://webdeveloper/") != -1 && webdeveloper_getBooleanPreference("webdeveloper.debug", true))
2087 {
2088 webdeveloper_openErrorConsole(false);
2089 }
2090 }
2091 catch(exception)
2092 {
2093 // Do nothing
2094 }
2095 }
2096
2097 return false;
2098 }
2099 }