Skip to content

Instantly share code, notes, and snippets.

@YannickFricke
Forked from flipflop/gist:1263020
Created October 4, 2011 22:34
Show Gist options
  • Save YannickFricke/1263050 to your computer and use it in GitHub Desktop.
Save YannickFricke/1263050 to your computer and use it in GitHub Desktop.
Mobile Detection with Optional Zepto / jQuery include
<?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