MDL-36609 javascript: ensure HTML element exists before attempting to perform JS...
authorMark Nelson <markn@moodle.com>
Mon, 19 Nov 2012 07:43:46 +0000 (15:43 +0800)
committerMark Nelson <markn@moodle.com>
Mon, 19 Nov 2012 07:43:46 +0000 (15:43 +0800)
lib/javascript-static.js

index fa0dfc0..2c4e368 100644 (file)
@@ -340,11 +340,16 @@ M.util.init_maximised_embed = function(Y, id) {
         if (Y.Lang.isString(el)) {
             el = Y.one('#' + el);
         }
-        var val = el.getStyle(prop);
-        if (val == 'auto') {
-            val = el.getComputedStyle(prop);
+        // Ensure element exists.
+        if (el) {
+            var val = el.getStyle(prop);
+            if (val == 'auto') {
+                val = el.getComputedStyle(prop);
+            }
+            return parseInt(val);
+        } else {
+            return 0;
         }
-        return parseInt(val);
     };
 
     var resize_object = function() {