bugbuster/contao-mobiledetection-bundle

此包已被废弃,不再维护。未建议替代包。

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

1.0.2 2021-01-22 22:39 UTC

This package is auto-updated.

Last update: 2024-04-23 07:49:30 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

Codacy Badge

关于

基于 "http://mobiledetect.net/" 的 Contao 4 "Mobile-Detection" 包

为开发者提供的辅助类。演示前端模块存在。

安装

使用 Contao Manager

使用 Composer

  • composer require bugbuster/contao-mobiledetection-bundle
  • Composer 加载了额外的 "mobiledetect/mobiledetectlib" 版本 2.*

钩子帮助!

钩子向页面CSS类(在body标签中)添加特殊类

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

示例

Galaxy S II(手机)

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

Motorola Xoom(平板)

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

Linux Mint PC(计算机)

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

使用类

您有两种选择

  • 您正在使用原始类(Detection\MobileDetect)。
  • 您正在使用包装类(BugBuster\MobileDetection\Mobile_Detection)。

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(包装类)

use BugBuster\MobileDetection\Mobile_Detection;
...
$this->Mobile_Detection = new 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”演示模块。