bugbuster/mobiledetection

Contao辅助类,用于检测手机和平板(设备类型)。钩子会在body标签中添加CSS类。

安装: 139

依赖: 0

建议者: 0

安全: 0

星标: 1

关注者: 3

分支: 0

开放问题: 1

类型:contao-module

3.5.0 2014-10-27 23:19 UTC

This package is auto-updated.

Last update: 2024-09-23 10:03:23 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

关于

基于"http://mobiledetect.net/"的Contao 3模块"Mobile-Detection"

开发者辅助类。包含演示前端模块。

安装

手动安装

通过Composer

钩子有帮助!

钩子会在页面的CSS类(在body标签中)中添加一个特殊类

  • phone : 手机设备,但不是平板
  • tablet : 手机设备和平板
  • computer : 没有手机设备,也没有平板

示例

Galaxy S II (Phone)

  • <body id="top" class="android safari webkit sf4 mobile phone">

Motorola Xoom (Tablet)

  • <body id="top" class="android safari webkit sf3 mobile tablet">

Linux Mint PC (Computer)

  • <body id="top" class="unix firefox gecko fx18 computer">

使用类

你有两种选择

  • 你使用的是原始类(Detection\MobileDetect)。
  • 你使用的是包装类(MobileDetection\Mobile_Detection)。

Mobile_Detect (原始类)

ER2版本(原始类的无命名空间版本)

include '<path>/Mobile_Detect.php';

$detect = new Mobile_Detect();

继续阅读下一节中的描述。

Composer版本(原始类的命名空间版本)

use Detection\MobileDetect;

$detect = new MobileDetect(); 

// Check for any mobile device.
if ($detect->isMobile())
 
// Check for any tablet.
if($detect->isTablet())
 
// Check for any mobile device, excluding tablets.
if ($detect->isMobile() && !$detect->isTablet())

要查看可用方法的完整列表,请检查目录examples

Mobile_Detection (包装类)

$this->import('\MobileDetection\Mobile_Detection','Mobile_Detection');

// Check device type
echo $this->Mobile_Detection->getDeviceType(); // phone|tablet|computer

// Check for any mobile device.
if ($this->Mobile_Detection->isMobile())

// Check for any tablet.
if ($this->Mobile_Detection->isTablet())

// Check mobile grade
echo $this->Mobile_Detection->getMobileGrade(); // A|B|C

// Check mobile rules
$arrRules = $this->Mobile_Detection->getMobileRules(); 
// result e.g. array('SamsungTablet','AndroidOS','Safari')

请参阅演示模块"MobileDetectionDemo"。