Hi!

I'm using browscap and adaptivetheme "Mobile Regions and Blocks" extension to hide some regions in mobile.

It works very well, but the same region becomes hidden in tablet also: I don't want this.

Is it possible to have the same configuration for an ipotetic "$is_tablet" as well as "$is_mobile"?

Thank you very much for considering this.

CommentFileSizeAuthor
#17 mobile-tablet-1793534-17.patch4.17 KBmpdonadio

Comments

Jeff Burnz’s picture

At this stage I don't know, I need to look into what browsecap can return, I am not entirely sure it can return a group such as "tablets".

mxt’s picture

Thank you Jeff, I've opened a support request in browscap issue queue: http://drupal.org/node/1794072

Jeff Burnz’s picture

Status: Active » Postponed (maintainer needs more info)

OK, lets postpone this for now based on the outcome of that issue.

mxt’s picture

Status: Postponed (maintainer needs more info) » Active
Jeff Burnz’s picture

Status: Active » Postponed

OK, well I am going to postpone this again because at the moment I don't have the time to craft a feature such as that employed by Mobile Tools - I kind of know how it does it but am not sure this can even run in a theme (maybe, maybe not).

Of course patches are more than welcome and certainly when I get time I can revisit this.

What I would say is that its probably pointless reinventing what Mobile Tools does and we could look at using that as a dependency at getting device groups, such as tablet.

mxt’s picture

Thank you,

ok, I'm going to investigate this: http://drupal.org/project/context_mobile_detect and this: http://mobiledrupal.com/content/using-context-module-mobile-tools-create...

I'll come back here to report potential solutions

mxt’s picture

Ok, I can confirm that the combination:

context + context_mobile_detect

works like a charm!

This allow you to set visibility for regions or blocks based on device groups (mobile, tablet, desktop)

The only issue is that within the same device group, there isn't yet a detection for "isPortrait" or "isLandscape" that definitively would complete the solution.
I've already leaved a request to the php base library: http://code.google.com/p/php-mobile-detect/wiki/Roadmap

Other possible solutions for this lack:

  1. If Context had had support reactions based on media queries conditions would be resolutive (here's a thread on this: http://drupal.org/node/1026022)
  2. With mobile_tools maybe everyone can write a personal plugin to include "landscape/portrait" detection as described here: http://mobiledrupal.com/content/create-your-own-device-detection-algorit...

Any other thoughts?

Jeff Burnz’s picture

"isPortrait" or "isLandscape" is actually not a good idea - this would force a page refresh between orientation changes - can you imagine the page suddenly refreshing because you moved a bit while looking at your iPad?

I'll take a look at the mobile detect lib, looks promising.

Jeff Burnz’s picture

Status: Postponed » Active

Cool, I found this: http://drupal.org/sandbox/matthew.donadio/1780496

I have asked the developer to promote that to a full project, so with that running as a dependency we can have our is_tablet and other conditions and start building some logic around it.

crispinbailey’s picture

Very cool development. +1

mpdonadio’s picture

Mobile Detect was promoted to full project status: http://drupal.org/project/mobile_detect

Currently dev version only, but will be doing more testing and working towards a proper 1.0 release.

Jeff Burnz’s picture

Awesome, I'm gonna make this full steam ahead with this feature using Mobile Detect, I think thats great news and something we can really make heavy use of.

mpdonadio’s picture

Jeff, do you plan on working this into your existing framework? I started to look into making a patch for this, but wasn't sure reworking at_get_browser() to return an object/array with the $is_tablet and $is_mobile properties would break things for end users.

I also have an uncomitted patch for http://drupal.org/node/1824042, but am still pondering whether it is a good idea (it's just template_preprocess that sets variables for a few hooks). If this would help you, I can commit/push it.

Jeff Burnz’s picture

I think that's a way forward, to rework at_get_browser to return an object, aka

$detect = mobile_detect_get_object();

Fine, I am totally down with that. I will need to document this in case anyone has actually used at_get_browser().

I'm interested in the performance of mobile detect, as you notice at_get_browser() is cached, can the object be cached, or is this simply not worth it?

The one small issue, which I am sure you identified, is that we need to still set $is_mobile when the user only has Browscap installed. I think I am somewhat keen to see this in at_get_browser() itself, rather than say in template_preprocess() or hook_page_alter() (the two main places at_get_browser is called in AT Core).

So yeah, a patch to re do at_get_browser is the first step, if we can do that now and worry about the rest later (the major refactoring in adaptivetheme_page_alter for example).

Jeff Burnz’s picture

On the template_preprocess issue, well, it could be useful, for me its not really important since I would do that anyway, AT Core calls at_get_browser in adaptivetheme_preprocess(), and I can't really stop doing that now, maybe in Drupal 8 I could, but for now I am kind of stuck with that approach. Suggestions welcome of course.

mpdonadio’s picture

Jeff, I have a decent idea for this in my head. It's actually mostly simple, and should help future proof this process a bit. I'll post a patch in the next few days.

mpdonadio’s picture

Status: Active » Needs review
StatusFileSize
new4.17 KB

First pass.

at_get_browser() now returns an associative array.

$browser = at_get_browser();
$is_mobile = $browser['is_mobile'];
$is_tablet = $browser['is_tablet'];

The thing I am not really sure about is that $is_mobile and $is_tablet are now mixed. TRUE/FALSE if the feature was detected properly, NULL if the feature could not be determined.

It also leaves the Mobile_Detect semantics that $is_mobile will also be TRUE when $is_tablet is TRUE. Not sure what is best here, as both arguments are valid.

Updated the docs in node.tpl.php as a first shot, but let the rest alone.

I think I have it corrected everywhere it needs to be, but I am not terribly familiar with the internals.

I also don't have a working site with Browscap installed right now for regression testing, but I will get to this soon.

Jeff Burnz’s picture

It also leaves the Mobile_Detect semantics that $is_mobile will also be TRUE when $is_tablet is TRUE. Not sure what is best here, as both arguments are valid.

Agreed, tricky one, I will need to work through the overall logic in the theme and put some thought into it. Great start!

Jeff Burnz’s picture

Status: Needs review » Needs work

OK, I have applied and tested, so we're half way there.

I will rework the Float Region Blocks feature in the theme to use these new options, which means a total re-write of the forms and the logic in hook_page_alter(), as it all gets a lot more complicated. I'm done with the form at this stage and in the next few days will complete the logic that will allow you to unset or move blocks in all mobile devices or just smartphone - which I assume is what we want in this theme - either unset or move blocks in all regions or just smartphone, thus leaving them untouched in tablet, as per the original feature request.

Peeps, I have to add one caveat, I am really fighting for backwards compatibility but it might be a stretch, I can't promise it will be pefectly backwards compatible, but I will try!

mxt’s picture

Thank you guys for working on this.

Just FYI, context_mobile_detect team is working to obtain "isPortrait" and "isLandscape" (see http://drupal.org/node/1796454#comment-6698364)

Jeff Burnz’s picture

Status: Needs work » Fixed

These few features are in the dev version now, I committed this today. As per usual pull from GIT or wait for the archive to update with todays commits (normally 24 hours from now).

Please see this help page for details, http://adaptivethemes.com/documentation/mobile-regions-and-blocks-changes

Hopefully I will have time to add some screenshots and so on to that help page - there are new setting which, if using Mobile Detect module, allow you to move or hide regions/blocks in either all mobile devices, or just smartphone.

There is a new variable in all templates, for completeness I will mention both variables:

  • $is_mobile: Mixed, requires the Mobile Detect or Browscap module to return TRUE for mobile. Note that tablets are also considered mobile devices. Returns NULL if the feature could not be detected.
  • $is_tablet: Mixed, requires the Mobile Detect to return TRUE for tablets. Returns NULL if the feature could not be detected.

Note that the help page mentions AT 7.x-3.2, which technically has not been released yet (but will be shortly), think of this as the dev version.

If you are using Browscap make sure you are runnint the latest version (7.x-2.0) at this time and be sure to visit the Browscap settings in Drupal to check if the Current browscap data version has been updated (if there is a number there you should be right).

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.