diff --git a/plugins/c9.ide.dialog/dialog.js b/plugins/c9.ide.dialog/dialog.js index 21f49bfc..ab25a3f7 100644 --- a/plugins/c9.ide.dialog/dialog.js +++ b/plugins/c9.ide.dialog/dialog.js @@ -245,20 +245,38 @@ define(function(require, module, exports) { dropdown.setAttribute("value", item.value); break; default: - if ("onclick" in item) - el.onclick = item.onclick; - - var ignoreList = ["onclick"]; + // Attributes we are happy to set directly + var validAttributes = [ + "value", + "visible", + "zindex", + "disabled", + "caption", + "tooltip", + "command", + "class", + "icon", + "src", + "submenu" + ]; Object.keys(item).forEach(function(key) { - if (ignoreList.indexOf(key) > -1) return; + // Check for onclick explictly + if (key === "onclick") + return el.onclick = item.onclick; - var attributeExists = el.attributes.some(function(attribute) { - return (attribute.name === key) - }); + // Check for attributes we know exist and will directly set + if (validAttributes.indexOf(key) > -1) + return el.setAttribute(key, item[key]); - if (attributeExists) - el.setAttribute(key, item[key]); + // Otherwise, check if the object has the attribute to set + if (el.attributes) { + var attributeExists = el.attributes.some(function(attribute) { + return (attribute.name === key); + }); + if (attributeExists) + el.setAttribute(key, item[key]); + } }); break; } diff --git a/plugins/c9.ide.ui/forms.js b/plugins/c9.ide.ui/forms.js index 1a4072d0..4aaf2d45 100644 --- a/plugins/c9.ide.ui/forms.js +++ b/plugins/c9.ide.ui/forms.js @@ -481,20 +481,38 @@ define(function(require, exports, module) { } break; default: - if ("onclick" in item) - el.lastChild.onclick = item.onclick; - - var ignoreList = ["onclick"]; + // Attributes we are happy to set directly + var validAttributes = [ + "value", + "visible", + "zindex", + "disabled", + "caption", + "tooltip", + "command", + "class", + "icon", + "src", + "submenu" + ]; Object.keys(item).forEach(function(key) { - if (ignoreList.indexOf(key) > -1) return; + // Check for onclick explictly + if (key === "onclick") + return el.lastChild.onclick = item.onclick; - var attributeExists = el.lastChild.attributes.some(function(attribute) { - return (attribute.name === key) - }); + // Check for attributes we know exist and will directly set + if (validAttributes.indexOf(key) > -1) + return el.lastChild.setAttribute(key, item[key]); - if (attributeExists) - el.lastChild.setAttribute(key, item[key]); + // Otherwise, check if the object has the attribute to set + if (el.lastChild && el.lastChild.attributes) { + var attributeExists = el.lastChild.attributes.some(function(attribute) { + return (attribute.name === key); + }); + if (attributeExists) + el.lastChild.setAttribute(key, item[key]); + } }); break; }