Mikko Ohtamaa
2011-10-14 17:33:04 UTC
Hi,
As we don't have any web and mobile hybrids sites currently in the
project pipeline, Web and Mobile development may be bit slow.
However, one of the greatest issue, the device detection has caused
problems for many users. We have internally deployed detectmobile.js
for few sites and this seems to cure the problems.
detectmobile.js uses screen size instead of user agent string to
detect mobile devices.
https://github.com/miohtama/detectmobile.js
For those who want to fix the issues now here are the short
instructions.
detectmobile.js - download and this Javascript as the FIRST Javascript
in portal_javascript on the WEB site.
detectmobile-bootstrap.js - install this Javascript as the SECOND
Javascript in portal_javascript on the WEB site:
try {
// Set up detectmobile.js
detectmobile.redirectCallback = function(mode, url) {
if(mode == "mobile") {
// We could have arrived directly to a news
article
// from a search engine, not the site home
page
// Redirect to a corresponding article mobile
version
// This example has some URL path for the
article
// on both site.com and m.site.com, just
different domain name.
// But you could any kind of URL rewrite
here.
return detectmobile.replaceDomainName(url,
"m", true, true);
}
// Take no action
return url;
}
// Execute mobile redirect
detectmobile.process();
} catch(e) {
// Make sure that in the fault modes
// we do not interrupt execution of other Javascript code
if(console && console.exception) {
console.exception(e);
}
}
Then you need to override the old mobile redirector.
ZCML:
<adapter
for="zope.interface.Interface
zope.publisher.interfaces.browser.IBrowserRequest"
provides="gomobile.mobile.interfaces.IMobileRedirector"
factory=".redirector.Redirector"
/>
redirector.py:
"""
Override gomobile redirector not do to mobile redirects
automatically.
"""
from gomobile.mobile import redirector as base
from gomobile.mobile.interfaces import (
IMobileRequestDiscriminator, MobileRequestType, IUserAgentSniffer,
IMobileSiteLocationManager)
class Redirector(base.Redirector):
"""
"""
def redirect(self, media_type=MobileRequestType.MOBILE):
""" Redirects to the mobile site staying on the page pointed
by the current HTTP request.
Rewrites the current HTTP response.
@param media_type: Target media type. "www" or "mobile"
@return: True if redirect has been made
"""
# Never redirect on the server side,
# because redirects are handled by Javascript
return False
As we don't have any web and mobile hybrids sites currently in the
project pipeline, Web and Mobile development may be bit slow.
However, one of the greatest issue, the device detection has caused
problems for many users. We have internally deployed detectmobile.js
for few sites and this seems to cure the problems.
detectmobile.js uses screen size instead of user agent string to
detect mobile devices.
https://github.com/miohtama/detectmobile.js
For those who want to fix the issues now here are the short
instructions.
detectmobile.js - download and this Javascript as the FIRST Javascript
in portal_javascript on the WEB site.
detectmobile-bootstrap.js - install this Javascript as the SECOND
Javascript in portal_javascript on the WEB site:
try {
// Set up detectmobile.js
detectmobile.redirectCallback = function(mode, url) {
if(mode == "mobile") {
// We could have arrived directly to a news
article
// from a search engine, not the site home
page
// Redirect to a corresponding article mobile
version
// This example has some URL path for the
article
// on both site.com and m.site.com, just
different domain name.
// But you could any kind of URL rewrite
here.
return detectmobile.replaceDomainName(url,
"m", true, true);
}
// Take no action
return url;
}
// Execute mobile redirect
detectmobile.process();
} catch(e) {
// Make sure that in the fault modes
// we do not interrupt execution of other Javascript code
if(console && console.exception) {
console.exception(e);
}
}
Then you need to override the old mobile redirector.
ZCML:
<adapter
for="zope.interface.Interface
zope.publisher.interfaces.browser.IBrowserRequest"
provides="gomobile.mobile.interfaces.IMobileRedirector"
factory=".redirector.Redirector"
/>
redirector.py:
"""
Override gomobile redirector not do to mobile redirects
automatically.
"""
from gomobile.mobile import redirector as base
from gomobile.mobile.interfaces import (
IMobileRequestDiscriminator, MobileRequestType, IUserAgentSniffer,
IMobileSiteLocationManager)
class Redirector(base.Redirector):
"""
"""
def redirect(self, media_type=MobileRequestType.MOBILE):
""" Redirects to the mobile site staying on the page pointed
by the current HTTP request.
Rewrites the current HTTP response.
@param media_type: Target media type. "www" or "mobile"
@return: True if redirect has been made
"""
# Never redirect on the server side,
# because redirects are handled by Javascript
return False