From 9ac6556d5a73418c17156b1378322ca19d1766a7 Mon Sep 17 00:00:00 2001 From: nightwing Date: Tue, 15 Mar 2016 17:23:21 +0400 Subject: [PATCH] fix el.attributes is not an array error --- plugins/c9.ide.dialog/dialog.js | 29 +++-------------------------- plugins/c9.ide.ui/forms.js | 33 +++++---------------------------- 2 files changed, 8 insertions(+), 54 deletions(-) diff --git a/plugins/c9.ide.dialog/dialog.js b/plugins/c9.ide.dialog/dialog.js index ab25a3f7..77f36633 100644 --- a/plugins/c9.ide.dialog/dialog.js +++ b/plugins/c9.ide.dialog/dialog.js @@ -245,38 +245,15 @@ define(function(require, module, exports) { dropdown.setAttribute("value", item.value); break; default: - // Attributes we are happy to set directly - var validAttributes = [ - "value", - "visible", - "zindex", - "disabled", - "caption", - "tooltip", - "command", - "class", - "icon", - "src", - "submenu" - ]; - + // supported attributes + var validAttributes = /^(value|visible|zindex|disabled|caption|tooltip|command|class|icon|src|submenu)$/; Object.keys(item).forEach(function(key) { // Check for onclick explictly if (key === "onclick") return el.onclick = item.onclick; - // Check for attributes we know exist and will directly set - if (validAttributes.indexOf(key) > -1) + if (validAttributes.test(key)) return 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 4aaf2d45..31171f9d 100644 --- a/plugins/c9.ide.ui/forms.js +++ b/plugins/c9.ide.ui/forms.js @@ -481,38 +481,15 @@ define(function(require, exports, module) { } break; default: - // Attributes we are happy to set directly - var validAttributes = [ - "value", - "visible", - "zindex", - "disabled", - "caption", - "tooltip", - "command", - "class", - "icon", - "src", - "submenu" - ]; - + // supported attributes + var validAttributes = /^(value|visible|zindex|disabled|caption|tooltip|command|class|icon|src|submenu)$/; Object.keys(item).forEach(function(key) { // Check for onclick explictly if (key === "onclick") - return el.lastChild.onclick = item.onclick; - + return el.onclick = item.onclick; // Check for attributes we know exist and will directly set - if (validAttributes.indexOf(key) > -1) - return 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]); - } + if (validAttributes.test(key)) + return el.setAttribute(key, item[key]); }); break; }