Opened 9 years ago

Closed 4 years ago

#11242 closed defect (fixed)

style disparity (string vs. hash)

Reported by: bill Owned by: bill
Priority: high Milestone: 2.0
Component: Parser Version: 1.5.0b2
Keywords: Cc: dante
Blocked By: Blocking:

Description

Sometimes the style parameter is passed to widgets as a string like

"width: 300px; height: 300px"

rather than as a hash like

{
   width: "300px",
   height: "300px"
}

In a similar vein, widget.get("style") can return either a string or a hash.

For consistency, and for widgets to easier handle the style argument, it probably makes sense for

  1. define style as a hash (for programmatic widget creation)
  2. make the parser convert style from a string to hash, as per the following code:
// test case string
var str = "border-width: 100px; foo-bar-zaz: 3; font-family: 'arial unicode ms' ; ";

// string --> hash conversion code
var clauses = dojo.trim(str).split(";"),
    hash = {};
for(var i=0; i<clauses.length; i++){
    var split = clauses[i].indexOf(":");
    console.log("split of " + clauses[i] + " is " + split);
    if(split > 0){
        var name = dojo.trim(clauses[i].substr(0, split)).
                  replace(/-[a-z]/g, function(foo){ return foo[1].toUpperCase(); }),	// border-width --> borderWidth
            value = clauses[i].substr(split+1).replace(/^\s*['"]?/, "").
                  replace(/['"]?\s*$/, "");	// trim spaces + quotes
        if(name && value){
            hash[name] = value;
        }
    }
}

console.log("result: ", dojo.toJson(hash));

Not sure if that's sufficient or if there are other case issues to deal with; maybe name should be converted to lowercase before the - replacement.

Change History (1)

comment:1 Changed 4 years ago by bill

Resolution: fixed
Status: newclosed

Closing as fixed in 2.0 because https://github.com/ibm-js/deliteful always handles style as a string.

Note: See TracTickets for help on using tickets.