views:

51

answers:

1

IE appears to be choking on the following line 2207 from the uncompressed raphaeljs 1.4.7 (in the context of my code, of course):

gs.left != (t = left + "px") && (gs.left = t);

I'm unfamiliar with the != syntax in this context so I'm finding difficult to figure out what is going on or why IE might be unhappy about it. I've tested in IE6 & IE8, and Chrome & Firefox on OSX. Of course I'd step through using firebug if it was a problem in FF...

Can you tell me what that line is trying to achieve, and even better, can you see why IE might potentially be having a problem with it?

For your context, here's the full method with that line in it:

    Element[proto].setBox = function (params, cx, cy) {
        if (this.removed) {
            return this;
        }
        var gs = this.Group.style,
            os = (this.shape && this.shape.style) || this.node.style;
        params = params || {};
        for (var i in params) if (params[has](i)) {
            this.attrs[i] = params[i];
        }
        cx = cx || this._.rt.cx;
        cy = cy || this._.rt.cy;
        var attr = this.attrs,
            x,
            y,
            w,
            h;
        switch (this.type) {
            case "circle":
                x = attr.cx - attr.r;
                y = attr.cy - attr.r;
                w = h = attr.r * 2;
                break;
            case "ellipse":
                x = attr.cx - attr.rx;
                y = attr.cy - attr.ry;
                w = attr.rx * 2;
                h = attr.ry * 2;
                break;
            case "image":
                x = +attr.x;
                y = +attr.y;
                w = attr.width || 0;
                h = attr.height || 0;
                break;
            case "text":
                this.textpath.v = ["m", round(attr.x), ", ", round(attr.y - 2), "l", round(attr.x) + 1, ", ", round(attr.y - 2)][join](E);
                x = attr.x - round(this.W / 2);
                y = attr.y - this.H / 2;
                w = this.W;
                h = this.H;
                break;
            case "rect":
            case "path":
                if (!this.attrs.path) {
                    x = 0;
                    y = 0;
                    w = this.paper.width;
                    h = this.paper.height;
                } else {
                    var dim = pathDimensions(this.attrs.path);
                    x = dim.x;
                    y = dim.y;
                    w = dim.width;
                    h = dim.height;
                }
                break;
            default:
                x = 0;
                y = 0;
                w = this.paper.width;
                h = this.paper.height;
                break;
        }
        cx = (cx == null) ? x + w / 2 : cx;
        cy = (cy == null) ? y + h / 2 : cy;
        var left = cx - this.paper.width / 2,
            top = cy - this.paper.height / 2, t;
        gs.left != (t = left + "px") && (gs.left = t);
        gs.top != (t = top + "px") && (gs.top = t);
        this.X = pathlike[has](this.type) ? -left : x;
        this.Y = pathlike[has](this.type) ? -top : y;
        this.W = w;
        this.H = h;
        if (pathlike[has](this.type)) {
            os.left != (t = -left * zoom + "px") && (os.left = t);
            os.top != (t = -top * zoom + "px") && (os.top = t);
        } else if (this.type == "text") {
            os.left != (t = -left + "px") && (os.left = t);
            os.top != (t = -top + "px") && (os.top = t);
        } else {
            gs.width != (t = this.paper.width + "px") && (gs.width = t);
            gs.height != (t = this.paper.height + "px") && (gs.height = t);
            os.left != (t = x - left + "px") && (os.left = t);
            os.top != (t = y - top + "px") && (os.top = t);
            os.width != (t = w + "px") && (os.width = t);
            os.height != (t = h + "px") && (os.height = t);
        }
    };
A: 

There’s nothing wrong with that line of code — assuming gs.left and left are defined. It’s equivalent to:

t = left + 'px';
if (gs.left != t) gs.left = t;

What exactly do you mean by “choking”?

byoogle
Thanks byoogle. I'm not suggesting there's anything wrong with this line of code, I just wanted to understand it. IE is reporting one of its ambiguous Error on Page: Invalid Arguments on this line while other browsers carry on.
Andrew
Got it. So my best guess is, in IE, “gs” isn’t getting defined as an object with a “left” property up the call stack. I’d start by alerting “gs”, “gs.left”, and “left” to make sure you have what you’re supposed to by the fatal line.
byoogle