Proposal for Supporting Mobile Themes and Browser Detection

Proposal for Supporting Mobile Themes and Browser Detection

by Anthony Forth -
Number of replies: 26

At The Open University we're working actively on mobile support for mobile.  We would be grateful for your comments on the below.  The OU would expect to undertake the work involved.  There also a bug here http://tracker.moodle.org/browse/MDL-25394

Introduction
This document proposes some additions to Moodle 2.1 to enable detection of mobile devices so that additional or alternative functionality can be provided.  This would allow blocks, modules, etc to take advantage of mobile functionality (cameras, geo-location, etc); make more subtle adjustments within a mobile context; or to develop modules or blocks that are only for use on mobile devices.

It also specifies a means for administrators to select a theme for mobile devices.  This provides an alternative to using @media rules within a ‘modern browser’ theme with the associated issues this may bring for users with larger displays (loss of features or unfamiliar layout if resizing a browser window).  As a separate exercise, The Open University also intend to submit a mobile theme for possible inclusion in Moodle 2.1.

Browser Detection
A site setting enablemobiledetection will be added and set to yes by default.

The following functions would be added to lib/moodlelib.php –

is_mobile_browser() –  detects whether a mobile browser is being used using a regular expression defined by detectmobilebrowser.com (see.PHP download).  Returns true or false.  If enablemobiledetection is set to no then will return false.

For more granular detection of browser operating systems and browsers, it is intended that the existing check_browser_operating_system and check_browser_version functions should be used and extended if required.


Mobile Theme
Administrators will be able to specify a theme to use for mobile devices through an additional ‘Use for mobile browsers’ button on the ‘theme selector’.

theme/index.php will be amended to display an additional form for selection of a mobile theme and accept an additional choosemobile parameter for theme configuration.  The box will be greyed out if the theme does not have the new parameter mobileoptimised set to true.

In lib/pagelib.php, resolve_theme()  will be amended under the site case to check if a browser is mobile, whether mobiledisabletheme (see below) exists and is true/false and whether a mobile theme is set.


Switching Themes
Mobile themes should provide the user with the ability to switch from the mobile theme to the ‘modern browser’ theme.  This selection should persist for either the duration of the session or permanently according to the user’s selection, made via two links in the page footer.  All ‘modern browser’ themes should, if is_mobile_browser() returns true, show a link to switch back to the mobile view.  Template designers can specify where these links should appear.

An additional public function will be added to the core_render class in lib\outputrenderers.php, theme_switch_links().  Calling this will add the two switch links to a mobile theme or the single link to a ‘modern browser’ theme.  An additional protected variable will be added to the class, switchlinkdisplayed, that will be false by default.  Calling the function will cause it to be set to true.

standard_html_footer() will be amended to add a call to theme_switch_links() if switchlinkdisplayed is not set to true.

A new folder mobile folder will be created at the root.  This will contain a single file, switch.php.  According to the switch link selected, this will either set a session variable mobiledisabletheme to true, set a user preference mobileblocktheme to true or set both of these to false.  The user will be redirected to the screen on which the link was selected.

Average of ratings:Useful (4)
In reply to Anthony Forth

Re: Proposal for Supporting Mobile Themes and Browser Detection

by Mauno Korpelainen -

Excellent proposal!

Switcher itself is not a major problem -  I have tested the same code from detectmobilebrowser.com with theme layout files - and if mobile devices get also different default css without holy grail layout from base theme (different mobile base theme?) most activities can be used with mobile devices.

In reply to Anthony Forth

Re: Proposal for Supporting Mobile Themes and Browser Detection

by Mauno Korpelainen -

To this middle part (Mobile Theme):

For a start mobile base theme should eliminate floats and frames, columns (one column with the content first is the best option), scripted effects (menus, docks, popups etc), nested tables and layout tables (most of tables have already gone in moodle 2.0 ). Mobile base theme css should set proper widths and heights for small-screen elements, reduce margins, paddings and borders ( to 0), switch to ems or percentages rather than pixels, switch to smaller font sizes for headings and paragraph text and so on.

With current moodle 2 css most of these things can be done with overriding theme css of base theme but ideally mobiles should not need most of base theme css at all smile

In reply to Mauno Korpelainen

Re: Proposal for Supporting Mobile Themes and Browser Detection

by Lei Zhang -

For the css part, it should load 'A' separate style sheet (assuming only need ONE for mobile) instead of all the standard moodle css (base, canvas...) once the brower detection found it's a mobile device. This will hopefully reduced the page loading time and bandwidth for users, considering a lot of places still charging ridiculous amount of fees for mobile internet, e.g. Zimbabwe, Nepal, Bhutan, New Zealand!!....sad

In reply to Lei Zhang

Re: Proposal for Supporting Mobile Themes and Browser Detection

by Anthony Forth -

That does seem like a good idea.  I had considered it, but not for that reason.  I'll amend the spec once there's been a bit more time for comments.

In reply to Anthony Forth

Re: Proposal for Supporting Mobile Themes and Browser Detection

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

These proposals seem like really good simple ideas to me, so I hope other people like them.

(Of course, as a colleague of Anthony's I am probably biased.)

In reply to Anthony Forth

Re: Proposal for Supporting Mobile Themes and Browser Detection

by Julian Ridden -

Sounds great. A huge +1 from me. I have another idea to add to the mix. Once we have browser detection could we enable/diable certain filters based on this.

Specifically what I have in mind is that once we know they are mobile based I would disable the multimedia filters as these probably wont operate, and I would also like to add a new one that replaces a .flv file with a .mp4 extension tat would auto link to to the mp4 file if they are on a mobile device. (this would require however that both an mp4 and flv variant of the files were uploaded beforehand however).

Thoughts? Or am I just dreaming?

Julian

In reply to Julian Ridden

Re: Proposal for Supporting Mobile Themes and Browser Detection

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I think the requirement you have identified is a good one (different multimedia handling on different devices) but I am not sure about your proposed solution.

Your suggesting is:

A. A general mechanism for varying which filters run depending on target device.

and alternative is.

B. Specifically change the multimedia filter, so that it becomes aware of different devices, and does appropriate things with the different media types.

I am not sure which of those is better. My feeling is that B. might be simpler, at least in the short term.

In reply to Tim Hunt

Re: Proposal for Supporting Mobile Themes and Browser Detection

by Edward Beckmann -

Hi All

I agree with Tim, in that its a nice idea and very use-focused. One thought is that if you detect the browser then apply its own CSS, you could hide different classes depending on the CSS. As a norm, you would have each resource uploaded with both PC and mobile versions if they were required. The key is that when you upload an mp4 the code calls it 'class="mp4", and so on for other types. So in a desktop-focused CSS you have .mp4 {display:none} but .flv {your chosen styles} and vice-versa for the mobile CSS.

Does that make sense to anyone or am I off in the wrong direction?

Cheers

Ed

In reply to Anthony Forth

Re: Proposal for Supporting Mobile Themes and Browser Detection

by Roger Emery -

Hello,

This is an excellent proposal. I have been looking at mobile apps recently (for Mahara) and as pretty and functional as they can be, they create a never ending update and support cycle for many mobile platforms.
A small screen browser css theme is much easier to control, update, and customise centrally - there is only one to fix.

One thing not mentioned are the 'mid-sized' screen devices such as iPad, Galaxy Tab and so on running 5-10 inch screens. Some could support a full theme and others may better run a mobile theme.
Would there be place for a locally defined (in 'local' directory) config file so new broswer versions/device types/functionality could be added as they are released in various local markets under different branding/versions? Admins would then be able to easily set or override the defaults as required.

 

 

 

In reply to Anthony Forth

Re: Proposal for Supporting Mobile Themes and Browser Detection

by Anthony Forth -

Following community feedback, our proposal has broadened.  Here's  v2 -

Moodle Device Detection Specification

Introduction
This document proposes some additions to Moodle 2.1 to enable detection of different types of device so that additional or alternative functionality can be provided.  This would, for example, allow blocks, modules, etc to take advantage of mobile functionality (cameras, geo-location, etc); make customisations for tablets or to develop modules or blocks that are only for use for particular types.

It also specifies a means for different themes to be used for different types.  This provides an alternative to using @media rules within a theme with the associated issues this may bring for users with larger displays (loss of features or unfamiliar layout if resizing a browser window).

Browser Detection
A site setting enabledevicedetection will be added and set to yes by default.

The following functions would be added to lib/moodlelib.php –

get_device_type() –  uses  regular expressions to detect whether a device is mobile, legacy, tablet or default.  If enabledevicedetection is set to no then will return default.  Further, users can use a new administration setting to add additional name/regular expression pair (if the regular expression is found then the function will return the name).  User defined expressions will have precedence, allowing the four basic types to be overridden.

For more granular detection of browser operating systems and browsers, it is intended that the existing check_browser_operating_system and check_browser_version functions should be used and extended if required.

Theme Selection
The theme selector user interface for sites, courses and users will be changed so that, if enabledevicedetection is set to yes, it will be device type led.

The first screen will show a list of device types, including user specified types, with a thumbnail of the currently selected theme and a ‘return to default site settings’ button if changes have been made.  Users will then be able to select a device and see, by default, a list of supporting themes (the user will also be able to opt to see a list of all themes, whether they provide support or not).  The current theme will appear at the top of the list followed by a list of themes that can be chosen with thumbnails and a select button.

If enabledevicedetection is set to ‘no’ then a default device type is always assumed, so in accessing the theme selector the user will be taken directly to the selector for default devices.

Moodle Themes will have an additional optional setting supporteddevicetypes that will include a comma delimited list of supported types.  If a theme does not have this, it will be assumed to support the default type only (remembering that this is only indicative as administrators can ultimately use any theme for any device type).

Storing Theme Settings
The theme fields of the site, course and user globals will include a comma delimited list of device categories and themes intersected by an ‘:’ (e.g. mobile:standardtheme).  If these are empty, default themes will be used.

Switching Themes
Themes being used for particular device types will provide the user with the ability to switch from the theme for their type of device to the default type theme.  This selection should persist for either the duration of the session or permanently according to the user’s selection, made via two links in the page footer.  This will be stored in a user or session variable in comma delimited form according to the current context (site, course, user, etc) and device e.g. $USER->switchtheme = ‘site:mobile:standardtheme, course:tablet:anothertheme’.

A new file, switch.php, will be added to the theme folder.  According to the switch link selected, this will either set the switchtheme field of the session or user variable (and save the user setting).  The user will be redirected to the screen on which the link was selected.

Themes being used for particular device types will show a link to switch back to the default theme.  When a switch from the device type theme is undertaken, an additional variable, originatingtheme, will be added to the $THEME global.  If this variable exists, the theme in current use should show a link back to the standard theme for the device in use.

An additional public function will be added to the core_render class in   lib\outputrenderers.php, theme_switch_links().  Calling this will add the two switch links to a mobile theme or the single link to a ‘modern browser’ theme if the aforementioned conditions are met.

Template designers can specify where these links should appear.   An additional protected variable will be added to the class, switchlinkdisplayed, that will be false by default.  Calling the theme_switch_links() will cause it to be set to true.  standard_html_footer() will be amended to add a call to theme_switch_links() if switchlinkdisplayed is not set to true.

Resolving Themes
In lib/pagelib.php, resolve_theme() will be amended to check the value returned by get_device_type() and compare it to the relevant theme field to find the correct theme to use.  Any switchtheme settings in the session or user globals will have precedence, then theme field settings.  The existing theme order (course, category, session, user, site) will continue to be respected.

If no theme can be found, then the default Moodle theme will be used.

Existing legacy browser support code will be removed.

Upgrade from Moodle 2.0
An upgrade script will be written to maintain pre-existing theme settings. A modern theme will become a default type theme in Moodle 2.1 and a legacy theme will be associated with the new legacy type.

In reply to Anthony Forth

Re: Proposal for Supporting Mobile Themes and Browser Detection

by sam marshall -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

I already privately (...and somewhat late) gave a few comments on this which I don't think Anthony made changes for - not sure if that is intentional or he accidentally posted an older version here. Anyhow I can add my comments here too, but will wait until after the weekend to see what's going on.

In reply to sam marshall

Re: Proposal for Supporting Mobile Themes and Browser Detection

by Petr Skoda -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
I like this proposal a lot more and I am looking forward to yours comments. Thanks for the work, I think this could help many developers when creating new highly customised user interfaces.

Petr
In reply to Petr Skoda

Re: Proposal for Supporting Mobile Themes and Browser Detection

by sam marshall -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

It turns out Anthony did take some of my comments into account, whereas others I had misunderstood the spec. Here are my revised comments smile

1. I thought this system should be always on, i.e. no need for (yet) another  site option as I couldn't see why you would want to turn it off, given that even with it turned on, the default behaviour is basically unchanged I think...

2. I suggested not including tablet as a predefined device type - but Anthony thinks this will be wanted in lots of places and thinks he will probably be able to find a similar regular expression for it. (So with that in mind, I guess I agree with him.)

3. In the user interface for selecting themes for a course or user (or category etc), I think there should be a really big button at the top of the first page 'Use default' or whatever. So that it's easy to go back to the default without having to manually select whatever theme that is. It's better if people select default rather than selecting the site theme manually, otherwise they end up with a different setting if site theme ever changes.

4.  Re where settings are stored when the user clicks the 'switch to normal view' link, I didn't understand the spec - Anthony explained to me that this is stored either in session (presumably $SESSION) or, for the permanent option, in a user preference. The user preference stores your preferred option per device type, so that if you use multiple different tablets for example, it will remember that you've chosen that on a tablet, you always want to see the normal desktop view (say). It actually kind of says this up above but I misread it.

That's it I think.

--sam

In reply to sam marshall

Re: Proposal for Supporting Mobile Themes and Browser Detection

by Anthony Forth -

With regard to point 3, yes, agreed.

With regard to point 1, I have included this because there *might* be people out there who don't want to support mobile.  However, I don't feel passionate about this smile

When I get back from my Xmas holidays I'll get on with the code.

In reply to Anthony Forth

Re: Proposal for Supporting Mobile Themes and Browser Detection

by Nick Thompson -

Here is a document describing our approach to Mobile strategy here at UCLA: http://m.ucla.edu/doc/

Additionally, regarding the detection of mobile devices, we've written a layer on top of WURFL, though you can use WURFL libraries without modifying them.  This page describes a few of the function calls we make to determine what the type of device is: http://m.ucla.edu/doc/index.php?p=js/util

In reply to Anthony Forth

Re: Proposal for Supporting Mobile Themes and Browser Detection

by Anthony Forth -

Attached is the version of the spec I will be working from.  Only very minor changes from the above.

In reply to Anthony Forth

Re: Proposal for Supporting Mobile Themes and Browser Detection

by Anthony Forth -

Post the change to how pulls are handled, I've added the details for the repos for this to...

http://tracker.moodle.org/browse/MDL-25394

I've set it to peer review as this seemed to be the only option, not 100% certain about the workflow for pull requests.

 

In reply to Anthony Forth

Re: Proposal for Supporting Mobile Themes and Browser Detection

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Well hope you have better luck than me, as I'm still waiting (2 weeks down the line) for Peer review on a theme for Moodle 2.1

LOL

Mary

In reply to Anthony Forth

Re: Proposal for Supporting Mobile Themes and Browser Detection

by Anthony Forth -

I've finished the code for this.  It's now available for review at https://github.com/anthonyforth/moodle/compare/master...WIP-25394

The Moodle bug for this (http://tracker.moodle.org/browse/MDL-25394?focusedCommentId=103657#comment-103657) has also been updated.

In reply to Anthony Forth

Re: Proposal for Supporting Mobile Themes and Browser Detection

by Anthony Forth -

I've some more updates based on various comments received.

One question - it creates two new admin settings for enabling device detection and adding regexes to use to identify device types.  I put these on the 'advanced features' screen but people don't seem to like thissad.

Any thoughts on a better place for them?

In reply to Anthony Forth

Re: Proposal for Supporting Mobile Themes and Browser Detection

by Danny Wahl -

I would suggest:

Site Admin->Themes->Theme Settings (append)

Site Admin->Themes->Mobile Settings (new)

Site Admin->Development->Experimental->Experimental Settings (append)

In reply to Danny Wahl

Re: Proposal for Supporting Mobile Themes and Browser Detection

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I think Site Admin->Themes->Theme Settings is the place to put this.

In reply to Tim Hunt

Re: Proposal for Supporting Mobile Themes and Browser Detection

by Anthony Forth -

Themes->Theme Settings it is.

In reply to Anthony Forth

Re: Proposal for Supporting Mobile Themes and Browser Detection

by Adam Sanders -

I work for my university (Idaho State) supporting faculty and staff in the use of moodle. A large portion of the calls we recieve are related to, and rectified, but directing the professor or student to use Firefox to access moodle.

With the browser detection would it be possible to add a function that recognized the browser accessing moodle (IE, FF, Chrome, ect) and sent a popup to the user if they werent using firefox? This would solve a lot of problems (at least on our IT end) before they ever started.

In reply to Adam Sanders

Re: Proposal for Supporting Mobile Themes and Browser Detection

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

This would be easy to do in the header of your theme.