Re: [WSG] Testing styling availability when using JavaScript

2010-08-05 Thread Josh Godsiff

On 5/8/2010 8:03 PM, Foskett, Mike wrote:


The scenario I'm thinking of is JS available but no CSS, either 
unavailable or switched off.





Unless you're working on some sort of project where there's a high 
likelyhood that that will occur, don't bother - in the real world, the 
number of people with a JS-on CSS-off configuration is probably less 
than 0.5%.


- Josh Godsiff
-- oxideinteractive.com.au 


***
List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm
Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm
Help: memberh...@webstandardsgroup.org
***

[WSG] Testing styling availability when using JavaScript

2010-08-05 Thread Foskett, Mike
Hi All,

Is there any advantage to testing the availability of styling before running 
scripts?

The scenario I'm thinking of is JS available but no CSS, either unavailable or 
switched off.
Something like:

var cssOn;

var gotStyle=function(){

  function init(){
// Simon Willisons - http://simonwillison.net/2004/May/26/addLoadEvent/
function addLoadEvent(f){var o=window.onload;if(typeof 
window.onload!='function'){window.onload=f;}else{window.onload=function(){if(o){o();}f();};}}

// mike foskett - 
http://websemantics.co.uk/resources/useful_javascript_functions/
function hasCSS(){var 
d=document.createElement('div');d.id="hasCSS";document.body.appendChild(d);var 
o=document.getElementById("hasCSS"),v=false;if(window.getComputedStyle){v=(window.getComputedStyle(o,null).getPropertyValue('display')==='none');}else{if(o.currentStyle){v=(o.currentStyle.display==='none');}}document.body.removeChild(d);return
 v;}

addLoadEvent(function(){
cssOn=hasCSS();
});

  }

  return{
init:init
  };

}();

gotStyle.init();


In the CSS:
#hasCSS {display:none}



The above:
1. waits for page load
2. appends a test element
3. applies a style to it
4. tests for the applied style
5. sets the global variable accordingly
6. removes the test element



Regards,

Mike



This is a confidential email. Tesco may monitor and record all emails. The 
views expressed in this email are those of the sender and not Tesco.

Tesco Stores Limited
Company Number: 519500
Registered in England
Registered Office: Tesco House, Delamare Road, Cheshunt, Hertfordshire EN8 9SL
VAT Registration Number: GB 220 4302 31


***
List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm
Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm
Help: memberh...@webstandardsgroup.org
***