dynamically load ratchet android/iPhone css themes based on the device

318 Views Asked by At

I am looking for any lightweight, expressive, intuitive, or eloquent way to select CSS themes dynamically for the Goratch library.

I would love something from AngularJs, such as ng-include if etc.

CDN links

http://cdnjs.com/libraries/ratchet
1

There are 1 best solutions below

1
On

I went with this option. If you're running PHP

function userAgent() {
    $iPod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
    $iPhone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
    $iPad = strpos($_SERVER['HTTP_USER_AGENT'],"iPad");
    $android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");

    if($iPad||$iPhone||$iPod) {
        return 'ios';
    } else if($android) {
        return 'android';
    } else {
        return 'pc';
    }
}

Then something like:

<?php if(userAgent() == 'android') { ?>
    <link rel="stylesheet" href="/web/css/ratchet-theme-android.min.css">
<?php } else { // etc...?>
    <link rel="stylesheet" href="/web/css/ratchet-theme-ios.min.css">
<? } ?>