Version 1
[yaffs-website] / vendor / jcalderonzumba / mink-phantomjs-driver / src / Resources / Script / is_checked.js.twig
diff --git a/vendor/jcalderonzumba/mink-phantomjs-driver/src/Resources/Script/is_checked.js.twig b/vendor/jcalderonzumba/mink-phantomjs-driver/src/Resources/Script/is_checked.js.twig
new file mode 100644 (file)
index 0000000..6b14cad
--- /dev/null
@@ -0,0 +1,31 @@
+{% autoescape 'js' %}
+(function (xpath) {
+  function getElement(xpath, within) {
+    var result;
+    if (within === null || within === undefined) {
+      within = document;
+    }
+    result = document.evaluate(xpath, within, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
+    if (result.snapshotLength !== 1) {
+      return null;
+    }
+    return result.snapshotItem(0);
+  }
+
+  var node = getElement(xpath);
+
+  if (node === null) {
+    return null;
+  }
+
+  if(node.tagName.toLowerCase() != "input"){
+    return null;
+  }
+
+  if(node.type.toLowerCase() != "checkbox" && node.type.toLowerCase() != "radio"){
+    return null;
+  }
+
+  return node.checked;
+}('{{ xpath }}'));
+{% endautoescape %}