scriptaculous icon indicating copy to clipboard operation
scriptaculous copied to clipboard

Builder doesn't copy the style attribute correctly.

Open wyuenho opened this issue 15 years ago • 1 comments

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.

wyuenho avatar Jul 04 '10 09:07 wyuenho

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

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

mislav avatar Jul 05 '10 09:07 mislav