Skip to content

Instantly share code, notes, and snippets.

View jonarnes's full-sized avatar

Jon Arne S. jonarnes

View GitHub Profile
@jonarnes
jonarnes / script.js
Last active August 29, 2015 13:58
wurfl.js css bridge
/*Adding a CSS class to the html element (Modernizr-style)*/
document.documentElement.className += ' ' + (WURFL.is_mobile ? '' : 'no-') + "mobile"; /*adds class="mobile" or class="no-mobile" to html element*/
document.documentElement.className += ' ' + WURFL.form_factor.toLowerCase(); /*Adding the formfactor as class name to html element*/
document.documentElement.className += ' ' + WURFL.complete_device_name.toLowerCase().replace(/\s+/g, ''); /*Removing spaces, and puts the complete device name as the class name on html element*/
/*...or using data- attributes. In the CSS we can then do stuff like:*/
document.documentElement.setAttribute('data-device_name', WURFL.complete_device_name);
document.documentElement.setAttribute('data-form_factor', WURFL.form_factor );
document.documentElement.setAttribute('data-is_mobile', WURFL.is_mobile );