git-svn-id: svn://euphorik.ch/pompage@45 02bbb61a-6d21-0410-aba0-cb053bdfd66a
[pompage.git] / doc / webdeveloper / forms.js
1 // Clears all radio buttons
2 function webdeveloper_clearRadioButtons()
3 {
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;
11
12 // Loop through the documents
13 for(var i = 0; i < documentLength; i++)
14 {
15 pageDocument = documentList[i];
16 inputElementList = pageDocument.getElementsByTagName("input");
17 inputElementsLength = inputElementList.length;
18
19 // Loop through all the input tags
20 for(var j = 0; j < inputElementsLength; j++)
21 {
22 inputElement = inputElementList[j];
23
24 // If the element is a radio button
25 if(inputElement.hasAttribute("type") && inputElement.getAttribute("type").toLowerCase() == "radio")
26 {
27 inputElement.checked = false;
28
29 clearedRadioButtons++;
30 }
31 else
32 {
33 // This stops the fields reordering
34 inputElement.setAttribute("type", inputElement.getAttribute("type"));
35 }
36 }
37 }
38
39 // If the hide informational dialogs preference is not set
40 if(!webdeveloper_getBooleanPreference("webdeveloper.informational.dialogs.hide", true))
41 {
42 var stringBundle = document.getElementById("webdeveloper-string-bundle");
43 var title = stringBundle.getString("webdeveloper_clearRadioButtons");
44
45 // If one radio button was cleared
46 if(clearedRadioButtons == 1)
47 {
48 webdeveloper_informationalDialog(title, stringBundle.getFormattedString("webdeveloper_clearRadioButtonsSingleResult"));
49 }
50 else
51 {
52 webdeveloper_informationalDialog(title, stringBundle.getFormattedString("webdeveloper_clearRadioButtonsMultipleResult", [clearedRadioButtons]));
53 }
54 }
55 }
56
57 // Converts form methods
58 function webdeveloper_convertFormMethods(method)
59 {
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;
64 var form = null;
65 var formLength = null;
66 var formList = null;
67 var pageDocument = null;
68
69 // Loop through the documents
70 for(var i = 0; i < documentLength; i++)
71 {
72 pageDocument = documentList[i];
73 formList = pageDocument.forms;
74 formLength = formList.length;
75
76 // Loop through all the forms
77 for(var j = 0; j < formLength; j++)
78 {
79 form = formList[j];
80
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))
83 {
84 form.setAttribute("method", method);
85 convertedForms++;
86 }
87 }
88 }
89
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"))
92 {
93 webdeveloper_removeStyleSheet("webdeveloper-display-form-details", false);
94 webdeveloper_displayFormDetails(displayFormDetailsMenu, false);
95 }
96
97 // If the hide informational dialogs preference is not set
98 if(!webdeveloper_getBooleanPreference("webdeveloper.informational.dialogs.hide", true))
99 {
100 var stringBundle = document.getElementById("webdeveloper-string-bundle");
101 var title = stringBundle.getString("webdeveloper_convertFormMethods");
102
103 // If one form was converted
104 if(convertedForms == 1)
105 {
106 webdeveloper_informationalDialog(title, stringBundle.getFormattedString("webdeveloper_convertFormMethodsSingleResult", [method.toUpperCase()]));
107 }
108 else
109 {
110 webdeveloper_informationalDialog(title, stringBundle.getFormattedString("webdeveloper_convertFormMethodsMultipleResult", [convertedForms, method.toUpperCase()]));
111 }
112 }
113 }
114
115 // Converts select elements to text inputs
116 function webdeveloper_convertSelectElementsToTextInputs()
117 {
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;
127
128 // Loop through the documents
129 for(var i = 0; i < documentLength; i++)
130 {
131 pageDocument = documentList[i];
132 selectElements = pageDocument.getElementsByTagName("select");
133
134 // While there are select elements
135 while(selectElements.length > 0)
136 {
137 inputElement = pageDocument.createElement("input");
138 selectElement = selectElements[0];
139 parentNode = selectElement.parentNode;
140
141 inputElement.value = selectElement.value;
142
143 // If the select element has an id attribute
144 if(selectElement.hasAttribute("id"))
145 {
146 inputElement.setAttribute("id", selectElement.getAttribute("id"));
147 }
148
149 // If the select element has a name attribute
150 if(selectElement.hasAttribute("name"))
151 {
152 inputElement.setAttribute("name", selectElement.getAttribute("name"));
153 }
154
155 inputElement.setAttribute("type", "text");
156
157 parentNode.insertBefore(inputElement, selectElement);
158 webdeveloper_removeElement(selectElement);
159 convertedSelectElements++;
160 }
161 }
162
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"))
165 {
166 webdeveloper_removeStyleSheet("webdeveloper-display-form-details", false);
167 webdeveloper_displayFormDetails(displayFormDetailsMenu, false);
168 }
169
170 // If the hide informational dialogs preference is not set
171 if(!webdeveloper_getBooleanPreference("webdeveloper.informational.dialogs.hide", true))
172 {
173 var stringBundle = document.getElementById("webdeveloper-string-bundle");
174 var title = stringBundle.getString("webdeveloper_convertSelectElementsToTextInputs");
175
176 // If one select element was converted
177 if(convertedSelectElements == 1)
178 {
179 webdeveloper_informationalDialog(title, stringBundle.getString("webdeveloper_convertSelectElementsToTextInputsSingleResult"));
180 }
181 else
182 {
183 webdeveloper_informationalDialog(title, stringBundle.getFormattedString("webdeveloper_convertSelectElementsToTextInputsMultipleResult", [convertedSelectElements]));
184 }
185 }
186 }
187
188 // Displays/hides the form details for the page
189 function webdeveloper_displayFormDetails(element)
190 {
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;
205 var text = null;
206 var textAreaElement = null;
207 var textAreaElementList = null;
208 var textAreaElementsLength = null;
209
210 // Loop through the documents
211 for(var i = 0; i < documentLength; i++)
212 {
213 pageDocument = documentList[i];
214 inputElementList = pageDocument.getElementsByTagName("input");
215 inputElementsLength = inputElementList.length;
216
217 // Need to do this to stop the feature running twice
218 webdeveloper_removeAllElementsByXPath(pageDocument, "//span[@class='webdeveloper-display-form-details']");
219
220 // Loop through all the input tags
221 for(var j = 0; j < inputElementsLength; j++)
222 {
223 inputElement = inputElementList[j];
224
225 // If the input element is unhidden - need to do this to stop it running twice
226 if(inputElement.className.indexOf("webdeveloper-unhidden") != -1)
227 {
228 inputElement.className = webdeveloper_removeSubstring(inputElement.className, "webdeveloper-unhidden");
229
230 inputElement.setAttribute("type", "hidden");
231 }
232
233 // If displaying
234 if(display)
235 {
236 spanElement = pageDocument.createElement("span");
237 text = "<input";
238
239 // If the element is hidden
240 if(inputElement.hasAttribute("type") && inputElement.getAttribute("type").toLowerCase() == "hidden")
241 {
242 inputElement.className += " webdeveloper-unhidden";
243
244 inputElement.setAttribute("type", "text");
245 }
246
247 // This stops the fields reordering
248 inputElement.setAttribute("type", inputElement.getAttribute("type"));
249
250 // If the element has an id attribute
251 if(inputElement.hasAttribute("id"))
252 {
253 text += ' id="' + inputElement.getAttribute("id") + '"';
254 }
255
256 // If the element has an name attribute
257 if(inputElement.hasAttribute("name"))
258 {
259 text += ' name="' + inputElement.getAttribute("name") + '"';
260 }
261
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"))
264 {
265 text += ' value="' + inputElement.value + '"';
266 }
267
268 // If the element has a size attribute
269 if(inputElement.hasAttribute("size"))
270 {
271 text += ' size="' + inputElement.getAttribute("size") + '"';
272 }
273
274 // If the element has a maxlength attribute
275 if(inputElement.hasAttribute("maxlength"))
276 {
277 text += ' maxlength="' + inputElement.getAttribute("maxlength") + '"';
278 }
279
280 text += ">";
281
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);
286 }
287 }
288
289 // If displaying
290 if(display)
291 {
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;
298
299 // Loop through all the button tags
300 for(j = 0; j < buttonElementsLength; j++)
301 {
302 buttonElement = buttonElementList[j];
303 spanElement = pageDocument.createElement("span");
304 text = "<button";
305
306 // If the element has an id attribute
307 if(buttonElement.hasAttribute("id"))
308 {
309 text += ' id="' + buttonElement.getAttribute("id") + '"';
310 }
311
312 // If the element has an name attribute
313 if(buttonElement.hasAttribute("name"))
314 {
315 text += ' name="' + buttonElement.getAttribute("name") + '"';
316 }
317
318 text += ">";
319
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);
324 }
325
326 // Loop through all the select tags
327 for(j = 0; j < selectElementsLength; j++)
328 {
329 selectElement = selectElementList[j];
330 spanElement = pageDocument.createElement("span");
331 text = "<select";
332
333 // If the element has an id attribute
334 if(selectElement.hasAttribute("id"))
335 {
336 text += ' id="' + selectElement.getAttribute("id") + '"';
337 }
338
339 // If the element has an name attribute
340 if(selectElement.hasAttribute("name"))
341 {
342 text += ' name="' + selectElement.getAttribute("name") + '"';
343 }
344
345 text += ">";
346
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);
351 }
352
353 // Loop through all the textarea tags
354 for(j = 0; j < textAreaElementsLength; j++)
355 {
356 textAreaElement = textAreaElementList[j];
357 spanElement = pageDocument.createElement("span");
358 text = "<textarea";
359
360 // If the element has an id attribute
361 if(textAreaElement.hasAttribute("id"))
362 {
363 text += ' id="' + textAreaElement.getAttribute("id") + '"';
364 }
365
366 // If the element has an name attribute
367 if(textAreaElement.hasAttribute("name"))
368 {
369 text += ' name="' + textAreaElement.getAttribute("name") + '"';
370 }
371
372 text += ">";
373
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);
378 }
379 }
380 }
381
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");
384 }
385
386 // Enables form auto completion
387 function webdeveloper_enableFormAutoCompletion()
388 {
389 var autoCompleteElements = null;
390 var autoCompleteElementsLength = null;
391 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
392 var documentLength = documentList.length;
393 var enabledElements = 0;
394
395 // Loop through the documents
396 for(var i = 0; i < documentLength; i++)
397 {
398 autoCompleteElements = webdeveloper_evaluateXPath(documentList[i], "//*[@autocomplete]");
399 autoCompleteElementsLength = autoCompleteElements.length;
400
401 // Loop through the auto complete elements
402 for(var j = 0; j < autoCompleteElementsLength; j++)
403 {
404 autoCompleteElements[j].removeAttribute("autocomplete");
405 enabledElements++;
406 }
407 }
408
409 // If the hide informational dialogs preference is not set
410 if(!webdeveloper_getBooleanPreference("webdeveloper.informational.dialogs.hide", true))
411 {
412 var stringBundle = document.getElementById("webdeveloper-string-bundle");
413 var title = stringBundle.getString("webdeveloper_enableAutoCompletion");
414
415 // If one element was enabled
416 if(enabledElements == 1)
417 {
418 webdeveloper_informationalDialog(title, stringBundle.getString("webdeveloper_enableAutoCompletionSingleResult"));
419 }
420 else
421 {
422 webdeveloper_informationalDialog(title, stringBundle.getFormattedString("webdeveloper_enableAutoCompletionMultipleResult", [enabledElements]));
423 }
424 }
425 }
426
427 // Enables all the form fields
428 function webdeveloper_enableFormFields()
429 {
430 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
431 var documentLength = documentList.length;
432 var enabledFields = 0;
433 var form = null;
434 var formElement = null;
435 var formElementList = null;
436 var formElements = null;
437 var formElementsLength = null;
438 var formLength = null;
439 var formList = null;
440 var imageInputElement = null;
441 var imageInputElements = null;
442 var imageInputElementsLength = null;
443
444 // Loop through the documents
445 for(var i = 0; i < documentLength; i++)
446 {
447 formList = documentList[i].forms;
448 formLength = formList.length;
449
450 // Loop through the forms
451 for(var j = 0; j < formLength; j++)
452 {
453 form = formList[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;
459
460 // Loop through the form elements
461 for(var k = 0; k < formElementsLength; k++)
462 {
463 formElementList.push(formElements[k]);
464 }
465
466 // Loop through the image input elements
467 for(k = 0; k < imageInputElementsLength; k++)
468 {
469 formElementList.push(imageInputElements[k]);
470 }
471
472 formElementsLength = formElementList.length;
473
474 // Loop through the form elements
475 for(k = 0; k < formElementsLength; k++)
476 {
477 formElement = formElementList[k];
478
479 // If the form element is disabled
480 if(formElement.disabled)
481 {
482 formElement.disabled = false;
483 enabledFields++;
484 }
485 }
486 }
487 }
488
489 // If the hide informational dialogs preference is not set
490 if(!webdeveloper_getBooleanPreference("webdeveloper.informational.dialogs.hide", true))
491 {
492 var stringBundle = document.getElementById("webdeveloper-string-bundle");
493 var title = stringBundle.getString("webdeveloper_enableFormFields");
494
495 // If one field was enabled
496 if(enabledFields == 1)
497 {
498 webdeveloper_informationalDialog(title, stringBundle.getString("webdeveloper_enableFormFieldsSingleResult"));
499 }
500 else
501 {
502 webdeveloper_informationalDialog(title, stringBundle.getFormattedString("webdeveloper_enableFormFieldsMultipleResult", [enabledFields]));
503 }
504 }
505 }
506
507 // Makes all the form fields writable
508 function webdeveloper_makeFormFieldsWritable()
509 {
510 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
511 var documentLength = documentList.length;
512 var readOnlyElements = null;
513 var readOnlyElementsLength = null;
514 var writableFields = 0;
515
516 // Loop through the documents
517 for(var i = 0; i < documentLength; i++)
518 {
519 readOnlyElements = webdeveloper_evaluateXPath(documentList[i], "//*[@readonly]");
520 readOnlyElementsLength = readOnlyElements.length;
521
522 // Loop through all the input tags
523 for(var j = 0; j < readOnlyElementsLength; j++)
524 {
525 readOnlyElements[j].removeAttribute("readonly");
526 writableFields++;
527 }
528 }
529
530 // If the hide informational dialogs preference is not set
531 if(!webdeveloper_getBooleanPreference("webdeveloper.informational.dialogs.hide", true))
532 {
533 var stringBundle = document.getElementById("webdeveloper-string-bundle");
534 var title = stringBundle.getString("webdeveloper_makeFormFieldsWritable");
535
536 // If one field was made writable
537 if(writableFields == 1)
538 {
539 webdeveloper_informationalDialog(title, stringBundle.getString("webdeveloper_makeFormFieldsWritableSingleResult"));
540 }
541 else
542 {
543 webdeveloper_informationalDialog(title, stringBundle.getFormattedString("webdeveloper_makeFormFieldsWritableMultipleResult", [writableFields]));
544 }
545 }
546 }
547
548 // Populates the form fields on the page
549 function webdeveloper_populateFormFields()
550 {
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;
558 var option = null;
559 var options = 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;
568
569 // Loop through the documents
570 for(var i = 0; i < documentLength; i++)
571 {
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;
579
580 // Loop through all the input tags
581 for(var j = 0; j < inputElementsLength; j++)
582 {
583 inputElement = inputElementList[j];
584 inputElementType = inputElement.getAttribute("type");
585
586 // If the input element is not disabled
587 if(!inputElement.disabled)
588 {
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"))
591 {
592 inputElementName = inputElement.getAttribute("name");
593
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"))
596 {
597 inputElement.value = webdeveloper_getStringPreference("webdeveloper.populate.form.fields.email", true);
598 }
599 else if(inputElementType == "password")
600 {
601 inputElement.value = "password";
602 }
603 else
604 {
605 inputElement.value = inputElementName;
606 }
607 }
608 else if(inputElementType == "checkbox" || inputElementType == "radio")
609 {
610 inputElement.checked = true;
611 }
612 }
613 }
614
615 // Loop through all the select tags
616 for(j = 0; j < selectElementsLength; j++)
617 {
618 selectElement = selectElementList[j];
619
620 // If the select element is not disabled and the value is not set
621 if(!selectElement.disabled && selectElement.value.trim() == "")
622 {
623 options = selectElement.options;
624 optionsLength = options.length;
625
626 // Loop through the options
627 for(var k = 0; k < optionsLength; k++)
628 {
629 option = options.item(k);
630
631 // If the optionis set and the option text and option value are not empty
632 if(option && option.text.trim() != "" && option.value.trim() != "")
633 {
634 selectElement.selectedIndex = k;
635
636 break;
637 }
638 }
639 }
640 }
641
642 // Loop through all the text area tags
643 for(j = 0; j < textAreaElementsLength; j++)
644 {
645 textAreaElement = textAreaElementList[j];
646
647 // If the text area element is not disabled and the value is not set
648 if(!textAreaElement.disabled && textAreaElement.value.trim() == "")
649 {
650 textAreaElement.value = textAreaElement.getAttribute("name");
651 }
652 }
653 }
654 }
655
656 // Removes all maximum lengths on form elements
657 function webdeveloper_removeMaximumLengths()
658 {
659 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
660 var documentLength = documentList.length;
661 var maximumLengthElements = null;
662 var maximumLengthElementsLength = null;
663 var removed = 0;
664
665 // Loop through the documents
666 for(var i = 0; i < documentLength; i++)
667 {
668 maximumLengthElements = webdeveloper_evaluateXPath(documentList[i], "//input[@maxlength]");
669 maximumLengthElementsLength = maximumLengthElements.length;
670
671 // Loop through all the input tags
672 for(var j = 0; j < maximumLengthElementsLength; j++)
673 {
674 maximumLengthElements[j].removeAttribute("maxlength");
675 removed++;
676 }
677 }
678
679 // If the hide informational dialogs preference is not set
680 if(!webdeveloper_getBooleanPreference("webdeveloper.informational.dialogs.hide", true))
681 {
682 var stringBundle = document.getElementById("webdeveloper-string-bundle");
683 var title = stringBundle.getString("webdeveloper_removeMaximumLengths");
684
685 // If one maxlength was removed
686 if(removed == 1)
687 {
688 webdeveloper_informationalDialog(title, stringBundle.getString("webdeveloper_removeMaximumLengthsSingleResult"));
689 }
690 else
691 {
692 webdeveloper_informationalDialog(title, stringBundle.getFormattedString("webdeveloper_removeMaximumLengthsMultipleResult", [removed]));
693 }
694 }
695 }
696
697 // Shows all passwords on a form
698 function webdeveloper_showPasswords()
699 {
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;
707
708 // Loop through the documents
709 for(var i = 0; i < documentLength; i++)
710 {
711 pageDocument = documentList[i];
712 inputElementList = pageDocument.getElementsByTagName("input");
713 inputElementsLength = inputElementList.length;
714
715 // Loop through all the input tags
716 for(var j = 0; j < inputElementsLength; j++)
717 {
718 inputElement = inputElementList[j];
719
720 // If the element is password
721 if(inputElement.hasAttribute("type") && inputElement.getAttribute("type").toLowerCase() == "password")
722 {
723 inputElement.setAttribute("type", "text");
724 shownPasswords++;
725 }
726 else
727 {
728 // This stops the fields reordering
729 inputElement.setAttribute("type", inputElement.getAttribute("type"));
730 }
731 }
732 }
733
734 // If the hide informational dialogs preference is not set
735 if(!webdeveloper_getBooleanPreference("webdeveloper.informational.dialogs.hide", true))
736 {
737 var stringBundle = document.getElementById("webdeveloper-string-bundle");
738 var title = stringBundle.getString("webdeveloper_showPasswords");
739
740 // If one password was shown
741 if(shownPasswords == 1)
742 {
743 webdeveloper_informationalDialog(title, stringBundle.getString("webdeveloper_showPasswordsSingleResult"));
744 }
745 else
746 {
747 webdeveloper_informationalDialog(title, stringBundle.getFormattedString("webdeveloper_showPasswordsMultipleResult", [shownPasswords]));
748 }
749 }
750 }
751
752 // Updates the forms menu
753 function webdeveloper_updateFormsMenu(suffix)
754 {
755 webdeveloper_configureElementByAppliedStyle(document.getElementById("webdeveloper-display-form-details-" + suffix), "checked", "webdeveloper-display-form-details");
756 }
757
758 // Displays all the forms for the page
759 function webdeveloper_viewFormInformation()
760 {
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;
771 var form = 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;
778 var formList = 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;
793 var pElement = 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]);
801
802 generatedDocument.title = title;
803
804 webdeveloper_addGeneratedStyles(generatedDocument);
805
806 headerElement.appendChild(generatedDocument.createTextNode(title));
807 bodyElement.appendChild(headerElement);
808
809 webdeveloper_addGeneratedTools(generatedDocument);
810
811 // Loop through the documents
812 for(var i = 0; i < documentLength; i++)
813 {
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");
824
825 linkElement.setAttribute("href", documentURL);
826 linkElement.appendChild(generatedDocument.createTextNode(documentURL));
827 headerElement.appendChild(linkElement);
828 bodyElement.appendChild(headerElement);
829
830 headerElement = generatedDocument.createElement("h3");
831
832 spanElement.setAttribute("class", "expanded pivot");
833 headerElement.appendChild(spanElement);
834
835 // If there is one form
836 if(formLength == 1)
837 {
838 headerElement.appendChild(generatedDocument.createTextNode(formLength + " " + stringBundle.getString("webdeveloper_form").toLowerCase()));
839 }
840 else
841 {
842 headerElement.appendChild(generatedDocument.createTextNode(formLength + " " + stringBundle.getString("webdeveloper_forms").toLowerCase()));
843 }
844
845 bodyElement.appendChild(headerElement);
846
847 // Loop through the forms
848 for(var j = 0; j < formLength; j++)
849 {
850 form = formList[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");
859
860 // Loop through the form elements
861 for(var k = 0; k < formElementsLength; k++)
862 {
863 formElementList.push(formElements[k]);
864 }
865
866 // Loop through the image input elements
867 for(k = 0; k < imageInputElementsLength; k++)
868 {
869 formElementList.push(imageInputElements[k]);
870 }
871
872 formElementsLength = formElementList.length;
873
874 headerElement.appendChild(generatedDocument.createTextNode(stringBundle.getString("webdeveloper_form")));
875 divElement.appendChild(headerElement);
876
877 // Form id heading
878 cellHeaderElement = generatedDocument.createElement("th");
879
880 cellHeaderElement.appendChild(generatedDocument.createTextNode(stringBundle.getString("webdeveloper_id")));
881 tableRowElement.appendChild(cellHeaderElement);
882
883 // Form name heading
884 cellHeaderElement = generatedDocument.createElement("th");
885
886 cellHeaderElement.appendChild(generatedDocument.createTextNode(stringBundle.getString("webdeveloper_name")));
887 tableRowElement.appendChild(cellHeaderElement);
888
889 // Form method heading
890 cellHeaderElement = generatedDocument.createElement("th");
891
892 cellHeaderElement.appendChild(generatedDocument.createTextNode(stringBundle.getString("webdeveloper_method")));
893 tableRowElement.appendChild(cellHeaderElement);
894
895 // Form action heading
896 cellHeaderElement = generatedDocument.createElement("th");
897
898 cellHeaderElement.appendChild(generatedDocument.createTextNode(stringBundle.getString("webdeveloper_action")));
899 tableRowElement.appendChild(cellHeaderElement);
900 tableElement.appendChild(tableRowElement);
901
902 tableRowElement = generatedDocument.createElement("tr");
903
904 // Form id
905 cellDataElement = generatedDocument.createElement("td");
906
907 cellDataElement.appendChild(generatedDocument.createTextNode(form.getAttribute("id")));
908 tableRowElement.appendChild(cellDataElement);
909
910 // Form name
911 cellDataElement = generatedDocument.createElement("td");
912
913 cellDataElement.appendChild(generatedDocument.createTextNode(form.getAttribute("name")));
914 tableRowElement.appendChild(cellDataElement);
915
916 // Form method
917 cellDataElement = generatedDocument.createElement("td");
918
919 cellDataElement.appendChild(generatedDocument.createTextNode(form.getAttribute("method")));
920 tableRowElement.appendChild(cellDataElement);
921
922 // Form action
923 cellDataElement = generatedDocument.createElement("td");
924
925 cellDataElement.appendChild(generatedDocument.createTextNode(form.getAttribute("action")));
926 tableRowElement.appendChild(cellDataElement);
927 tableElement.appendChild(tableRowElement);
928 divElement.appendChild(tableElement);
929
930 pElement = generatedDocument.createElement("p");
931
932 divElement.appendChild(pElement);
933
934 headerElement = generatedDocument.createElement("h3");
935 tableElement = generatedDocument.createElement("table");
936 tableRowElement = generatedDocument.createElement("tr");
937
938 headerElement.appendChild(generatedDocument.createTextNode(stringBundle.getString("webdeveloper_elements")));
939 divElement.appendChild(headerElement);
940
941 // Element index heading
942 cellHeaderElement = generatedDocument.createElement("th");
943
944 cellHeaderElement.appendChild(generatedDocument.createTextNode(stringBundle.getString("webdeveloper_index")));
945 tableRowElement.appendChild(cellHeaderElement);
946
947 // Element id heading
948 cellHeaderElement = generatedDocument.createElement("th");
949
950 cellHeaderElement.appendChild(generatedDocument.createTextNode(stringBundle.getString("webdeveloper_id")));
951 tableRowElement.appendChild(cellHeaderElement);
952
953 // Element name heading
954 cellHeaderElement = generatedDocument.createElement("th");
955
956 cellHeaderElement.appendChild(generatedDocument.createTextNode(stringBundle.getString("webdeveloper_name")));
957 tableRowElement.appendChild(cellHeaderElement);
958 tableElement.appendChild(tableRowElement);
959
960 // Element type heading
961 cellHeaderElement = generatedDocument.createElement("th");
962
963 cellHeaderElement.appendChild(generatedDocument.createTextNode(stringBundle.getString("webdeveloper_type")));
964 tableRowElement.appendChild(cellHeaderElement);
965 tableElement.appendChild(tableRowElement);
966
967 // Element value heading
968 cellHeaderElement = generatedDocument.createElement("th");
969
970 cellHeaderElement.appendChild(generatedDocument.createTextNode(stringBundle.getString("webdeveloper_value")));
971 tableRowElement.appendChild(cellHeaderElement);
972 tableElement.appendChild(tableRowElement);
973
974 // Element label heading
975 cellHeaderElement = generatedDocument.createElement("th");
976
977 cellHeaderElement.appendChild(generatedDocument.createTextNode(stringBundle.getString("webdeveloper_label")));
978 tableRowElement.appendChild(cellHeaderElement);
979
980 // Element size heading
981 cellHeaderElement = generatedDocument.createElement("th");
982
983 cellHeaderElement.appendChild(generatedDocument.createTextNode(stringBundle.getString("webdeveloper_size")));
984 tableRowElement.appendChild(cellHeaderElement);
985 tableElement.appendChild(tableRowElement);
986
987 // Element maximum length heading
988 cellHeaderElement = generatedDocument.createElement("th");
989
990 cellHeaderElement.appendChild(generatedDocument.createTextNode(stringBundle.getString("webdeveloper_maximumLength")));
991 tableRowElement.appendChild(cellHeaderElement);
992 tableElement.appendChild(tableRowElement);
993
994 // Element state heading
995 cellHeaderElement = generatedDocument.createElement("th");
996
997 cellHeaderElement.appendChild(generatedDocument.createTextNode(stringBundle.getString("webdeveloper_state")));
998 tableRowElement.appendChild(cellHeaderElement);
999 tableElement.appendChild(tableRowElement);
1000
1001 // Loop through the form elements
1002 for(k = 0; k < formElementsLength; k++)
1003 {
1004 elementStates = new Array();
1005 elementValue = "";
1006 formElement = formElementList[k];
1007 formElementId = formElement.getAttribute("id");
1008 elementType = formElement.tagName.toLowerCase();
1009 labelElement = "";
1010 labelValue = "";
1011 tableRowElement = generatedDocument.createElement("tr");
1012
1013 // If this is an even row
1014 if(k % 2 != 0)
1015 {
1016 tableRowElement.setAttribute("class", "shaded");
1017 }
1018
1019 // If the element has an id
1020 if(formElementId)
1021 {
1022 // Loop through the labels
1023 for(var l = 0; l < labelLength; l++)
1024 {
1025 labelElement = labelList[l];
1026
1027 // If this is the label for the element
1028 if(labelElement.hasAttribute("for") && labelElement.getAttribute("for") == formElementId)
1029 {
1030 labelValue = labelElement.innerHTML;
1031 }
1032 }
1033 }
1034
1035 // If this is an input element
1036 if(elementType == "input")
1037 {
1038 elementType = formElement.getAttribute("type");
1039 elementValue = formElement.value;
1040 }
1041 else if(elementType == "textarea")
1042 {
1043 elementValue = formElement.value;
1044 }
1045
1046 // If the element is checked
1047 if(formElement.checked)
1048 {
1049 elementStates.push("Checked");
1050 }
1051
1052 // If the element is disabled
1053 if(formElement.disabled)
1054 {
1055 elementStates.push("Disabled");
1056 }
1057
1058 // If the element is read only
1059 if(formElement.readOnly)
1060 {
1061 elementStates.push("Readonly");
1062 }
1063
1064 elementStatesLength = elementStates.length;
1065
1066 // Element index
1067 cellDataElement = generatedDocument.createElement("td");
1068
1069 cellDataElement.appendChild(generatedDocument.createTextNode(k));
1070 tableRowElement.appendChild(cellDataElement);
1071 tableElement.appendChild(tableRowElement);
1072
1073 // Element id
1074 cellDataElement = generatedDocument.createElement("td");
1075
1076 cellDataElement.appendChild(generatedDocument.createTextNode(formElementId));
1077 tableRowElement.appendChild(cellDataElement);
1078
1079 // Element name
1080 cellDataElement = generatedDocument.createElement("td");
1081
1082 cellDataElement.appendChild(generatedDocument.createTextNode(formElement.getAttribute("name")));
1083 tableRowElement.appendChild(cellDataElement);
1084 tableElement.appendChild(tableRowElement);
1085
1086 // Element type
1087 cellDataElement = generatedDocument.createElement("td");
1088
1089 cellDataElement.appendChild(generatedDocument.createTextNode(elementType));
1090 tableRowElement.appendChild(cellDataElement);
1091 tableElement.appendChild(tableRowElement);
1092
1093 // Element value
1094 cellDataElement = generatedDocument.createElement("td");
1095
1096 cellDataElement.appendChild(generatedDocument.createTextNode(elementValue));
1097 tableRowElement.appendChild(cellDataElement);
1098 tableElement.appendChild(tableRowElement);
1099
1100 // Element label
1101 cellDataElement = generatedDocument.createElement("td");
1102
1103 cellDataElement.appendChild(generatedDocument.createTextNode(labelValue));
1104 tableRowElement.appendChild(cellDataElement);
1105 tableElement.appendChild(tableRowElement);
1106
1107 // Element size
1108 cellDataElement = generatedDocument.createElement("td");
1109
1110 cellDataElement.appendChild(generatedDocument.createTextNode(formElement.getAttribute("size")));
1111 tableRowElement.appendChild(cellDataElement);
1112 tableElement.appendChild(tableRowElement);
1113
1114 // Element maximum length
1115 cellDataElement = generatedDocument.createElement("td");
1116
1117 cellDataElement.appendChild(generatedDocument.createTextNode(formElement.getAttribute("maxlength")));
1118 tableRowElement.appendChild(cellDataElement);
1119 tableElement.appendChild(tableRowElement);
1120
1121 // Element state
1122 cellDataElement = generatedDocument.createElement("td");
1123
1124 // Loop through the element states
1125 for(l = 0; l < elementStatesLength; l++)
1126 {
1127 pElement = generatedDocument.createElement("p");
1128
1129 pElement.appendChild(generatedDocument.createTextNode(elementStates[l]));
1130 cellDataElement.appendChild(pElement);
1131 }
1132
1133 tableRowElement.appendChild(cellDataElement);
1134 tableElement.appendChild(tableRowElement);
1135 }
1136
1137 tableElement.setAttribute("class", "sortable");
1138 divElement.setAttribute("class", "output");
1139 divElement.appendChild(tableElement);
1140 divElement.appendChild(generatedDocument.createElement("hr"));
1141 bodyElement.appendChild(divElement);
1142 }
1143 }
1144
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);
1149
1150 scriptElement = generatedDocument.createElement("script");
1151
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);
1156
1157 scriptElement = generatedDocument.createElement("script");
1158
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);
1163
1164 scriptElement = generatedDocument.createElement("script");
1165
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);
1170
1171 // If the open tabs in background preference is set to true
1172 if(webdeveloper_getBooleanPreference("webdeveloper.open.tabs.background", true))
1173 {
1174 getBrowser().selectedTab = oldTab;
1175 }
1176 }