I am currently experiencing some issues with some touch detection in a plugin i am using.
The plugin uses the following code
touch = ("ontouchstart" in window) || window.DocumentTouch && document instanceof DocumentTouch;
eventType = (touch) ? "touchend" : "click";
To determine if it should use touchend or click event on some gallery navigation.
However unfortunately when accessing the page using a Blackberry 9300 running os 6.0 its falsely reported as being a touch enabled device and event doesn't fire.
I've checked the detection method used and its the same as the one in Modernizr.
Does anyone have a solution to this issue?
According to Paul Irish, RIM said this about the issue:
Unfortunately, we had a build system issue during BlackBerry 6.0 that caused builds to have WebKit touch support enabled, even for non-touch devices. It's long been fixed, but some public builds do have this issue.
See these (currently open) tickets at github/Modernizr for possible work-arounds and the lastest detection code and then try to alter your plugin as needed. You might need to specifically detect blackberry if the latest detection code below doesn't work.
Also check this touch test out, the browserscope tab indicates blackberry 9000 has been detected as false, so worth a shot to test it in your device too. http://modernizr.github.com/Modernizr/touch.html
The latest modernizr source for the touch detect appears to have an addition of an @media detection in addition to your code you posted.
/*
* The Modernizr.touch test only indicates if the browser supports
* touch events, which does not necessarily reflect a touchscreen
* device, as evidenced by tablets running Windows 7 or, alas,
* the Palm Pre / WebOS (touch) phones.
*
* Additionally, Chrome (desktop) used to lie about its support on this,
* but that has since been rectified: crbug.com/36415
*
* We also test for Firefox 4 Multitouch Support.
*
* For more info, see: modernizr.github.com/Modernizr/touch.html
*/
tests['touch'] = function() {
var bool;
if(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {
bool = true;
} else {
injectElementWithStyles(['@media (',prefixes.join('touch-enabled),('),mod,')','{#modernizr{top:9px;position:absolute}}'].join(''), function( node ) {
bool = node.offsetTop === 9;
});
}
return bool;
};
To specifically detect a BlackBerry devices using the user agent string and borrowing from solutions given from here and here I whipped up this little function which you can test and see working on jsbin at http://jsbin.com/aliwur/1/edit#javascript,live and it should parse out Blackberry 5.0/4.0/6.0 and Playbook from the user agent strings:
function rim_useragent_parser(ua) {
var info = false,
model = null,
model_number = null,
os_version = null;
if (ua.indexOf("BlackBerry") >= 0) {
if (ua.indexOf("Version/") >= 0) {
// BlackBerry 6 and 7
model = ua.match(/BlackBerry\s[0-9]*/);
if (model) {
model_number = model[0].match(/[0-9]+/);
pos = ua.indexOf("Version/") + 8;
os_version = ua.substring(pos, pos + 3);
info = {
'model' : model[0],
'model_number' : model_number[0],
'os_version' : os_version
};
}
}
else {
// BlackBerry Device Software 4.2 to 5.0
model = ua.match(/^BlackBerry[0-9]*/);
if (model) {
model_number = model[0].match(/[0-9]+/);
var SplitUA = ua.split("/");
os_version = SplitUA[1].substring(0, 3);
info = {
'model' : model[0],
'model_number' : model_number[0],
'os_version' : os_version
};
}
}
}
else if (ua.indexOf("PlayBook") >= 0) {
// PlayBook
model = ua.match(/RIM Tablet OS\s[0-9].[0-9].[0-9]/);
if (model) {
model_number = model[0].match(/[0-9].[0-9].[0-9]/);
pos = ua.indexOf("Version/") + 8;
os_version = ua.substring(pos, pos + 5);
info = {
'model' : model[0],
'model_number' : model_number[0],
'os_version' : os_version
};
}
}
return info;
}
Of course that might be more then you need so to simplify it to only "Blackberry 9300 6.0" I guess you could also just do this:
var ua = navigator.userAgent;
if (ua.indexOf("BlackBerry") >= 0) {
if (ua.indexOf("Version/") >= 0) {
// BlackBerry 6 and 7
var model = ua.match(/BlackBerry\s[0-9]*/);
if (model) {
var model_number = model[0].match(/[0-9]+/);
if (model_number) model_number = model_number[0];
pos = ua.indexOf("Version/") + 8;
os_version = ua.substring(pos, pos + 3);
if (os_version === '6.0' && model_number === '9300') {
// do what you need specifically for this
}
}
}
}
https://github.com/tobie/ua-parser/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With