Skip to content

Commit

Permalink
Add some more mobile detection (and for dev)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Wilcox committed Jul 13, 2012
1 parent f72fbed commit 0d60aaa
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions has.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ define([
var el = document.createElement('bv');
var vid = d.createElement('video');
var test_style = el.style;
var ua = navigator.userAgent;
var winSize = function(){
var element = (d.compatMode == 'BackCompat') ? d.body : d.documentElement;
return { w: element.clientWidth, h: element.clientHeight};
}

var cap = function(word){
return word.charAt(0).toUpperCase() + word.substr(1);
}
Expand Down Expand Up @@ -80,6 +86,27 @@ define([
return !!vid.canPlayType;
});

has.add('mobile', function(){
// Checking ua string for iPhone - this way, testing can be done
// on desktop Safari with dev mode UA set
if(/iPhone/.test(ua)) return true;
// checking touch + window size to determine if mobile
// 600 width is rather arbitrary
return has('touch') && winSize().w < 600;
});

has.add('fake-mobile', function(){
// Testing if we are in fake iPhone mode with desktop Safari and
// dev mode UA set
return has('iphone') && !(has('touch') && winSize().w < 600);
});

has.add('tablet', function(){
// checking touch + window size to determine if tablet
// 600 width is rather arbitrary
return has('touch') && winSize().w > 600;
});

return has;

});

0 comments on commit 0d60aaa

Please sign in to comment.