-
-
Save YannickFricke/1263050 to your computer and use it in GitHub Desktop.
Mobile Detection with Optional Zepto / jQuery include
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$deviceClass = ""; | |
$graduateLevelClass = ""; | |
if (ereg('iPhone',$_SERVER['HTTP_USER_AGENT']) || ereg('iPod',$_SERVER['HTTP_USER_AGENT'])) { | |
$deviceClass = "ui-iphone"; | |
} else if (ereg('iPad',$_SERVER['HTTP_USER_AGENT'])) { | |
$deviceClass = "ui-ipad"; | |
} else if (ereg('Android',$_SERVER['HTTP_USER_AGENT']) && ereg('Mobile Safari',$_SERVER['HTTP_USER_AGENT'])) { | |
$deviceClass = "ui-android"; | |
}; | |
?> | |
<?php | |
if($deviceClass == "ui-iphone" || $deviceClass == "ui-ipad" || $deviceClass == "ui-android") { | |
?> | |
<script src="js/lib/zepto.min.js"></script> | |
<?php | |
} else { | |
?> | |
<script src="js/lib/jquery-min.js"></script> | |
<?php | |
} | |
?> | |
<!-- Script Module usage example --> | |
<script> | |
;(function($, doc, undefined){ | |
// $ will be assigned to Zepto or jQuery depending on PHP | |
// for desktop (jQuery) or mobile (Zepto) support re-using the same code | |
}(this.Zepto || this.jQuery, document)); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment