Question

I have a test which will change depending on certain user interactions. I'm trying to tie this into modernizr.

I'm trying to force a test to re-run by calling addTest again.

//this works the first time
//adds html.mousing class
Modernizr.addTest('mousing',function(){
    return true;
});


//later in the code
//this DOES NOT add html.no-mousing
Modernizr.addTest('mousing',function(){
    return false;
});

Any ideas how to rerun or refresh a modernizer test?

Was it helpful?

Solution

Modernizr is made to test browser functionality not arbitrarily toggle classes based on user interactions. (Just because a user has interacted with your page does not mean the browser is all of a sudden incapable of "mousing"). You are better off not adding this as a Modernizr test and simply adding/remove classnames when you need to.

However, to answer your question, you would need to delete the cached value of mousing on Modernizr and re-run the test while additionally manually removing any matching classnames on the html element. Something like:

Modernizr.addTest('mousing',function(){
  return true;
});
/* ... */
delete Modernizr.mousing;
Modernizr.addTest('mousing',function(){
  document.html.className = document.html.className.replace(/\b(no-)?mousing\b/g, '');
  return false;
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top