Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Gwenwyfar on February 11, 2015, 01:57:35 PM

Title: Question about use of $context['browser'] for mobile devices
Post by: Gwenwyfar on February 11, 2015, 01:57:35 PM
I was looking at the array list on $context to find some I needed, and I thought of some uses for some others as well. One of them would be to use the browser related ones ([is_android], [is_iphone]) to remove certain things (specially images) from loading completely on mobile devices instead of just blocking them with css, to eat less of the already poor download speed on them.

But it seems to be very device-specific (and have in mind I know absolutely nothing about what kind of device is what, to me they're all either a phone or a tablet computer), so I wanted to know if there is any combination of them that I can use to target ANY mobile device? Or will just those target most of them already? On any case I will keep the CSS block for those that might not get affected, but it would be useful to know on which ones it works, exactly, or how does it define what is what.

Title: Re: Question about use of $context['browser'] for mobile devices
Post by: Antechinus on February 11, 2015, 04:15:04 PM
Nope. You can write your own array to target any you want to hit, but the default 2.0.x array is very limited. It basically covers iphone and (generic) android and not much else. To cover every mobile device is use anywhere in the world, you'd have to make quite a few additions.

I did write a mod which extended it somewhat, and IIRC there was an even more comprehensive one written by someone else (maybe Emanuele).
Title: Re: Question about use of $context['browser'] for mobile devices
Post by: Gwenwyfar on February 11, 2015, 04:23:52 PM
Didn't know there was a mod for it, I'll give it a try, thanks :)

His mod seems to be for making a separate theme though, I'll see if I can use just the detection from it.
Title: Re: Question about use of $context['browser'] for mobile devices
Post by: Antechinus on February 11, 2015, 04:33:44 PM
It's "his". ;)
Title: Re: Question about use of $context['browser'] for mobile devices
Post by: Gwenwyfar on February 11, 2015, 05:04:27 PM
Oh. That is a woman's name around here, because of the "e" after "l"  :P I'll remember that next time ;)
Title: Re: Question about use of $context['browser'] for mobile devices
Post by: Antechinus on February 11, 2015, 05:13:26 PM
He's Italian. They have funny names.
Title: Re: Question about use of $context['browser'] for mobile devices
Post by: Gwenwyfar on February 11, 2015, 05:43:19 PM
Ahh. His name is pretty common here too, but its "Emanuel" instead :P
Title: Re: Question about use of $context['browser'] for mobile devices
Post by: margarett on February 11, 2015, 07:29:09 PM
Quote from: Fortytwo on February 11, 2015, 04:23:52 PM
His mod seems to be for making a separate theme though, I'll see if I can use just the detection from it.
Nope, I think it is not ;)
http://custom.simplemachines.org/mods/index.php?mod=3349

QuoteOnce instantiated the class is placed in $context['device'], so that other mods and themes can use the it in order to do change their behaviour depending on the device.
This means (to me) that you can not choose any dedicated mobile theme and *still* have $context['device'] show you the proper info ;)
Title: Re: Question about use of $context['browser'] for mobile devices
Post by: Gwenwyfar on February 11, 2015, 07:38:00 PM
Ah, I think I missed that part. Was talking about this one:
QuoteAt the moment in this mod this function is used to allow admins to select a default theme for mobile devices.