1 // Clears all radio buttons
2 function webdeveloper_clearRadioButtons()
4 var clearedRadioButtons
= 0;
5 var documentList
= webdeveloper_getDocuments(webdeveloper_getContentWindow());
6 var documentLength
= documentList
.length
;
7 var inputElement
= null;
8 var inputElementList
= null;
9 var inputElementsLength
= null;
10 var pageDocument
= null;
12 // Loop through the documents
13 for(var i
= 0; i
< documentLength
; i
++)
15 pageDocument
= documentList
[i
];
16 inputElementList
= pageDocument
.getElementsByTagName("input");
17 inputElementsLength
= inputElementList
.length
;
19 // Loop through all the input tags
20 for(var j
= 0; j
< inputElementsLength
; j
++)
22 inputElement
= inputElementList
[j
];
24 // If the element is a radio button
25 if(inputElement
.hasAttribute("type") && inputElement
.getAttribute("type").toLowerCase() == "radio")
27 inputElement
.checked
= false;
29 clearedRadioButtons
++;
33 // This stops the fields reordering
34 inputElement
.setAttribute("type", inputElement
.getAttribute("type"));
39 // If the hide informational dialogs preference is not set
40 if(!webdeveloper_getBooleanPreference("webdeveloper.informational.dialogs.hide", true))
42 var stringBundle
= document
.getElementById("webdeveloper-string-bundle");
43 var title
= stringBundle
.getString("webdeveloper_clearRadioButtons");
45 // If one radio button was cleared
46 if(clearedRadioButtons
== 1)
48 webdeveloper_informationalDialog(title
, stringBundle
.getFormattedString("webdeveloper_clearRadioButtonsSingleResult"));
52 webdeveloper_informationalDialog(title
, stringBundle
.getFormattedString("webdeveloper_clearRadioButtonsMultipleResult", [clearedRadioButtons
]));
57 // Converts form methods
58 function webdeveloper_convertFormMethods(method
)
60 var convertedForms
= 0;
61 var displayFormDetailsMenu
= document
.getElementById("webdeveloper-display-form-details-menu");
62 var documentList
= webdeveloper_getDocuments(webdeveloper_getContentWindow());
63 var documentLength
= documentList
.length
;
65 var formLength
= null;
67 var pageDocument
= null;
69 // Loop through the documents
70 for(var i
= 0; i
< documentLength
; i
++)
72 pageDocument
= documentList
[i
];
73 formList
= pageDocument
.forms
;
74 formLength
= formList
.length
;
76 // Loop through all the forms
77 for(var j
= 0; j
< formLength
; j
++)
81 // If this form is not already the right method
82 if((!form
.hasAttribute("method") && method
== "post") || (form
.hasAttribute("method") && form
.getAttribute("method").toLowerCase() != method
))
84 form
.setAttribute("method", method
);
90 // Reapply the display form details style sheet if it is currently on - fixes bug with form method not updating
91 if(displayFormDetailsMenu
.getAttribute("checked"))
93 webdeveloper_removeStyleSheet("webdeveloper-display-form-details", false);
94 webdeveloper_displayFormDetails(displayFormDetailsMenu
, false);
97 // If the hide informational dialogs preference is not set
98 if(!webdeveloper_getBooleanPreference("webdeveloper.informational.dialogs.hide", true))
100 var stringBundle
= document
.getElementById("webdeveloper-string-bundle");
101 var title
= stringBundle
.getString("webdeveloper_convertFormMethods");
103 // If one form was converted
104 if(convertedForms
== 1)
106 webdeveloper_informationalDialog(title
, stringBundle
.getFormattedString("webdeveloper_convertFormMethodsSingleResult", [method
.toUpperCase()]));
110 webdeveloper_informationalDialog(title
, stringBundle
.getFormattedString("webdeveloper_convertFormMethodsMultipleResult", [convertedForms
, method
.toUpperCase()]));
115 // Converts select elements to text inputs
116 function webdeveloper_convertSelectElementsToTextInputs()
118 var convertedSelectElements
= 0;
119 var displayFormDetailsMenu
= document
.getElementById("webdeveloper-display-form-details-menu");
120 var documentList
= webdeveloper_getDocuments(webdeveloper_getContentWindow());
121 var documentLength
= documentList
.length
;
122 var inputElement
= null;
123 var pageDocument
= null;
124 var parentNode
= null;
125 var selectElement
= null;
126 var selectElements
= null;
128 // Loop through the documents
129 for(var i
= 0; i
< documentLength
; i
++)
131 pageDocument
= documentList
[i
];
132 selectElements
= pageDocument
.getElementsByTagName("select");
134 // While there are select elements
135 while(selectElements
.length
> 0)
137 inputElement
= pageDocument
.createElement("input");
138 selectElement
= selectElements
[0];
139 parentNode
= selectElement
.parentNode
;
141 inputElement
.value
= selectElement
.value
;
143 // If the select element has an id attribute
144 if(selectElement
.hasAttribute("id"))
146 inputElement
.setAttribute("id", selectElement
.getAttribute("id"));
149 // If the select element has a name attribute
150 if(selectElement
.hasAttribute("name"))
152 inputElement
.setAttribute("name", selectElement
.getAttribute("name"));
155 inputElement
.setAttribute("type", "text");
157 parentNode
.insertBefore(inputElement
, selectElement
);
158 webdeveloper_removeElement(selectElement
);
159 convertedSelectElements
++;
163 // Reapply the display form details style sheet if it is currently on - fixes bug with form method not updating
164 if(displayFormDetailsMenu
.getAttribute("checked"))
166 webdeveloper_removeStyleSheet("webdeveloper-display-form-details", false);
167 webdeveloper_displayFormDetails(displayFormDetailsMenu
, false);
170 // If the hide informational dialogs preference is not set
171 if(!webdeveloper_getBooleanPreference("webdeveloper.informational.dialogs.hide", true))
173 var stringBundle
= document
.getElementById("webdeveloper-string-bundle");
174 var title
= stringBundle
.getString("webdeveloper_convertSelectElementsToTextInputs");
176 // If one select element was converted
177 if(convertedSelectElements
== 1)
179 webdeveloper_informationalDialog(title
, stringBundle
.getString("webdeveloper_convertSelectElementsToTextInputsSingleResult"));
183 webdeveloper_informationalDialog(title
, stringBundle
.getFormattedString("webdeveloper_convertSelectElementsToTextInputsMultipleResult", [convertedSelectElements
]));
188 // Displays/hides the form details for the page
189 function webdeveloper_displayFormDetails(element
)
191 var buttonElement
= null;
192 var buttonElementList
= null;
193 var buttonElementsLength
= null;
194 var display
= element
.getAttribute("checked");
195 var documentList
= webdeveloper_getDocuments(webdeveloper_getContentWindow());
196 var documentLength
= documentList
.length
;
197 var inputElement
= null;
198 var inputElementList
= null;
199 var inputElementsLength
= null;
200 var pageDocument
= null;
201 var selectElement
= null;
202 var selectElementList
= null;
203 var selectElementsLength
= null;
204 var spanElement
= null;
206 var textAreaElement
= null;
207 var textAreaElementList
= null;
208 var textAreaElementsLength
= null;
210 // Loop through the documents
211 for(var i
= 0; i
< documentLength
; i
++)
213 pageDocument
= documentList
[i
];
214 inputElementList
= pageDocument
.getElementsByTagName("input");
215 inputElementsLength
= inputElementList
.length
;
217 // Need to do this to stop the feature running twice
218 webdeveloper_removeAllElementsByXPath(pageDocument
, "//span[@class='webdeveloper-display-form-details']");
220 // Loop through all the input tags
221 for(var j
= 0; j
< inputElementsLength
; j
++)
223 inputElement
= inputElementList
[j
];
225 // If the input element is unhidden - need to do this to stop it running twice
226 if(inputElement
.className
.indexOf("webdeveloper-unhidden") != -1)
228 inputElement
.className
= webdeveloper_removeSubstring(inputElement
.className
, "webdeveloper-unhidden");
230 inputElement
.setAttribute("type", "hidden");
236 spanElement
= pageDocument
.createElement("span");
239 // If the element is hidden
240 if(inputElement
.hasAttribute("type") && inputElement
.getAttribute("type").toLowerCase() == "hidden")
242 inputElement
.className
+= " webdeveloper-unhidden";
244 inputElement
.setAttribute("type", "text");
247 // This stops the fields reordering
248 inputElement
.setAttribute("type", inputElement
.getAttribute("type"));
250 // If the element has an id attribute
251 if(inputElement
.hasAttribute("id"))
253 text
+= ' id="' + inputElement
.getAttribute("id") + '"';
256 // If the element has an name attribute
257 if(inputElement
.hasAttribute("name"))
259 text
+= ' name="' + inputElement
.getAttribute("name") + '"';
262 // If the element is a checkbox or radio button
263 if(inputElement
.hasAttribute("type") && (inputElement
.getAttribute("type").toLowerCase() == "checkbox" || inputElement
.getAttribute("type").toLowerCase() == "radio"))
265 text
+= ' value="' + inputElement
.value
+ '"';
268 // If the element has a size attribute
269 if(inputElement
.hasAttribute("size"))
271 text
+= ' size="' + inputElement
.getAttribute("size") + '"';
274 // If the element has a maxlength attribute
275 if(inputElement
.hasAttribute("maxlength"))
277 text
+= ' maxlength="' + inputElement
.getAttribute("maxlength") + '"';
282 spanElement
.setAttribute("class", "webdeveloper-display-form-details");
283 spanElement
.setAttribute("title", text
);
284 spanElement
.appendChild(pageDocument
.createTextNode(text
));
285 inputElement
.parentNode
.insertBefore(spanElement
, inputElement
);
292 buttonElementList
= pageDocument
.getElementsByTagName("button");
293 buttonElementsLength
= buttonElementList
.length
;
294 selectElementList
= pageDocument
.getElementsByTagName("select");
295 selectElementsLength
= selectElementList
.length
;
296 textAreaElementList
= pageDocument
.getElementsByTagName("textarea");
297 textAreaElementsLength
= textAreaElementList
.length
;
299 // Loop through all the button tags
300 for(j
= 0; j
< buttonElementsLength
; j
++)
302 buttonElement
= buttonElementList
[j
];
303 spanElement
= pageDocument
.createElement("span");
306 // If the element has an id attribute
307 if(buttonElement
.hasAttribute("id"))
309 text
+= ' id="' + buttonElement
.getAttribute("id") + '"';
312 // If the element has an name attribute
313 if(buttonElement
.hasAttribute("name"))
315 text
+= ' name="' + buttonElement
.getAttribute("name") + '"';
320 spanElement
.setAttribute("class", "webdeveloper-display-form-details");
321 spanElement
.setAttribute("title", text
);
322 spanElement
.appendChild(pageDocument
.createTextNode(text
));
323 buttonElement
.parentNode
.insertBefore(spanElement
, buttonElement
);
326 // Loop through all the select tags
327 for(j
= 0; j
< selectElementsLength
; j
++)
329 selectElement
= selectElementList
[j
];
330 spanElement
= pageDocument
.createElement("span");
333 // If the element has an id attribute
334 if(selectElement
.hasAttribute("id"))
336 text
+= ' id="' + selectElement
.getAttribute("id") + '"';
339 // If the element has an name attribute
340 if(selectElement
.hasAttribute("name"))
342 text
+= ' name="' + selectElement
.getAttribute("name") + '"';
347 spanElement
.setAttribute("class", "webdeveloper-display-form-details");
348 spanElement
.setAttribute("title", text
);
349 spanElement
.appendChild(pageDocument
.createTextNode(text
));
350 selectElement
.parentNode
.insertBefore(spanElement
, selectElement
);
353 // Loop through all the textarea tags
354 for(j
= 0; j
< textAreaElementsLength
; j
++)
356 textAreaElement
= textAreaElementList
[j
];
357 spanElement
= pageDocument
.createElement("span");
360 // If the element has an id attribute
361 if(textAreaElement
.hasAttribute("id"))
363 text
+= ' id="' + textAreaElement
.getAttribute("id") + '"';
366 // If the element has an name attribute
367 if(textAreaElement
.hasAttribute("name"))
369 text
+= ' name="' + textAreaElement
.getAttribute("name") + '"';
374 spanElement
.setAttribute("class", "webdeveloper-display-form-details");
375 spanElement
.setAttribute("title", text
);
376 spanElement
.appendChild(pageDocument
.createTextNode(text
));
377 textAreaElement
.parentNode
.insertBefore(spanElement
, textAreaElement
);
382 webdeveloper_toggleStyleSheet(element
, "chrome://webdeveloper/content/stylesheets/display_form_details.css", "webdeveloper-display-form-details");
383 webdeveloper_toggleFeatureTooltipStyles(element
, "webdeveloper-display-form-details-tooltips", "*:before, span.webdeveloper-display-form-details");
386 // Enables form auto completion
387 function webdeveloper_enableFormAutoCompletion()
389 var autoCompleteElements
= null;
390 var autoCompleteElementsLength
= null;
391 var documentList
= webdeveloper_getDocuments(webdeveloper_getContentWindow());
392 var documentLength
= documentList
.length
;
393 var enabledElements
= 0;
395 // Loop through the documents
396 for(var i
= 0; i
< documentLength
; i
++)
398 autoCompleteElements
= webdeveloper_evaluateXPath(documentList
[i
], "//*[@autocomplete]");
399 autoCompleteElementsLength
= autoCompleteElements
.length
;
401 // Loop through the auto complete elements
402 for(var j
= 0; j
< autoCompleteElementsLength
; j
++)
404 autoCompleteElements
[j
].removeAttribute("autocomplete");
409 // If the hide informational dialogs preference is not set
410 if(!webdeveloper_getBooleanPreference("webdeveloper.informational.dialogs.hide", true))
412 var stringBundle
= document
.getElementById("webdeveloper-string-bundle");
413 var title
= stringBundle
.getString("webdeveloper_enableAutoCompletion");
415 // If one element was enabled
416 if(enabledElements
== 1)
418 webdeveloper_informationalDialog(title
, stringBundle
.getString("webdeveloper_enableAutoCompletionSingleResult"));
422 webdeveloper_informationalDialog(title
, stringBundle
.getFormattedString("webdeveloper_enableAutoCompletionMultipleResult", [enabledElements
]));
427 // Enables all the form fields
428 function webdeveloper_enableFormFields()
430 var documentList
= webdeveloper_getDocuments(webdeveloper_getContentWindow());
431 var documentLength
= documentList
.length
;
432 var enabledFields
= 0;
434 var formElement
= null;
435 var formElementList
= null;
436 var formElements
= null;
437 var formElementsLength
= null;
438 var formLength
= null;
440 var imageInputElement
= null;
441 var imageInputElements
= null;
442 var imageInputElementsLength
= null;
444 // Loop through the documents
445 for(var i
= 0; i
< documentLength
; i
++)
447 formList
= documentList
[i
].forms
;
448 formLength
= formList
.length
;
450 // Loop through the forms
451 for(var j
= 0; j
< formLength
; j
++)
454 formElementList
= new Array();
455 formElements
= form
.elements
;
456 formElementsLength
= formElements
.length
;
457 imageInputElements
= webdeveloper_evaluateXPath(form
, "//input[@type='image']");
458 imageInputElementsLength
= imageInputElements
.length
;
460 // Loop through the form elements
461 for(var k
= 0; k
< formElementsLength
; k
++)
463 formElementList
.push(formElements
[k
]);
466 // Loop through the image input elements
467 for(k
= 0; k
< imageInputElementsLength
; k
++)
469 formElementList
.push(imageInputElements
[k
]);
472 formElementsLength
= formElementList
.length
;
474 // Loop through the form elements
475 for(k
= 0; k
< formElementsLength
; k
++)
477 formElement
= formElementList
[k
];
479 // If the form element is disabled
480 if(formElement
.disabled
)
482 formElement
.disabled
= false;
489 // If the hide informational dialogs preference is not set
490 if(!webdeveloper_getBooleanPreference("webdeveloper.informational.dialogs.hide", true))
492 var stringBundle
= document
.getElementById("webdeveloper-string-bundle");
493 var title
= stringBundle
.getString("webdeveloper_enableFormFields");
495 // If one field was enabled
496 if(enabledFields
== 1)
498 webdeveloper_informationalDialog(title
, stringBundle
.getString("webdeveloper_enableFormFieldsSingleResult"));
502 webdeveloper_informationalDialog(title
, stringBundle
.getFormattedString("webdeveloper_enableFormFieldsMultipleResult", [enabledFields
]));
507 // Makes all the form fields writable
508 function webdeveloper_makeFormFieldsWritable()
510 var documentList
= webdeveloper_getDocuments(webdeveloper_getContentWindow());
511 var documentLength
= documentList
.length
;
512 var readOnlyElements
= null;
513 var readOnlyElementsLength
= null;
514 var writableFields
= 0;
516 // Loop through the documents
517 for(var i
= 0; i
< documentLength
; i
++)
519 readOnlyElements
= webdeveloper_evaluateXPath(documentList
[i
], "//*[@readonly]");
520 readOnlyElementsLength
= readOnlyElements
.length
;
522 // Loop through all the input tags
523 for(var j
= 0; j
< readOnlyElementsLength
; j
++)
525 readOnlyElements
[j
].removeAttribute("readonly");
530 // If the hide informational dialogs preference is not set
531 if(!webdeveloper_getBooleanPreference("webdeveloper.informational.dialogs.hide", true))
533 var stringBundle
= document
.getElementById("webdeveloper-string-bundle");
534 var title
= stringBundle
.getString("webdeveloper_makeFormFieldsWritable");
536 // If one field was made writable
537 if(writableFields
== 1)
539 webdeveloper_informationalDialog(title
, stringBundle
.getString("webdeveloper_makeFormFieldsWritableSingleResult"));
543 webdeveloper_informationalDialog(title
, stringBundle
.getFormattedString("webdeveloper_makeFormFieldsWritableMultipleResult", [writableFields
]));
548 // Populates the form fields on the page
549 function webdeveloper_populateFormFields()
551 var documentList
= webdeveloper_getDocuments(webdeveloper_getContentWindow());
552 var documentLength
= documentList
.length
;
553 var inputElement
= null;
554 var inputElementList
= null;
555 var inputElementName
= null;
556 var inputElementsLength
= null;
557 var inputElementType
= null;
560 var optionsLength
= null;
561 var pageDocument
= null;
562 var selectElement
= null;
563 var selectElementList
= null;
564 var selectElementsLength
= null;
565 var textAreaElement
= null;
566 var textAreaElementList
= null;
567 var textAreaElementsLength
= null;
569 // Loop through the documents
570 for(var i
= 0; i
< documentLength
; i
++)
572 pageDocument
= documentList
[i
];
573 inputElementList
= pageDocument
.getElementsByTagName("input");
574 inputElementsLength
= inputElementList
.length
;
575 selectElementList
= pageDocument
.getElementsByTagName("select");
576 selectElementsLength
= selectElementList
.length
;
577 textAreaElementList
= pageDocument
.getElementsByTagName("textarea");
578 textAreaElementsLength
= textAreaElementList
.length
;
580 // Loop through all the input tags
581 for(var j
= 0; j
< inputElementsLength
; j
++)
583 inputElement
= inputElementList
[j
];
584 inputElementType
= inputElement
.getAttribute("type");
586 // If the input element is not disabled
587 if(!inputElement
.disabled
)
589 // If the input element value is not set and the type is not set or is password or text
590 if(inputElement
.value
.trim() == "" && (!inputElementType
|| inputElementType
== "password" || inputElementType
== "text"))
592 inputElementName
= inputElement
.getAttribute("name");
594 // If the input element type is text, the name contains email and the populate form fields email preference is set
595 if(inputElementType
== "text" && inputElementName
.toLowerCase().indexOf("email") != -1 && webdeveloper_isPreferenceSet("webdeveloper.populate.form.fields.email"))
597 inputElement
.value
= webdeveloper_getStringPreference("webdeveloper.populate.form.fields.email", true);
599 else if(inputElementType
== "password")
601 inputElement
.value
= "password";
605 inputElement
.value
= inputElementName
;
608 else if(inputElementType
== "checkbox" || inputElementType
== "radio")
610 inputElement
.checked
= true;
615 // Loop through all the select tags
616 for(j
= 0; j
< selectElementsLength
; j
++)
618 selectElement
= selectElementList
[j
];
620 // If the select element is not disabled and the value is not set
621 if(!selectElement
.disabled
&& selectElement
.value
.trim() == "")
623 options
= selectElement
.options
;
624 optionsLength
= options
.length
;
626 // Loop through the options
627 for(var k
= 0; k
< optionsLength
; k
++)
629 option
= options
.item(k
);
631 // If the optionis set and the option text and option value are not empty
632 if(option
&& option
.text
.trim() != "" && option
.value
.trim() != "")
634 selectElement
.selectedIndex
= k
;
642 // Loop through all the text area tags
643 for(j
= 0; j
< textAreaElementsLength
; j
++)
645 textAreaElement
= textAreaElementList
[j
];
647 // If the text area element is not disabled and the value is not set
648 if(!textAreaElement
.disabled
&& textAreaElement
.value
.trim() == "")
650 textAreaElement
.value
= textAreaElement
.getAttribute("name");
656 // Removes all maximum lengths on form elements
657 function webdeveloper_removeMaximumLengths()
659 var documentList
= webdeveloper_getDocuments(webdeveloper_getContentWindow());
660 var documentLength
= documentList
.length
;
661 var maximumLengthElements
= null;
662 var maximumLengthElementsLength
= null;
665 // Loop through the documents
666 for(var i
= 0; i
< documentLength
; i
++)
668 maximumLengthElements
= webdeveloper_evaluateXPath(documentList
[i
], "//input[@maxlength]");
669 maximumLengthElementsLength
= maximumLengthElements
.length
;
671 // Loop through all the input tags
672 for(var j
= 0; j
< maximumLengthElementsLength
; j
++)
674 maximumLengthElements
[j
].removeAttribute("maxlength");
679 // If the hide informational dialogs preference is not set
680 if(!webdeveloper_getBooleanPreference("webdeveloper.informational.dialogs.hide", true))
682 var stringBundle
= document
.getElementById("webdeveloper-string-bundle");
683 var title
= stringBundle
.getString("webdeveloper_removeMaximumLengths");
685 // If one maxlength was removed
688 webdeveloper_informationalDialog(title
, stringBundle
.getString("webdeveloper_removeMaximumLengthsSingleResult"));
692 webdeveloper_informationalDialog(title
, stringBundle
.getFormattedString("webdeveloper_removeMaximumLengthsMultipleResult", [removed
]));
697 // Shows all passwords on a form
698 function webdeveloper_showPasswords()
700 var documentList
= webdeveloper_getDocuments(webdeveloper_getContentWindow());
701 var documentLength
= documentList
.length
;
702 var inputElement
= null;
703 var inputElementList
= null;
704 var inputElementsLength
= null;
705 var pageDocument
= null;
706 var shownPasswords
= 0;
708 // Loop through the documents
709 for(var i
= 0; i
< documentLength
; i
++)
711 pageDocument
= documentList
[i
];
712 inputElementList
= pageDocument
.getElementsByTagName("input");
713 inputElementsLength
= inputElementList
.length
;
715 // Loop through all the input tags
716 for(var j
= 0; j
< inputElementsLength
; j
++)
718 inputElement
= inputElementList
[j
];
720 // If the element is password
721 if(inputElement
.hasAttribute("type") && inputElement
.getAttribute("type").toLowerCase() == "password")
723 inputElement
.setAttribute("type", "text");
728 // This stops the fields reordering
729 inputElement
.setAttribute("type", inputElement
.getAttribute("type"));
734 // If the hide informational dialogs preference is not set
735 if(!webdeveloper_getBooleanPreference("webdeveloper.informational.dialogs.hide", true))
737 var stringBundle
= document
.getElementById("webdeveloper-string-bundle");
738 var title
= stringBundle
.getString("webdeveloper_showPasswords");
740 // If one password was shown
741 if(shownPasswords
== 1)
743 webdeveloper_informationalDialog(title
, stringBundle
.getString("webdeveloper_showPasswordsSingleResult"));
747 webdeveloper_informationalDialog(title
, stringBundle
.getFormattedString("webdeveloper_showPasswordsMultipleResult", [shownPasswords
]));
752 // Updates the forms menu
753 function webdeveloper_updateFormsMenu(suffix
)
755 webdeveloper_configureElementByAppliedStyle(document
.getElementById("webdeveloper-display-form-details-" + suffix
), "checked", "webdeveloper-display-form-details");
758 // Displays all the forms for the page
759 function webdeveloper_viewFormInformation()
761 var cellDataElement
= null;
762 var cellHeaderElement
= null;
763 var divElement
= null;
764 var documentList
= webdeveloper_getDocuments(webdeveloper_getContentWindow());
765 var documentLength
= documentList
.length
;
766 var documentURL
= null;
767 var elementStates
= null;
768 var elementStatesLength
= null;
769 var elementType
= null;
770 var elementValue
= null;
772 var formElement
= null;
773 var formElementId
= null;
774 var formElementList
= null;
775 var formElements
= null;
776 var formElementsLength
= null;
777 var formLength
= null;
779 var imageInputElements
= null;
780 var imageInputElementsLength
= null;
781 var labelElement
= null;
782 var labelLength
= null;
783 var labelList
= null;
784 var labelValue
= null;
785 var linkElement
= null;
786 var oldTab
= getBrowser().selectedTab
;
787 var oldURL
= getBrowser().currentURI
.spec
;
788 var generatedDocument
= webdeveloper_generateDocument("");
789 var bodyElement
= webdeveloper_getDocumentBodyElement(generatedDocument
);
790 var headElement
= webdeveloper_getDocumentHeadElement(generatedDocument
);
791 var headerElement
= generatedDocument
.createElement("h1");
792 var pageDocument
= null;
794 var preElement
= null;
795 var scriptElement
= generatedDocument
.createElement("script");
796 var spanElement
= null;
797 var stringBundle
= document
.getElementById("webdeveloper-string-bundle");
798 var tableElement
= null;
799 var tableRowElement
= null;
800 var title
= stringBundle
.getFormattedString("webdeveloper_viewFormInformationTitle", [oldURL
]);
802 generatedDocument
.title
= title
;
804 webdeveloper_addGeneratedStyles(generatedDocument
);
806 headerElement
.appendChild(generatedDocument
.createTextNode(title
));
807 bodyElement
.appendChild(headerElement
);
809 webdeveloper_addGeneratedTools(generatedDocument
);
811 // Loop through the documents
812 for(var i
= 0; i
< documentLength
; i
++)
814 divElement
= generatedDocument
.createElement("div");
815 headerElement
= generatedDocument
.createElement("h2");
816 linkElement
= generatedDocument
.createElement("a");
817 pageDocument
= documentList
[i
];
818 documentURL
= pageDocument
.documentURI
;
819 formList
= pageDocument
.forms
;
820 formLength
= formList
.length
;
821 labelList
= pageDocument
.getElementsByTagName("label");
822 labelLength
= labelList
.length
;
823 spanElement
= generatedDocument
.createElement("span");
825 linkElement
.setAttribute("href", documentURL
);
826 linkElement
.appendChild(generatedDocument
.createTextNode(documentURL
));
827 headerElement
.appendChild(linkElement
);
828 bodyElement
.appendChild(headerElement
);
830 headerElement
= generatedDocument
.createElement("h3");
832 spanElement
.setAttribute("class", "expanded pivot");
833 headerElement
.appendChild(spanElement
);
835 // If there is one form
838 headerElement
.appendChild(generatedDocument
.createTextNode(formLength
+ " " + stringBundle
.getString("webdeveloper_form").toLowerCase()));
842 headerElement
.appendChild(generatedDocument
.createTextNode(formLength
+ " " + stringBundle
.getString("webdeveloper_forms").toLowerCase()));
845 bodyElement
.appendChild(headerElement
);
847 // Loop through the forms
848 for(var j
= 0; j
< formLength
; j
++)
851 formElementList
= new Array();
852 formElements
= form
.elements
;
853 formElementsLength
= formElements
.length
;
854 headerElement
= generatedDocument
.createElement("h3");
855 imageInputElements
= webdeveloper_evaluateXPath(form
, "//input[@type='image']");
856 imageInputElementsLength
= imageInputElements
.length
;
857 tableElement
= generatedDocument
.createElement("table");
858 tableRowElement
= generatedDocument
.createElement("tr");
860 // Loop through the form elements
861 for(var k
= 0; k
< formElementsLength
; k
++)
863 formElementList
.push(formElements
[k
]);
866 // Loop through the image input elements
867 for(k
= 0; k
< imageInputElementsLength
; k
++)
869 formElementList
.push(imageInputElements
[k
]);
872 formElementsLength
= formElementList
.length
;
874 headerElement
.appendChild(generatedDocument
.createTextNode(stringBundle
.getString("webdeveloper_form")));
875 divElement
.appendChild(headerElement
);
878 cellHeaderElement
= generatedDocument
.createElement("th");
880 cellHeaderElement
.appendChild(generatedDocument
.createTextNode(stringBundle
.getString("webdeveloper_id")));
881 tableRowElement
.appendChild(cellHeaderElement
);
884 cellHeaderElement
= generatedDocument
.createElement("th");
886 cellHeaderElement
.appendChild(generatedDocument
.createTextNode(stringBundle
.getString("webdeveloper_name")));
887 tableRowElement
.appendChild(cellHeaderElement
);
889 // Form method heading
890 cellHeaderElement
= generatedDocument
.createElement("th");
892 cellHeaderElement
.appendChild(generatedDocument
.createTextNode(stringBundle
.getString("webdeveloper_method")));
893 tableRowElement
.appendChild(cellHeaderElement
);
895 // Form action heading
896 cellHeaderElement
= generatedDocument
.createElement("th");
898 cellHeaderElement
.appendChild(generatedDocument
.createTextNode(stringBundle
.getString("webdeveloper_action")));
899 tableRowElement
.appendChild(cellHeaderElement
);
900 tableElement
.appendChild(tableRowElement
);
902 tableRowElement
= generatedDocument
.createElement("tr");
905 cellDataElement
= generatedDocument
.createElement("td");
907 cellDataElement
.appendChild(generatedDocument
.createTextNode(form
.getAttribute("id")));
908 tableRowElement
.appendChild(cellDataElement
);
911 cellDataElement
= generatedDocument
.createElement("td");
913 cellDataElement
.appendChild(generatedDocument
.createTextNode(form
.getAttribute("name")));
914 tableRowElement
.appendChild(cellDataElement
);
917 cellDataElement
= generatedDocument
.createElement("td");
919 cellDataElement
.appendChild(generatedDocument
.createTextNode(form
.getAttribute("method")));
920 tableRowElement
.appendChild(cellDataElement
);
923 cellDataElement
= generatedDocument
.createElement("td");
925 cellDataElement
.appendChild(generatedDocument
.createTextNode(form
.getAttribute("action")));
926 tableRowElement
.appendChild(cellDataElement
);
927 tableElement
.appendChild(tableRowElement
);
928 divElement
.appendChild(tableElement
);
930 pElement
= generatedDocument
.createElement("p");
932 divElement
.appendChild(pElement
);
934 headerElement
= generatedDocument
.createElement("h3");
935 tableElement
= generatedDocument
.createElement("table");
936 tableRowElement
= generatedDocument
.createElement("tr");
938 headerElement
.appendChild(generatedDocument
.createTextNode(stringBundle
.getString("webdeveloper_elements")));
939 divElement
.appendChild(headerElement
);
941 // Element index heading
942 cellHeaderElement
= generatedDocument
.createElement("th");
944 cellHeaderElement
.appendChild(generatedDocument
.createTextNode(stringBundle
.getString("webdeveloper_index")));
945 tableRowElement
.appendChild(cellHeaderElement
);
947 // Element id heading
948 cellHeaderElement
= generatedDocument
.createElement("th");
950 cellHeaderElement
.appendChild(generatedDocument
.createTextNode(stringBundle
.getString("webdeveloper_id")));
951 tableRowElement
.appendChild(cellHeaderElement
);
953 // Element name heading
954 cellHeaderElement
= generatedDocument
.createElement("th");
956 cellHeaderElement
.appendChild(generatedDocument
.createTextNode(stringBundle
.getString("webdeveloper_name")));
957 tableRowElement
.appendChild(cellHeaderElement
);
958 tableElement
.appendChild(tableRowElement
);
960 // Element type heading
961 cellHeaderElement
= generatedDocument
.createElement("th");
963 cellHeaderElement
.appendChild(generatedDocument
.createTextNode(stringBundle
.getString("webdeveloper_type")));
964 tableRowElement
.appendChild(cellHeaderElement
);
965 tableElement
.appendChild(tableRowElement
);
967 // Element value heading
968 cellHeaderElement
= generatedDocument
.createElement("th");
970 cellHeaderElement
.appendChild(generatedDocument
.createTextNode(stringBundle
.getString("webdeveloper_value")));
971 tableRowElement
.appendChild(cellHeaderElement
);
972 tableElement
.appendChild(tableRowElement
);
974 // Element label heading
975 cellHeaderElement
= generatedDocument
.createElement("th");
977 cellHeaderElement
.appendChild(generatedDocument
.createTextNode(stringBundle
.getString("webdeveloper_label")));
978 tableRowElement
.appendChild(cellHeaderElement
);
980 // Element size heading
981 cellHeaderElement
= generatedDocument
.createElement("th");
983 cellHeaderElement
.appendChild(generatedDocument
.createTextNode(stringBundle
.getString("webdeveloper_size")));
984 tableRowElement
.appendChild(cellHeaderElement
);
985 tableElement
.appendChild(tableRowElement
);
987 // Element maximum length heading
988 cellHeaderElement
= generatedDocument
.createElement("th");
990 cellHeaderElement
.appendChild(generatedDocument
.createTextNode(stringBundle
.getString("webdeveloper_maximumLength")));
991 tableRowElement
.appendChild(cellHeaderElement
);
992 tableElement
.appendChild(tableRowElement
);
994 // Element state heading
995 cellHeaderElement
= generatedDocument
.createElement("th");
997 cellHeaderElement
.appendChild(generatedDocument
.createTextNode(stringBundle
.getString("webdeveloper_state")));
998 tableRowElement
.appendChild(cellHeaderElement
);
999 tableElement
.appendChild(tableRowElement
);
1001 // Loop through the form elements
1002 for(k
= 0; k
< formElementsLength
; k
++)
1004 elementStates
= new Array();
1006 formElement
= formElementList
[k
];
1007 formElementId
= formElement
.getAttribute("id");
1008 elementType
= formElement
.tagName
.toLowerCase();
1011 tableRowElement
= generatedDocument
.createElement("tr");
1013 // If this is an even row
1016 tableRowElement
.setAttribute("class", "shaded");
1019 // If the element has an id
1022 // Loop through the labels
1023 for(var l
= 0; l
< labelLength
; l
++)
1025 labelElement
= labelList
[l
];
1027 // If this is the label for the element
1028 if(labelElement
.hasAttribute("for") && labelElement
.getAttribute("for") == formElementId
)
1030 labelValue
= labelElement
.innerHTML
;
1035 // If this is an input element
1036 if(elementType
== "input")
1038 elementType
= formElement
.getAttribute("type");
1039 elementValue
= formElement
.value
;
1041 else if(elementType
== "textarea")
1043 elementValue
= formElement
.value
;
1046 // If the element is checked
1047 if(formElement
.checked
)
1049 elementStates
.push("Checked");
1052 // If the element is disabled
1053 if(formElement
.disabled
)
1055 elementStates
.push("Disabled");
1058 // If the element is read only
1059 if(formElement
.readOnly
)
1061 elementStates
.push("Readonly");
1064 elementStatesLength
= elementStates
.length
;
1067 cellDataElement
= generatedDocument
.createElement("td");
1069 cellDataElement
.appendChild(generatedDocument
.createTextNode(k
));
1070 tableRowElement
.appendChild(cellDataElement
);
1071 tableElement
.appendChild(tableRowElement
);
1074 cellDataElement
= generatedDocument
.createElement("td");
1076 cellDataElement
.appendChild(generatedDocument
.createTextNode(formElementId
));
1077 tableRowElement
.appendChild(cellDataElement
);
1080 cellDataElement
= generatedDocument
.createElement("td");
1082 cellDataElement
.appendChild(generatedDocument
.createTextNode(formElement
.getAttribute("name")));
1083 tableRowElement
.appendChild(cellDataElement
);
1084 tableElement
.appendChild(tableRowElement
);
1087 cellDataElement
= generatedDocument
.createElement("td");
1089 cellDataElement
.appendChild(generatedDocument
.createTextNode(elementType
));
1090 tableRowElement
.appendChild(cellDataElement
);
1091 tableElement
.appendChild(tableRowElement
);
1094 cellDataElement
= generatedDocument
.createElement("td");
1096 cellDataElement
.appendChild(generatedDocument
.createTextNode(elementValue
));
1097 tableRowElement
.appendChild(cellDataElement
);
1098 tableElement
.appendChild(tableRowElement
);
1101 cellDataElement
= generatedDocument
.createElement("td");
1103 cellDataElement
.appendChild(generatedDocument
.createTextNode(labelValue
));
1104 tableRowElement
.appendChild(cellDataElement
);
1105 tableElement
.appendChild(tableRowElement
);
1108 cellDataElement
= generatedDocument
.createElement("td");
1110 cellDataElement
.appendChild(generatedDocument
.createTextNode(formElement
.getAttribute("size")));
1111 tableRowElement
.appendChild(cellDataElement
);
1112 tableElement
.appendChild(tableRowElement
);
1114 // Element maximum length
1115 cellDataElement
= generatedDocument
.createElement("td");
1117 cellDataElement
.appendChild(generatedDocument
.createTextNode(formElement
.getAttribute("maxlength")));
1118 tableRowElement
.appendChild(cellDataElement
);
1119 tableElement
.appendChild(tableRowElement
);
1122 cellDataElement
= generatedDocument
.createElement("td");
1124 // Loop through the element states
1125 for(l
= 0; l
< elementStatesLength
; l
++)
1127 pElement
= generatedDocument
.createElement("p");
1129 pElement
.appendChild(generatedDocument
.createTextNode(elementStates
[l
]));
1130 cellDataElement
.appendChild(pElement
);
1133 tableRowElement
.appendChild(cellDataElement
);
1134 tableElement
.appendChild(tableRowElement
);
1137 tableElement
.setAttribute("class", "sortable");
1138 divElement
.setAttribute("class", "output");
1139 divElement
.appendChild(tableElement
);
1140 divElement
.appendChild(generatedDocument
.createElement("hr"));
1141 bodyElement
.appendChild(divElement
);
1145 scriptElement
.setAttribute("defer", "defer");
1146 scriptElement
.setAttribute("src", "chrome://webdeveloper/content/common/dom.js");
1147 scriptElement
.setAttribute("type", "text/javascript");
1148 headElement
.appendChild(scriptElement
);
1150 scriptElement
= generatedDocument
.createElement("script");
1152 scriptElement
.setAttribute("defer", "defer");
1153 scriptElement
.setAttribute("src", "chrome://webdeveloper/content/common/xpath.js");
1154 scriptElement
.setAttribute("type", "text/javascript");
1155 headElement
.appendChild(scriptElement
);
1157 scriptElement
= generatedDocument
.createElement("script");
1159 scriptElement
.setAttribute("defer", "defer");
1160 scriptElement
.setAttribute("src", "chrome://webdeveloper/content/generated/output_pivot.js");
1161 scriptElement
.setAttribute("type", "text/javascript");
1162 headElement
.appendChild(scriptElement
);
1164 scriptElement
= generatedDocument
.createElement("script");
1166 scriptElement
.setAttribute("defer", "defer");
1167 scriptElement
.setAttribute("src", "chrome://webdeveloper/content/generated/table_sort.js");
1168 scriptElement
.setAttribute("type", "text/javascript");
1169 headElement
.appendChild(scriptElement
);
1171 // If the open tabs in background preference is set to true
1172 if(webdeveloper_getBooleanPreference("webdeveloper.open.tabs.background", true))
1174 getBrowser().selectedTab
= oldTab
;