add isMobile service and tests

This commit is contained in:
Manuel Araoz 2014-06-19 15:07:20 -03:00
commit 0347cb5bda
4 changed files with 57 additions and 24 deletions

View file

@ -2,7 +2,7 @@
var bitcore = require('bitcore');
angular.module('copayApp.controllers').controller('SendController',
function($scope, $rootScope, $window, $location, $timeout, $anchorScroll, $modal) {
function($scope, $rootScope, $window, $location, $timeout, $anchorScroll, $modal, isMobile) {
$scope.title = 'Send';
$scope.loading = false;
var satToUnit = 1 / config.unitToSatoshi;
@ -23,29 +23,6 @@ angular.module('copayApp.controllers').controller('SendController',
return flag;
};
// TODO this shouldnt be on a particular controller.
// Detect mobile devices
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
// Detect protocol
$scope.isHttp = ($window.location.protocol.indexOf('http') === 0);

26
js/services/isMobile.js Normal file
View file

@ -0,0 +1,26 @@
'use strict';
// Detect mobile devices
var isMobile = {
Android: function() {
return !! navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return !! navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return !! navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return !! navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return !! navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
angular.module('copayApp.services').value('isMobile', isMobile);