// Improvement when detect mobile

This commit is contained in:
lLefevre
2012-09-07 08:04:01 +00:00
parent 10a1581751
commit 864fc3d405
+13 -4
View File
@@ -98,11 +98,21 @@ class ContextCore
*/
public $smarty;
/**
* @ var Mobile Detect
*/
public $mobile_detect;
/**
* @var boolean|string mobile device of the customer
*/
protected $mobile_device;
public function __construct()
{
$this->mobile_detect = new Mobile_Detect();
}
public function getMobileDevice()
{
if (is_null($this->mobile_device))
@@ -110,20 +120,19 @@ class ContextCore
$this->mobile_device = false;
if ($this->checkMobileContext())
{
$detect = new Mobile_Detect();
switch ((int)Configuration::get('PS_ALLOW_MOBILE_DEVICE'))
{
case 1: // Only for mobile device
if ($detect->isMobile() && !$detect->isTablet())
if ($this->mobile_detect->isMobile() && !$this->mobile_detect->isTablet())
$this->mobile_device = true;
break;
case 2: // Only for touchpads
if ($detect->isTablet() && !$detect->is_mobile())
if ($this->mobile_detect->isTablet() && !$this->mobile_detect->is_mobile())
$this->mobile_device = true;
break;
case 3: // For touchpad or mobile devices
if ($detect->isMobile() || $detect->isTablet())
if ($this->mobile_detect->isMobile() || $this->mobile_detect->isTablet())
$this->mobile_device = true;
break;
}