PointedEars
-- Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Andrew Poulos wrote:
> On 10/02/2012 11:38 PM, Thomas 'PointedEars' Lahn wrote:
>> Andrew Poulos wrote:
>>> Alas, IE 9 supports window.getComputedStyle but not camel-cased CSS
>>> property names. So I tried this
>>> function getElStyle(el, IEcssPropName, cssPropName) {
>>> if (window.getComputedStyle) {
>>> return document.defaultView.getComputedStyle(el,
>>> null).getPropertyValue(cssPropName) ||
>>> document.defaultView.getComputedStyle(el,
>>> null).getPropertyValue(IEcssPropName);
>>> and it seems to work. Is there a better way?
>> Yes.
> Good, could you tell what it is?
Yes.
(This would actually be funny for me if it was not so disappointing.)
PointedEars
-- Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300d...@news.demon.co.uk>
>> On 10/02/2012 11:38 PM, Thomas 'PointedEars' Lahn wrote:
>>> Andrew Poulos wrote:
>>>> Alas, IE 9 supports window.getComputedStyle but not camel-cased CSS
>>>> property names. So I tried this
>>>> function getElStyle(el, IEcssPropName, cssPropName) {
>>>> if (window.getComputedStyle) {
>>>> return document.defaultView.getComputedStyle(el,
>>>> null).getPropertyValue(cssPropName) ||
>>>> document.defaultView.getComputedStyle(el,
>>>> null).getPropertyValue(IEcssPropName);
Andrew Poulos wrote:
> On 10/02/2012 11:55 PM, Thomas 'PointedEars' Lahn wrote:
>> Andrew Poulos wrote:
>>> On 10/02/2012 11:38 PM, Thomas 'PointedEars' Lahn wrote:
>>>> Andrew Poulos wrote:
>>>>> Alas, IE 9 supports window.getComputedStyle but not camel-cased CSS
>>>>> property names. So I tried this
>>>>> function getElStyle(el, IEcssPropName, cssPropName) {
>>>>> if (window.getComputedStyle) {
>>>>> return document.defaultView.getComputedStyle(el,
>>>>> null).getPropertyValue(cssPropName) ||
>>>>> document.defaultView.getComputedStyle(el,
>>>>> null).getPropertyValue(IEcssPropName);
Tim Streater wrote:
> Thomas 'PointedEars' Lahn <PointedE...@web.de> wrote:
>> Andrew Poulos wrote:
>> > On 10/02/2012 11:55 PM, Thomas 'PointedEars' Lahn wrote:
>> >> Andrew Poulos wrote:
>> >>> On 10/02/2012 11:38 PM, Thomas 'PointedEars' Lahn wrote:
>> >>>> Andrew Poulos wrote:
>> >>>>> […] it seems to work. Is there a better way?
>> >>>> Yes.
>> >>> Good, could you tell what it is?
>> >> Yes.
>> >> (This would actually be funny for me if it was not so disappointing.)
>> > Its disappointing to me as well.
>> All you need to do is asking a *smart* question.
> My advice, Andrew, is to tell him to fuck off. I have and have never
> regretted it.
You cannot miss what you never had in the first place.
>> On 10/02/2012 11:55 PM, Thomas 'PointedEars' Lahn wrote:
>>> Andrew Poulos wrote:
>>>> On 10/02/2012 11:38 PM, Thomas 'PointedEars' Lahn wrote:
>>>>> Andrew Poulos wrote:
>>>>>> Alas, IE 9 supports window.getComputedStyle but not camel-cased CSS
>>>>>> property names. So I tried this
>>>>>> function getElStyle(el, IEcssPropName, cssPropName) {
>>>>>> if (window.getComputedStyle) {
>>>>>> return document.defaultView.getComputedStyle(el,
>>>>>> null).getPropertyValue(cssPropName) ||
>>>>>> document.defaultView.getComputedStyle(el,
>>>>>> null).getPropertyValue(IEcssPropName);
>>>>>> and it seems to work. Is there a better way?
>>>>> Yes.
>>>> Good, could you tell what it is?
>>> Yes.
>>> (This would actually be funny for me if it was not so disappointing.)
>> Its disappointing to me as well.
> All you need to do is asking a *smart* question.
I think you are misleading me as it doesn't look like there's a better way.
One option I found is to put the currentStyle test first but that doesn't really resolve the fact getComputedStyle will fail with IE 9 and camel-cased CSS properties.
DM's recent tip only uses getComputedStyle and specifically excludes non camel-cased CSS properties so his function will fail in every flavour of IE.
Andrew Poulos wrote:
> On 11/02/2012 9:46 AM, Thomas 'PointedEars' Lahn wrote:
>> Andrew Poulos wrote:
>>> On 10/02/2012 11:55 PM, Thomas 'PointedEars' Lahn wrote:
>>>> Andrew Poulos wrote:
>>>>> On 10/02/2012 11:38 PM, Thomas 'PointedEars' Lahn wrote:
>>>>>> Andrew Poulos wrote:
>>>>>>> Alas, IE 9 supports window.getComputedStyle but not camel-cased CSS
>>>>>>> property names. So I tried this
>>>>>>> function getElStyle(el, IEcssPropName, cssPropName) {
>>>>>>> if (window.getComputedStyle) {
>>>>>>> return document.defaultView.getComputedStyle(el,
>>>>>>> null).getPropertyValue(cssPropName) ||
>>>>>>> document.defaultView.getComputedStyle(el,
>>>>>>> null).getPropertyValue(IEcssPropName);
>>>>>>> and it seems to work. Is there a better way?
>>>>>> Yes.
>>>>> Good, could you tell what it is?
>>>> Yes.
>>>> (This would actually be funny for me if it was not so disappointing.)
>>> Its disappointing to me as well.
>> All you need to do is asking a *smart* question.
> I think you are misleading me as it doesn't look like there's a better
> way.
Wrong on both accounts. For crying out loud, a *closely related* question has been asked (presumably, *again*) on StackOverflow *yesterday*, and I have commented on the other answers there, eventually referring to JSX:css.js (which does not consider getPropertyValue() yet – as the shorthand is optional, and potentially less efficient thanks to camel-casing –, but soon):
> One option I found is to put the currentStyle test first
It is wrong to put the `currentStyle' test and branch first. Proprietary approaches should only be the fallback or alternative to standards-compliant ones. Not only because the former are more error-prone, but also because they can be removed easier once they are not needed anymore.
> but that doesn't really resolve the fact getComputedStyle will fail with
> IE 9 and camel-cased CSS properties.
Wrong (just tested again). getComputedStyle() "fails" with IE 9(.0.8112.16421 on Windows 7) in *Compatibility* Mode, but not in Standards Mode, and it "fails" in IE < 9, of course.
(That URL is from the first page of Google hits. "HTML5" is M$'s marketing department talking, though; this method is part of W3C DOM Level 2 *Style*, and HTML5 refers to DOM Level 3 *Events* only.
Thomas 'PointedEars' Lahn wrote:
> Andrew Poulos wrote:
>> I think you are misleading me as it doesn't look like there's a better
>> way.
> Wrong on both accounts. For crying out loud, a *closely related* question
> has been asked (presumably, *again*) on StackOverflow *yesterday*, and I
> have commented on the other answers there, eventually referring to
> JSX:css.js (which does not consider getPropertyValue() yet – as the
> shorthand is optional, and potentially less efficient thanks to
> camel-casing –, but soon):
> […] >> but that doesn't really resolve the fact getComputedStyle will fail with
>> IE 9 and camel-cased CSS properties.
> Wrong (just tested again). getComputedStyle() "fails" with IE
> 9(.0.8112.16421 on Windows 7) in *Compatibility* Mode, but not in
> Standards Mode, and it "fails" in IE < 9, of course.
Well, *partially* wrong. getComputedStyle() does not fail with IE 9 per se.
But it does fail even in Standards Mode with camel-cased CSS properties because getPropertyValue() expects the *real* CSS property name. It is specified so in the W3C DOM Level 2 Style Specification:
Hence my assumption that the use of getPropertyValue() might turn out to be more efficient than using the optional shorthand with the camel-cased property name.
PointedEars
--
> If you get a bunch of authors […] that state the same "best practices"
> in any programming language, then you can bet who is wrong or right...
Not with javascript. Nonsense propagates like wildfire in this field.
-- Richard Cornford, comp.lang.javascript, 2011-11-14
Thomas 'PointedEars' Lahn wrote:
> Andrew Poulos wrote:
>> I think you are misleading me as it doesn't look like there's a better
>> way.
> Wrong on both accounts. For crying out loud, a *closely related* question
> has been asked (presumably, *again*) on StackOverflow *yesterday*, and I
> have commented on the other answers there, eventually referring to
> JSX:css.js (which does not consider getPropertyValue() yet – as the
> shorthand is optional, and potentially less efficient thanks to
> camel-casing –, but soon):
> […] >> but that doesn't really resolve the fact getComputedStyle will fail with
>> IE 9 and camel-cased CSS properties.
> Wrong (just tested again). getComputedStyle() "fails" with IE
> 9(.0.8112.16421 on Windows 7) in *Compatibility* Mode, but not in
> Standards Mode, and it "fails" in IE < 9, of course.
Well, *partially* wrong. getComputedStyle() does not fail with IE 9 per se.
But it does fail even in Standards Mode with camel-cased CSS properties because getPropertyValue() expects the *real* CSS property name. It is specified so in the W3C DOM Level 2 Style Specification:
Hence my assumption that the use of getPropertyValue() might turn out to be more efficient than using the optional shorthand with the camel-cased property name, especially as you need to map "float" to "cssFloat" or "styleFloat" aso.
PointedEars
--
> If you get a bunch of authors […] that state the same "best practices"
> in any programming language, then you can bet who is wrong or right...
Not with javascript. Nonsense propagates like wildfire in this field.
-- Richard Cornford, comp.lang.javascript, 2011-11-14
On 12/02/2012 1:21 AM, Thomas 'PointedEars' Lahn wrote:
> Thomas 'PointedEars' Lahn wrote:
>> Andrew Poulos wrote:
>>> I think you are misleading me as it doesn't look like there's a better
>>> way.
>> Wrong on both accounts. For crying out loud, a *closely related* question
>> has been asked (presumably, *again*) on StackOverflow *yesterday*, and I
>> have commented on the other answers there, eventually referring to
>> JSX:css.js (which does not consider getPropertyValue() yet – as the
>> shorthand is optional, and potentially less efficient thanks to
>> camel-casing –, but soon):
>> […]
>>> but that doesn't really resolve the fact getComputedStyle will fail with
>>> IE 9 and camel-cased CSS properties.
>> Wrong (just tested again). getComputedStyle() "fails" with IE
>> 9(.0.8112.16421 on Windows 7) in *Compatibility* Mode, but not in
>> Standards Mode, and it "fails" in IE< 9, of course.
> Well, *partially* wrong. getComputedStyle() does not fail with IE 9 per se.
> But it does fail even in Standards Mode with camel-cased CSS properties
> because getPropertyValue() expects the *real* CSS property name. It is
> specified so in the W3C DOM Level 2 Style Specification:
> Hence my assumption that the use of getPropertyValue() might turn out to be
> more efficient than using the optional shorthand with the camel-cased
> property name, especially as you need to map "float" to "cssFloat" or
> "styleFloat" also.
Andrew Poulos wrote:
> On 12/02/2012 1:21 AM, Thomas 'PointedEars' Lahn wrote:
>> Thomas 'PointedEars' Lahn wrote:
>>> Andrew Poulos wrote:
>>>> I think you are misleading me as it doesn't look like there's a better
>>>> way.
>>> Wrong on both accounts. For crying out loud, a *closely related*
>>> question has been asked (presumably, *again*) on StackOverflow
>>> *yesterday*, and I
See above. However, you have neglected to test potential differences between Standards Compliance and Quirks Mode in all cases. It is possible that `currentStyle' is available in Gecko's Quirks Mode as is `document.all'.
Andrew Poulos wrote:
> On 12/02/2012 1:21 AM, Thomas 'PointedEars' Lahn wrote:
>> Thomas 'PointedEars' Lahn wrote:
>>> Andrew Poulos wrote:
>>>> I think you are misleading me as it doesn't look like there's a better
>>>> way.
>>> Wrong on both accounts. For crying out loud, a *closely related*
>>> question has been asked (presumably, *again*) on StackOverflow
>>> *yesterday*, and I
See above. However, you have neglected to test potential differences between Standards Compliance and Quirks Mode in all cases. It is possible that `currentStyle' is available in Gecko's Quirks Mode as is `document.all'.