changeset 6:78c426daaa89

Tweak JavaScript to make it possible to roll back unwise Ur/Web runtime system change
author Adam Chlipala <adam@chlipala.net>
date Sat, 31 Dec 2011 15:24:27 -0500
parents 9dca7b936311
children 35cacb3eaf6e
files src/js/ajaxUpload.js
diffstat 1 files changed, 42 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/js/ajaxUpload.js	Thu Dec 29 16:31:23 2011 -0500
+++ b/src/js/ajaxUpload.js	Sat Dec 31 15:24:27 2011 -0500
@@ -1,17 +1,51 @@
+function tweakFormCode(autoSubmit, iframeId, submitId) {
+    var subm = document.getElementById(submitId);
+    if (subm == null && thisScript != null && thisScript.parentNode != null && thisScript.parentNode.getElementsByTagName) {
+        var subms = thisScript.parentNode.getElementsByTagName("input");
+        for (var i = 0; i < subms.length; ++i)
+            if (subms[i].id == submitId) {
+                subm = subms[i];
+                break;
+            }
+    }
+    if (subm == null) er("Can't find AjaxUpload control!");
+
+    subm.parentNode.target = iframeId;
+
+    if (subm.begin == undefined) {
+        subm.begin = subm.onmousedown;
+        subm.onmousedown = undefined;
+    }
+
+    subm.parentNode.onsubmit = function() {
+        subm.begin();
+        return true;
+    };
+
+    if (subm.withHandle == undefined) {
+        subm.withHandle = subm.onkeydown;
+        subm.onkeydown = undefined;
+    }
+
+    if (autoSubmit) {
+        subm.style.visibility = "hidden";
+        for (var node = subm.previousSibling; node.tagName != "INPUT"; node = node.previousSibling);
+        node.onchange = function() { subm.parentNode.submit(); };
+    }
+}
+
 function tweakForm(autoSubmit, iframeId, submitId) {
     return "<iframe id=\""
         + iframeId
         + "\" name=\""
         + iframeId
-        + "\" src=\"#\" style=\"width:0;height:0;border:0px solid #fff;\"></iframe>\n<script type=\"text/javascript\">var subm = document.getElementById(\""
+        + "\" src=\"#\" style=\"width:0;height:0;border:0px solid #fff;\"></iframe>\n<script type=\"text/javascript\">tweakFormCode("
+        + autoSubmit
+        + ",\""
+        + iframeId
+        + "\",\""
         + submitId
-        + "\"); subm.parentNode.target = \""
-        + iframeId
-        + "\"; if (subm.begin == undefined) { subm.begin = subm.onmousedown; subm.onmousedown = undefined; } subm.parentNode.onsubmit = function() { subm.begin(); return true; }; if (subm.withHandle == undefined) { subm.withHandle = subm.onkeydown; subm.onkeydown = undefined; } "
-        + (autoSubmit
-           ? "subm.style.visibility = \"hidden\"; for (var node = subm.previousSibling; node.tagName != \"INPUT\"; node = node.previousSibling); node.onchange = function() { subm.parentNode.submit(); }; "
-           : "")
-        + "</script>";
+        + "\");</script>";
 }
 
 function idToString(x) {