1 var webdeveloper_accessibilityValidator
= new WebDeveloperValidateAccessibility();
2 var webdeveloper_cssValidator
= new WebDeveloperValidateCSS();
3 var webdeveloper_htmlValidator
= new WebDeveloperValidateHTML();
4 var webdeveloper_selectedValidationTab
= -1;
6 // Clears the accessibility validation details for the page
7 function webdeveloper_clearPageAccessibilityValidation()
9 var validationButton
= document
.getElementById("webdeveloper-accessibility-validation");
11 // If the validation button is set
14 validationButton
.label
= "";
16 // If the validation button has a class attribute
17 if(validationButton
.hasAttribute("class"))
19 validationButton
.removeAttribute("class");
23 webdeveloper_accessibilityValidator
.cleanUp();
26 // Clears the CSS validation details for the page
27 function webdeveloper_clearPageCSSValidation()
29 var validationButton
= document
.getElementById("webdeveloper-css-validation");
31 // If the validation button is set
34 validationButton
.label
= "";
36 // If the validation button has a class attribute
37 if(validationButton
.hasAttribute("class"))
39 validationButton
.removeAttribute("class");
43 webdeveloper_cssValidator
.cleanUp();
46 // Clears the HTML validation details for the page
47 function webdeveloper_clearPageHTMLValidation()
49 var validationButton
= document
.getElementById("webdeveloper-html-validation");
51 // If the validation button is set
54 validationButton
.label
= "";
56 // If the validation button has a class attribute
57 if(validationButton
.hasAttribute("class"))
59 validationButton
.removeAttribute("class");
63 webdeveloper_htmlValidator
.cleanUp();
66 // Displays page validation
67 function webdeveloper_displayPageValidation(element
)
70 var windowContent
= window
.document
.getElementById("content");
72 // If the element is set
75 checked
= element
.getAttribute("checked");
78 webdeveloper_configureElement(document
.getElementById("webdeveloper-page-validation-toolbar"), "hidden", !checked
);
80 // If the window content is set
83 var tabBox
= windowContent
.mTabBox
;
85 webdeveloper_clearPageAccessibilityValidation();
86 webdeveloper_clearPageCSSValidation();
87 webdeveloper_clearPageHTMLValidation();
89 // If displaying page validation
92 var contentDocument
= webdeveloper_getContentDocument();
94 webdeveloper_updatePageAccessibilityValidation(contentDocument
);
95 webdeveloper_updatePageCSSValidation(contentDocument
);
96 webdeveloper_updatePageHTMLValidation(contentDocument
);
98 windowContent
.addEventListener("load", webdeveloper_pageValidationLoad
, true);
99 windowContent
.addEventListener("unload", webdeveloper_pageValidationUnload
, true);
101 // If the tab box is set
104 tabBox
.addEventListener("select", webdeveloper_tabValidationSelect
, false);
109 // Try to remove the event listener
112 windowContent
.removeEventListener("load", webdeveloper_pageValidationLoad
, true);
119 // Try to remove the event listener
122 windowContent
.removeEventListener("unload", webdeveloper_pageValidationUnload
, true);
129 // If the tab box is set
132 // Try to remove the event listener
135 tabBox
.removeEventListener("select", webdeveloper_tabValidationSelect
, false);
145 webdeveloper_toggleAppliedStyle(element
, "webdeveloper-display-page-validation");
148 // Checks if the page is validatable
149 function webdeveloper_isValidatablePage(uri
)
151 // If the URI is set and is validatable
152 if(uri
&& uri
!= "about:blank" && uri
!= "http://www.hermish.com/check_this.cfm" && uri
!= "http://jigsaw.w3.org/css-validator/validator" && uri
!= "http://validator.w3.org/check")
160 // Handles the page being loaded
161 function webdeveloper_pageValidationLoad(event
)
163 var eventTarget
= event
.target
;
165 // If the page is the target
166 if(eventTarget
&& eventTarget
.hasAttribute
&& eventTarget
.hasAttribute("id") && eventTarget
.getAttribute("id").toLowerCase() == "content")
168 var contentDocument
= eventTarget
.contentDocument
;
170 // Try to get the original target
173 var loadedDocument
= event
.originalTarget
;
175 // If the content document is set, the loaded document is set and has the same URI as the content document
176 if(contentDocument
&& loadedDocument
&& contentDocument
.documentURI
== loadedDocument
.documentURI
)
178 webdeveloper_clearPageAccessibilityValidation();
179 webdeveloper_clearPageCSSValidation();
180 webdeveloper_clearPageHTMLValidation();
182 // If the page is validatable
183 if(webdeveloper_isValidatablePage(contentDocument
.documentURI
))
185 webdeveloper_updatePageAccessibilityValidation(contentDocument
);
186 webdeveloper_updatePageCSSValidation(contentDocument
);
187 webdeveloper_updatePageHTMLValidation(contentDocument
);
198 // Handles the page being unloaded
199 function webdeveloper_pageValidationUnload(event
)
201 var eventTarget
= event
.target
;
203 // Try to get the original target
206 var originalTarget
= event
.originalTarget
;
208 // If the page is the target and the URI matches
209 if(eventTarget
&& originalTarget
&& eventTarget
.contentDocument
&& eventTarget
.hasAttribute
&& eventTarget
.hasAttribute("id") && eventTarget
.getAttribute("id").toLowerCase() == "content" && eventTarget
.contentDocument
.documentURI
== originalTarget
.documentURI
)
211 webdeveloper_clearPageAccessibilityValidation();
212 webdeveloper_clearPageCSSValidation();
213 webdeveloper_clearPageHTMLValidation();
222 // Handles a tab being selected
223 function webdeveloper_tabValidationSelect(event
)
225 var selectedTab
= getBrowser().mTabBox
.selectedIndex
;
227 // If the selected tab is different
228 if(selectedTab
!= webdeveloper_selectedValidationTab
)
230 var contentDocument
= webdeveloper_getContentDocument();
232 webdeveloper_selectedValidationTab
= selectedTab
;
234 webdeveloper_clearPageAccessibilityValidation();
235 webdeveloper_clearPageCSSValidation();
236 webdeveloper_clearPageHTMLValidation();
237 webdeveloper_updatePageAccessibilityValidation(contentDocument
);
238 webdeveloper_updatePageCSSValidation(contentDocument
);
239 webdeveloper_updatePageHTMLValidation(contentDocument
);
243 // Updates the accessibility validation for the page
244 function webdeveloper_updatePageAccessibilityValidation(contentDocument
)
246 var validationButton
= document
.getElementById("webdeveloper-accessibility-validation");
248 // If the validation button is set
251 webdeveloper_accessibilityValidator
.cleanUp();
252 webdeveloper_accessibilityValidator
.validateBackgroundAccessibility(Components
.classes
["@mozilla.org/network/io-service;1"].getService(Components
.interfaces
.nsIIOService
).newURI(contentDocument
.documentURI
, null, null));
254 validationButton
.label
= document
.getElementById("webdeveloper-string-bundle").getString("webdeveloper_validating");
258 // Updates the accessibility validation details for the page
259 function webdeveloper_updatePageAccessibilityValidationDetails()
261 // If the accessibility validation request is set and is ready
262 if(webdeveloper_accessibilityValidator
.validationRequest
&& webdeveloper_accessibilityValidator
.validationRequest
.readyState
== 4)
264 // Try to check the accessibility validation status
267 // If the accessibility validation status is set to success
268 if(webdeveloper_accessibilityValidator
.validationRequest
.status
== 200)
270 var errors
= webdeveloper_accessibilityValidator
.parseValidationResultsByType("violation");
271 var validationButton
= document
.getElementById("webdeveloper-accessibility-validation");
272 var warnings
= webdeveloper_accessibilityValidator
.parseValidationResultsByType("caution");
274 // If the validation button is set
277 var stringBundle
= document
.getElementById("webdeveloper-string-bundle");
279 // If there are errors
282 var labelValue
= stringBundle
.getString("webdeveloper_invalid") + ": " + errors
+ " " + stringBundle
.getString("webdeveloper_errors").toLowerCase();
284 // If there are warnings
287 labelValue
+= ", " + warnings
+ " " + stringBundle
.getString("webdeveloper_warnings").toLowerCase();
290 validationButton
.label
= labelValue
;
292 validationButton
.setAttribute("class", "error");
294 else if(warnings
> 0)
296 validationButton
.label
= stringBundle
.getString("webdeveloper_warning") + ": " + warnings
+ " " + stringBundle
.getString("webdeveloper_warnings").toLowerCase();
298 validationButton
.setAttribute("class", "warning");
302 validationButton
.label
= stringBundle
.getString("webdeveloper_valid");
304 validationButton
.setAttribute("class", "valid");
314 webdeveloper_accessibilityValidator
.cleanUp();
318 // Updates the CSS validation for the page
319 function webdeveloper_updatePageCSSValidation(contentDocument
)
321 var validationButton
= document
.getElementById("webdeveloper-css-validation");
323 // If the validation button is set
326 webdeveloper_cssValidator
.cleanUp();
327 webdeveloper_cssValidator
.validateBackgroundCSS(Components
.classes
["@mozilla.org/network/io-service;1"].getService(Components
.interfaces
.nsIIOService
).newURI(contentDocument
.documentURI
, null, null), webdeveloper_getDocuments(webdeveloper_getContentWindow()));
329 validationButton
.label
= document
.getElementById("webdeveloper-string-bundle").getString("webdeveloper_validating");
333 // Updates the CSS validation details for the page
334 function webdeveloper_updatePageCSSValidationDetails()
336 // If the CSS validation request is set and is ready
337 if(webdeveloper_cssValidator
.validationRequest
&& webdeveloper_cssValidator
.validationRequest
.readyState
== 4)
339 // Try to check the CSS validation status
342 // If the CSS validation status is set to success
343 if(webdeveloper_cssValidator
.validationRequest
.status
== 200)
345 var errors
= webdeveloper_cssValidator
.parseValidationResultsByType("errors");
346 var validationButton
= document
.getElementById("webdeveloper-css-validation");
347 var warnings
= webdeveloper_cssValidator
.parseValidationResultsByType("warnings");
349 // If the validation button is set
352 var stringBundle
= document
.getElementById("webdeveloper-string-bundle");
354 // If there are errors
357 var labelValue
= stringBundle
.getString("webdeveloper_invalid") + ": " + errors
+ " " + stringBundle
.getString("webdeveloper_errors").toLowerCase();
359 // If there are warnings
362 labelValue
+= ", " + warnings
+ " " + stringBundle
.getString("webdeveloper_warnings").toLowerCase();
365 validationButton
.label
= labelValue
;
367 validationButton
.setAttribute("class", "error");
369 else if(warnings
> 0)
371 validationButton
.label
= stringBundle
.getString("webdeveloper_warning") + ": " + warnings
+ " " + stringBundle
.getString("webdeveloper_warnings").toLowerCase();
373 validationButton
.setAttribute("class", "warning");
377 validationButton
.label
= stringBundle
.getString("webdeveloper_valid");
379 validationButton
.setAttribute("class", "valid");
389 webdeveloper_cssValidator
.cleanUp();
393 // Updates the HTML validation for the page
394 function webdeveloper_updatePageHTMLValidation(contentDocument
)
396 var validationButton
= document
.getElementById("webdeveloper-html-validation");
398 // If the validation button is set
401 webdeveloper_htmlValidator
.cleanUp();
402 webdeveloper_htmlValidator
.validateBackgroundHTML(Components
.classes
["@mozilla.org/network/io-service;1"].getService(Components
.interfaces
.nsIIOService
).newURI(contentDocument
.documentURI
, null, null));
404 validationButton
.label
= document
.getElementById("webdeveloper-string-bundle").getString("webdeveloper_validating");
408 // Updates the HTML validation details for the page
409 function webdeveloper_updatePageHTMLValidationDetails()
411 // If the HTML validation request is set and is ready
412 if(webdeveloper_htmlValidator
.validationRequest
&& webdeveloper_htmlValidator
.validationRequest
.readyState
== 4)
414 // Try to check the HTML validation status
417 // If the HTML validation status is set to success
418 if(webdeveloper_htmlValidator
.validationRequest
.status
== 200)
420 var validationButton
= document
.getElementById("webdeveloper-html-validation");
421 var validationStatus
= webdeveloper_htmlValidator
.validationRequest
.getResponseHeader("X-W3C-Validator-Status");
423 // If the validation button and validation status are set
424 if(validationButton
&& validationStatus
)
426 var stringBundle
= document
.getElementById("webdeveloper-string-bundle");
428 // If the validation status is valid
429 if(validationStatus
== "Valid")
431 validationButton
.label
= stringBundle
.getString("webdeveloper_valid");
433 validationButton
.setAttribute("class", "valid");
437 validationButton
.label
= stringBundle
.getString("webdeveloper_invalid") + ": " + webdeveloper_htmlValidator
.validationRequest
.getResponseHeader("X-W3C-Validator-Errors") + " " + stringBundle
.getString("webdeveloper_errors").toLowerCase();
439 validationButton
.setAttribute("class", "invalid");
449 webdeveloper_htmlValidator
.cleanUp();