Chris@0
|
1 {% autoescape 'js' %}
|
Chris@0
|
2 (function (xpath) {
|
Chris@0
|
3 function getElement(xpath) {
|
Chris@0
|
4 var polterAgent = window.__poltergeist;
|
Chris@0
|
5 var ids = polterAgent.find("xpath", xpath, document);
|
Chris@0
|
6 var polterNode = polterAgent.get(ids[0]);
|
Chris@0
|
7 return polterNode.element;
|
Chris@0
|
8 }
|
Chris@0
|
9
|
Chris@0
|
10 function inputRadioGetValue(element){
|
Chris@0
|
11 var value = null;
|
Chris@0
|
12 var name = element.getAttribute('name');
|
Chris@0
|
13 if (!name){
|
Chris@0
|
14 return null;
|
Chris@0
|
15 }
|
Chris@0
|
16 var fields = window.document.getElementsByName(name);
|
Chris@0
|
17 var i;
|
Chris@0
|
18 var l = fields.length;
|
Chris@0
|
19 for (i = 0; i < l; i++) {
|
Chris@0
|
20 var field = fields.item(i);
|
Chris@0
|
21 if (field.form === element.form && field.checked) {
|
Chris@0
|
22 return field.value;
|
Chris@0
|
23 }
|
Chris@0
|
24 }
|
Chris@0
|
25 return null;
|
Chris@0
|
26 }
|
Chris@0
|
27
|
Chris@0
|
28 var node = getElement(xpath);
|
Chris@0
|
29 var tagName = node.tagName.toLowerCase();
|
Chris@0
|
30 var value = null;
|
Chris@0
|
31 if (tagName == "input") {
|
Chris@0
|
32 var type = node.type.toLowerCase();
|
Chris@0
|
33 if (type == "checkbox") {
|
Chris@0
|
34 value = node.checked ? node.value : null;
|
Chris@0
|
35 } else if (type == "radio") {
|
Chris@0
|
36 value = inputRadioGetValue(node);
|
Chris@0
|
37 } else {
|
Chris@0
|
38 value = node.value;
|
Chris@0
|
39 }
|
Chris@0
|
40 } else if (tagName == "textarea") {
|
Chris@0
|
41 value = node.value;
|
Chris@0
|
42 } else if (tagName == "select") {
|
Chris@0
|
43 if (node.multiple) {
|
Chris@0
|
44 value = [];
|
Chris@0
|
45 for (var i = 0; i < node.options.length; i++) {
|
Chris@0
|
46 if (node.options[i].selected) {
|
Chris@0
|
47 value.push(node.options[i].value);
|
Chris@0
|
48 }
|
Chris@0
|
49 }
|
Chris@0
|
50 } else {
|
Chris@0
|
51 var idx = node.selectedIndex;
|
Chris@0
|
52 if (idx >= 0) {
|
Chris@0
|
53 value = node.options.item(idx).value;
|
Chris@0
|
54 } else {
|
Chris@0
|
55 value = null;
|
Chris@0
|
56 }
|
Chris@0
|
57 }
|
Chris@0
|
58 } else {
|
Chris@0
|
59 value = node.value;
|
Chris@0
|
60 }
|
Chris@0
|
61 return value;
|
Chris@0
|
62 }('{{ xpath }}'));
|
Chris@0
|
63 {% endautoescape %}
|