javascript MDL-24521 Fixed confirm dialog bug. Kudos to John Anderson for his work...
authorSam Hemelryk <sam@moodle.com>
Wed, 5 Jan 2011 06:02:42 +0000 (14:02 +0800)
committerSam Hemelryk <sam@moodle.com>
Wed, 5 Jan 2011 06:02:42 +0000 (14:02 +0800)
lib/javascript-static.js

index d79230d..93643ba 100644 (file)
@@ -262,15 +262,17 @@ M.util.show_confirm_dialog = function(e, args) {
                 return;
             }
 
-            if (target.get('tagName').toLowerCase() == 'a') {
+            var targetancestor = null,
+                targetform = null;
+
+            if (target.test('a')) {
                 window.location = target.get('href');
-            } else if (target.get('tagName').toLowerCase() == 'input') {
-                var parentelement = target.get('parentNode');
-                while (parentelement.get('tagName').toLowerCase() != 'form' && parentelement.get('tagName').toLowerCase() != 'body') {
-                    parentelement = parentelement.get('parentNode');
-                }
-                if (parentelement.get('tagName').toLowerCase() == 'form') {
-                    parentelement.submit();
+            } else if ((targetancestor = target.ancestor('a')) !== null) {
+                window.location = targetancestor.get('href');
+            } else if (target.test('input')) {
+                targetform = target.ancestor('form');
+                if (targetform && targetform.submit) {
+                    targetform.submit();
                 }
             } else if (M.cfg.developerdebug) {
                 alert("Element of type " + target.get('tagName') + " is not supported by the M.util.show_confirm_dialog function. Use A or INPUT");