Changed update() command to check for explicit attributes and fall back to checking the attributes array if it exists

This commit is contained in:
Rob Moran 2016-03-10 11:01:06 +00:00 committed by nightwing
parent 784b3edaec
commit e8ad218fb6
2 changed files with 56 additions and 20 deletions

View File

@ -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;
}

View File

@ -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;
}