SVG adds style.filter - now, where have we seen that before?
Tuesday, February 16, 2010 9:36:31 PM
<circle style="filter: url(#someCoolEffectDefinedOverThere)">and IE allows you to do something like
<div style="filter: alpha(opacity=50)">This means that a browser supporting SVG will define element.style.filter - and all versions of IE you want to care about also define element.style.filter. So if you're writing a generic script and see a random element with a style.filter property - how do you know what filter syntax is supported? We discovered this problem due to failing opacity effects - scripts doing
if(typeof element.style.filter != 'undefined'){
// IE syntax
}else{
// standards-compliant syntax
}
suddenly saw style.filter defined and started giving us IE-code. Seems Firefox is about to come across those compatibility problems too..
Of course it raises a red flag when we add something that causes new compatibility issues. It has been raised as an issue with the SVG working group, who discussed it and decided to sweep the issue under the carpet with an informative warning in the spec.
For compatibility, we're considering hiding style.filter like we hide document.all. That is not a good solution, however. We want scripts to be able to detect that SVG filters can be manipulated from JavaScript, and we want them to do so through good, old, best-practice object detection.
Microsoft will actually save us by re-naming filter to ms-filter. That's excellent, if late, and they still have the problem that millions of existing sites use IE-style CSS filters. It would have been the perfect solution had they done it back when their CSS filters were invented.. I still welcome their initiative, but at this point it probably won't make any difference for many years ahead. Right now, we're stuck with confusion. I'm worried that we're breaking established best-practice (object detection) and forcing people down the dirty road of browser sniffing. I think it will be confusing that HTML elements get a "filter" property that will presumably only work when set on SVG elements.
Now.. changing SVG's footprint in the CSS DOM wouldn't suffer from legacy content problems. My preferred solution would be to make sure "filter" only appears on the .style object of real SVG elements, and that it's named svgFilter in the DOM rather than just "filter", to make it easier to detect.
What do you all think?








zoquete # Wednesday, February 17, 2010 12:23:17 AM
They will make the oposite, as usually. It will cause only new problems. :'( Use differente syntax or keyword-name!!! Please
Gyrobo # Wednesday, February 17, 2010 12:37:06 AM
lucideer # Wednesday, February 17, 2010 12:38:24 AM
J. KingMTKnight # Wednesday, February 17, 2010 4:15:54 AM
The realities of SVG adoption on the Web and inline in Web browsers at large has really changed the game, no doubt.
Charles SchlossChas4 # Wednesday, February 17, 2010 4:40:44 AM
What does the W3C say?
serious # Wednesday, February 17, 2010 7:16:50 AM
+1 to your prefered solution
Jeff WaldenWaldo # Wednesday, February 17, 2010 8:05:29 AM
I tentatively think svgFilter makes sense. Regarding not exposing it on non-SVG content, do consider that Mozilla has proposed extending its use into non-SVG content and has implemented such as an extension. It doesn't seem unreasonable to think this may eventually be standardized more broadly; a sui generis decision (I think this culling of properties in this manner is without precedent) to remove filter from non-SVG content seems pretty odd and perhaps even premature.
sirnh1 # Wednesday, February 17, 2010 8:21:09 AM
Microsoft's solution is useless because it's only for IE8 (if I understood correctly), but where I work we are still expected to support IE6 and IE7 (since most people companies here still use IE6
Mark 'Tarquin' Wilton-Jonestarquinwj # Wednesday, February 17, 2010 8:25:02 AM
HTMLDivElement.style -> CSSStyleDeclaration
SVGCircleElement.style -> CSSStyleDeclaration
CSSStyleRule.style -> CSSStyleDeclaration
getComputedStyle() -> CSSStyleDeclaration
In particular, CSSStyleRule.style poses a problem, since it is what is used by DOM StyleSheets to represent each style rule in the stylesheet. A stylesheet can be applied to multiple documents or namespaces at the same time, so it can apply to a HTMLDivElement at the same time as a SVGCircleElement. That means that both the SVGCircleElement.style and CSSStyleRule.style would need to use the same CSSStyleDeclaration prototype, so the property was correctly exposed within a stylesheet. The only way I can see this working is for CSSStyleDeclaration (by default) to use a hidden 'filter' property, then have SVGCircleElement.style and CSSStyleRule.style use a special custom one that is not exposed for custom prototyping (CompleteCSSStyleDeclaration?) that inherits from CSSStyleDeclaration (including its .toString), and then also provides a visible 'filter' property.
I am not sure how it should work with getComputedStyle, as it would need to cope with all of those scripts (jQuery, for example) that frequently read all computed properties, and change the element's properties accordingly.
Are there any obvious problems with using the CompleteCSSStyleDeclaration approach? The first one I can see is that if someone uses CSSStyleDeclaration.prototype.filter, it won't work properly.
This all feels very messy, of course.
Anonymous # Wednesday, February 17, 2010 8:29:39 AM
_Grey_ # Wednesday, February 17, 2010 10:22:38 AM
Do not override .filter in CompleteCSSStyleDeclaration (make it 'magic' if necessary). By default, CSSStyleDeclaration.prototype.filter is 'invisible'. If the user changes the property, make it visible (and inherit that to CompleteCSSStyleDeclaration). That should work.
Of course a user could break his own content that way if he relies on the IE filter property elsewhere, but that's his own fault, isn't it?
zoquete # Wednesday, February 17, 2010 11:01:26 AM
Hallvord R. M. Steenhallvors # Wednesday, February 17, 2010 12:17:48 PM
Robert Longson: cool idea to extend it to HTML elements.
I think on the contrary - isn't that a fairly obvious way to signal that we're dealing with the "filter" syntax from the SVG spec? There is presedence for re-naming things in the DOM so that it doesn't conflict with the host language, for example when attributes have same name as an ECMAScript reserved word.
Such naming would also work better if other languages define "filter" style and are integrated into HTML. For example if MathML wants to use CSS to define number formatting, they might invent something like 'filter:"### ###.##"'.
zoquete: don't know how hypotethical namespaces in CSS would be integrated with the DOM interfaces. So the answer is "it depends.."
lucideer # Wednesday, February 17, 2010 1:50:11 PM
Naming it svgFilter would confuse people if it were added to HTML, and also just generally be a hackish and unconventional naming system.
Renaming properties to avoid clashes with ECMAScript reserved words doesn't generally restrict those properties to be tied to a certain language or usage in future - renaming class to className is fine because "name" is a generic word that doesn't imply anything about the behaviour of html class attributes, "SVG" implies a lot.
Surely the best (only good?) solution would be to change it in spec. Obviously SVG1.1 is a recommendation, and therefore set in stone, but there are sections of previous W3C specs that have never been implemented (things like DOM2's createCSSStylesheet that was only ever added to Konqueror) - couldn't filter be changed to something different for SVG1.2 and SVG1.1 just skipped over by implementors?
João EirasxErath # Wednesday, February 17, 2010 2:47:07 PM
lucideer # Wednesday, February 17, 2010 3:24:39 PM
<circle class="bob" ... /> <div class="bob" ... > ... </div> <style> .bob{ filter:url(#someCoolEffectDefinedOverThere); } ... ... .bob{ filter:alpha(opacity=50); } </style>? Edit: Excessive linespacing above seems a myOpera editor bug - inserts breaks into pre tags.._Grey_ # Wednesday, February 17, 2010 3:36:12 PM
edit: We could even hold a contest to create this snippet.
That way, we can avoid rewriting browsers, since web devs will be able to just drop a line of code into their product and be done with it. If this were published on ALA, maybe it would gain even more traction.
MyOpera team, please fix this!fearphage # Wednesday, February 17, 2010 5:00:45 PM
Originally posted by João Eiras:
I actually thought that was the whole point of this: svg applied to html.https://developer.mozilla.org/En/Applying_SVG_effects_to_HTML_content
https://developer.mozilla.org/web-tech/2008/09/15/svg-effects-for-html-content/
BONUS: svg + css3 transformations +
Anonymous # Wednesday, February 17, 2010 7:24:58 PM
Anonymous # Wednesday, February 17, 2010 7:52:22 PM
Hallvord R. M. Steenhallvors # Saturday, February 20, 2010 7:48:35 PM
Originally posted by anonymous:
All experience tells me that we'll struggle with this problem for YEARS due to object detection in legacy content. Further, SVG-supporting browser vendors are likely to work around that in the hackish "hide style.filter" way, breaking object detection for future script and probably making authors resort to browser sniffing.
Originally posted by anonymous:
I don't think you really paid attention to what the blog post was about
This is one example of a script that will no longer work as expected (unless browsers do weird things to work around your scripting).
Somebody suggesting to do the wrong thing after presumably having read this article might indicate just how much this is going to confuse people...
lucideer # Saturday, February 20, 2010 8:26:24 PM
Originally posted by Jeff Schiller:
Getting them to update to -ms-filter is one thing, getting them to drop filter as well is another - most will simply keep both for compatibility, particularly if they're unaware of this issue as they'll see no reason not to.
Consider that even today we have many sites that, while some may have been updated to include modern standards-compliant code, still have IE4 compat code in their scripts that they've just never bothered removing.
Anonymous # Tuesday, February 23, 2010 7:58:53 AM
Anonymous # Tuesday, February 23, 2010 8:01:37 AM
Anonymous # Thursday, February 25, 2010 12:09:18 AM
lucideer # Thursday, February 25, 2010 2:14:50 PM
Originally posted by anonymous:
No. The post was about the implementation in the browser, not about how web developers should or shouldn't detect support. The code sample was merely one example of how they might fail to properly detect support - there are obviously ways to detect support successfully (as you've demonstrated) but that doesn't help the browser deal with those using the unsuccessful methods.
Hallvord R. M. Steenhallvors # Thursday, February 25, 2010 11:58:17 PM
Originally posted by anonymous:
You're right, I didn't at first notice the plural form. This might help with the feature detection - sort of - except that all browsers supporting "SVG filters" will already have hidden style.filter when scripts get updated to pay attention to element.filters :-/
_Grey_ # Friday, February 26, 2010 5:42:31 PM
Anonymous # Friday, May 7, 2010 12:56:38 AM
Anonymous # Wednesday, August 25, 2010 3:16:28 PM