mirror of https://github.com/BTCPrivate/copay.git
add isMobile service and tests
This commit is contained in:
parent
78493f9d91
commit
0347cb5bda
|
@ -2,7 +2,7 @@
|
||||||
var bitcore = require('bitcore');
|
var bitcore = require('bitcore');
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('SendController',
|
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.title = 'Send';
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
var satToUnit = 1 / config.unitToSatoshi;
|
var satToUnit = 1 / config.unitToSatoshi;
|
||||||
|
@ -23,29 +23,6 @@ angular.module('copayApp.controllers').controller('SendController',
|
||||||
return flag;
|
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
|
// Detect protocol
|
||||||
$scope.isHttp = ($window.location.protocol.indexOf('http') === 0);
|
$scope.isHttp = ($window.location.protocol.indexOf('http') === 0);
|
||||||
|
|
||||||
|
|
|
@ -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);
|
|
@ -214,4 +214,18 @@ describe("Unit: Controllers", function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Send Controller', function() {
|
||||||
|
var sendCtrl;
|
||||||
|
beforeEach(inject(function($controller, $rootScope) {
|
||||||
|
scope = $rootScope.$new();
|
||||||
|
sendCtrl = $controller('SendController', {
|
||||||
|
$scope: scope,
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should have a SendController', function() {
|
||||||
|
expect(scope.isMobile).not.to.equal(null);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -108,3 +108,19 @@ describe("Unit: Backup Service", function() {
|
||||||
expectation.once();
|
expectation.once();
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Unit: isMobile Service", function() {
|
||||||
|
beforeEach(angular.mock.module('copayApp.services'));
|
||||||
|
it('should contain a isMobile service', inject(function(isMobile) {
|
||||||
|
expect(isMobile).not.to.equal(null);
|
||||||
|
}));
|
||||||
|
it('should not detect mobile by default', inject(function(isMobile) {
|
||||||
|
isMobile.any().should.equal(false);
|
||||||
|
}));
|
||||||
|
it('should detect mobile if user agent is Android', inject(function(isMobile) {
|
||||||
|
navigator.__defineGetter__('userAgent', function(){
|
||||||
|
return 'Android 2.2.3';
|
||||||
|
});
|
||||||
|
isMobile.any().should.equal(true);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue