From: Antoine Q. <an...@gr...> - 2001-09-18 17:32:00
|
> > In the gradients module, there is a function called at init > that looks > > up the DOM tree for the shapes filled with the gradients that are > > i:gradient enabled. So what I do is look through > > doc.getElementsByTagName('*') and I check each element's > "fill" property > > to see if it refers to the specified gradient. > > This is extremely expensive, are you sure there's no better > way ? Wouldn't > you be able to specify the targets on the gradient or > something like that ? > > <i:gradient> > <i:target xlink:href='#foo'> > <i:target xlink:href='#bar'> > </i:gradient> Of course, I could do that... But I really want to keep it as simple as possible, and since there was a way to avoid doing this... I may rethink the syntax then. How about doing: <rect style="fill:url(#my_gradient)"> <i:gradient xlink:href="#k_gradient"> <i:target xlink:href="#target" attributeName="fill" /> <i:target xlink:href="#target" attributeName="stroke" /> <i:target xlink:href="#coords" attributeName="fill" /> </i:gradient> </rect> This way we would now what is the gradient holder (the parent node). > > Problem is that before I > > read the "fill" property I need to check if that particular element > > allows for the Style interface (getStyle()) to be called. > > > > Anybody knows how to do this? > > I'm presently looking into ways of making E262 really OO, and > it's not > looking nice (it's even less OO than Java !). You might try > element.prototype.hasOwnProperty('style'), that should > normally tell you > whether your object has a property called style, which is needed by > getStyle(). However I wouldn't be surprised if it didn't > work. Another option > is to do the tricks people do in browsers (eval'ing to see if > it works, > testing the returned value to be an object, etc). Also note > that it is > possible -- though marginal -- that an element would have a > getStyle() method > that is not what you expect (this could happen with embedded > XHTML for > instance). That could have nasty side-effects (as most abuses > of polymorphism > would). A dirty trick works sometimes, and that is checking hasAttribute('style'), but it completely defeats the purpose of CSS since this would not support cascading. The eval way might well be the least awful option. antoine |