bugbuster / mobiledetection
Contao辅助类,用于检测手机和平板(设备类型)。钩子会在body标签中添加CSS类。
3.5.0
2014-10-27 23:19 UTC
Requires
- php: >=5.3
- contao-community-alliance/composer-plugin: *
- contao/core: >=3,<4
- mobiledetect/mobiledetectlib: 2.*
Replaces
- contao-legacy/mobiledetection: 3.5.0
This package is auto-updated.
Last update: 2024-09-23 10:03:23 UTC
README
关于
基于"http://mobiledetect.net/"的Contao 3模块"Mobile-Detection"
开发者辅助类。包含演示前端模块。
安装
手动安装
- 不要使用GitHub的ZIP文件!使用ER2 mobiledetection
通过Composer
- 搜索bugbuster/mobiledetection,版本 >= 3.5
- composer加载了额外的"mobiledetect/mobiledetectlib"版本2.*
钩子有帮助!
钩子会在页面的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())
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"。