Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Builder doesn't copy the style attribute correctly. #13

Open
wyuenho opened this issue Jul 4, 2010 · 1 comment
Open

Builder doesn't copy the style attribute correctly. #13

wyuenho opened this issue Jul 4, 2010 · 1 comment

Comments

@wyuenho
Copy link

wyuenho commented Jul 4, 2010

Problem:

var div = Builder.node("div", {style: {top: 10px, left: 20px}});

Builder._attributes just copies the dict to the style member of the

HTMLElement, but this doesn't work quite right because browsers don't really know how to type convert a dict to a CSSStyleDeclaration object. So you are forced to use a really long text string.

It would be better if _attributes copies the attributes recursively. Something like this:

for (var attr in attributes) {
  attr = JSON.parse(attr);
    if (attr) {
       for (k in attr) {
          element[attr][k] = attr[k];
       }
    }
}

The actual code will of course need to prevent cyclic references and set a depth of the copying if needed. This should take care of the general case where one wants to set the properties of any nested objects on any DOM elements.

@mislav
Copy link
Collaborator

mislav commented Jul 5, 2010

I don't think this case warrants changing how attributes are applied. You could have just used:

Builder.node(...).setStyle({ top: 10px, ... })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants