Skip to content

Instantly share code, notes, and snippets.

@flipflop
Last active September 27, 2015 11:28
Show Gist options
  • Save flipflop/1263020 to your computer and use it in GitHub Desktop.
Save flipflop/1263020 to your computer and use it in GitHub Desktop.
Mobile Detection with Optional Zepto / jQuery include
<?php
$deviceClass = "";
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
}(window.Zepto || window.jQuery, document));
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment