Hi,
Thanks for this awesome plugin, Peter. And thanks for your incredible support in this forum.
I’ve looked into this and here’s what’s up. One can detect a mobile device via PHP or JS. PHP would be used to generate some JS or CSS code which would actually show the menu button and hide some DOM elements. PHP browser detection is based on a user-agent, which isn’t very good, as there are user-agents added like literally every day and for new devices. So, scratch PHP.
That leaves us with JS. Parsing the user-agent as we said is a bad idea. The 2nd idea is to use Modernizr and it’s touch check. If a browser has touch capabilities, Modernizr adds a “touch” class to the <body> tag and the JS statement if(Modernizr.touch) is true.
Using this, we can find the jQuery document ready function call. For this plugin, it would be after:
$RMjQuery(document).ready(function(){
And put the following code after it:
if (Modernizr.touch) {
$RMjQuery('#click-menu').css('display', 'block');
$RMjQuery('FROM_WP_SETTINGS_CSS_ELEMENTS_TO_BE_HIDDEN').css('display', 'none');
$RMjQuery('#responsive-menu .responsive-menu li li li li .appendLink, #responsive-menu .responsive-menu li li li li li').css('display', 'none');
}
What we did here, is the following: checked, if the browser has touch capabilities, if so: shown the thee lines menu button, hid the CSS elements that were set in the WP plugin settings (this needs to be changed to a PHP variable of course), set the CSS rules that were originally set in the Responsive Menu plugin (not sure what they do, but doesn’t matter).
The only drawback is that Modernizr.touch checks if the browser has touch capabilities, not if the device itself has touch capabilities and has touch enabled. Some desktop browsers will return true for this even though the device they’re installed on doesn’t actually have touch capabilities. As far as I’ve read, this doesn’t happen very often though, so for my case it’s better than nothing.
I’m not sure if it’s a good idea to implement it, maybe as an option, but whatever – here it is.
Hope it helps someone.
Edit: Note that the display:none attributes are not marked as !important. They seem to work without it though. For some cases they might not work and here’s the solution: http://stackoverflow.com/questions/2655925/how-to-apply-important-using-css