On Apr 22, 7:14 pm, Tim Snadden <tim.snad...@gmail.com> wrote:
> Hi all - I've extended Prototype.BrowserFeatures and thought I'd check  
> with those in the know whether this makes sense as an approach or how  
> it could be improved. Basically I want to test to see if the browser  
> supports setting border-radius with CSS so that I can only use  
> javascript methods for browsers that need it. alphaPNG is to test  
> whether or not I need to use any hacks to make transparency work for  
> IE6. I don't know of any way to actually test that feature so I just  
> basically sniffed for 'less than IE7'.
>
> Object.extend(Prototype.BrowserFeatures,{
>         borderRadius: (
>                 function(){
>                         var radiusTest = $(document).createElement('div');
>                         try {
>                                 return !!(
>                                         
> radiusTest.getStyle('-webkit-border-radius') !== undefined ||
>                                         
> radiusTest.getStyle('-moz-border-radius') !== undefined ||
>                                         radiusTest.getStyle('border-radius') 
> !== undefined
>                                 );
>                         }                      
>                         catch(x) {
>                                 return false;
>                         }
>                 }()
>         ),      
>         alphaPNG: !(Prototype.Browser.IE && !window.XMLHttpRequest)
>
> });
>
> Thanks for your input, Tim

You shouldn't need try/catch for merely testing types of certain
properties.  I would check `borderRadius` first, since it's a standard
CSS3 property. `el` also needs to be `null`ed. I think a more
descriptive name for the test would be `hasBorderRadius` (instead of
`borderRadius`) - to denote that it is of a boolean value.

...
hasBorderRadius: (function(){
  var el = document.createElement('div');
  var s = el.style;
  var result = typeof s.borderRadius == 'string' ||
                   typeof s.MozBorderRadius == 'string' ||
                   typeof s.WebkitBorderRadius == 'string';
  el = null;
  return result;
})()
...

--
kangax
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to