Javascript Mobile Utils
App.utils = {
mobile:{
isAndroid: function() {
return navigator.userAgent.match(/Android/i);
},
isBlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
isIos: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
isOpera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
isWindows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
isMobileDevice: function() {
return (this.isAndroid() || this.isBlackBerry() || this.isIos() || this.isOpera() || this.isWindows());
},
isPortrait:function(){
return ($(window).width() < $(window).height());
},
isLandscape:function(){
return ($(window).width() > $(window).height());
},
isSmallScreen:function(){
return ($(window).width() < 768);
},
check:function(){
var $meta = $('meta[name="viewport"]');
var $body = $('body');
var $hiddenMobile = $('.hidden-mobile');
var $visibleMobile = $('.visible-mobile');
$meta.attr('content','initial-scale=1, width=device-width, user-scalable=1');
$body.removeClass('mobile-device');
//$hiddenMobile.show();
//$visibleMobile.hide();
if(this.isSmallScreen()){
$meta.attr('content','initial-scale=1, width=device-width, user-scalable=0');
$body.addClass('mobile-device');
//$hiddenMobile.hide();
//$visibleMobile.show();
}
},
init:function(){
var scope = this;
$(window).on('resize orientationchange', function (e) {
scope.check();
});
// initial call
scope.check();
}
}
};