Feature Request: Handle Embedded Object Attributes
Closed this issue · 2 comments
DamonOehlman commented
Not sure if this is something you want to add Kory, but I just found myself trying to do this (mainly to see if it would work):
crel('div', {
class: 'blah',
data: {
caption: 'A Test caption'
}
});
To see if the HTML element generated would contain a data-caption
attribute. Might be a nice feature to add at some stage if it doesn't increase the size of crel too much. Also, I can't remember if you mentioned that someone had already implemented this in another fork somewhere...
KoryNunn commented
This is not something I would want to add as core functionality, however, it should be able to be added already using the attribute map object.
This would probably work:
crel.attrMap['data'] = function(element, value){
for(var key in value){
if(value.hasOwnProperty(key)){
element.setAttribute('data-' + key, JSON.stringify(value[key]));
}
}
};
DamonOehlman commented
Nice Kory - I'll have a look into that and if it works, add some README goodness...