Skip to content

Commit cd07689

Browse files
committed
Merge pull request #1 from angular-adaptive/canary
v0.1.0
2 parents 6a217d9 + ad9313d commit cd07689

10 files changed

Lines changed: 246 additions & 2 deletions

File tree

.bowerrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"directory": "components"
3+
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/components/
2+
node_modules/
3+
*.log

.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: node_js
2+
node_js:
3+
- "0.8"
4+
5+
before_install:
6+
- export DISPLAY=:99.0
7+
- sh -e /etc/init.d/xvfb start
8+
- npm install -g bower grunt-cli
9+
- npm install
10+
- bower install
11+
12+
script: "grunt"

Gruntfile.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module.exports = function (grunt) {
2+
grunt.loadNpmTasks('grunt-karma');
3+
grunt.loadNpmTasks('grunt-contrib-jshint');
4+
5+
// Default task.
6+
grunt.registerTask('default', ['karma', 'jshint']);
7+
8+
var karmaConfig = function(configFile, customOptions) {
9+
var options = { configFile: configFile, keepalive: true };
10+
var travisOptions = process.env.TRAVIS && { browsers: ['Firefox'], reporters: 'dots' };
11+
return grunt.util._.extend(options, customOptions, travisOptions);
12+
};
13+
14+
// Project configuration.
15+
grunt.initConfig({
16+
karma: {
17+
unit: {
18+
options: karmaConfig('test/test.conf.js')
19+
}
20+
},
21+
jshint:{
22+
files:['src/**/*.js', 'test/**/*.js'],
23+
options: {
24+
curly:true,
25+
eqeqeq:true,
26+
immed:true,
27+
latedef:true,
28+
newcap:true,
29+
noarg:true,
30+
sub:true,
31+
boss:true,
32+
eqnull:true,
33+
devel:true,
34+
globals:{}
35+
}
36+
}
37+
});
38+
}

README.md

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,69 @@
1-
adaptive-detection
2-
==================
1+
# adaptive-detection v0.1.0 [![Build Status](https://travis-ci.org/angular-adaptive/adaptive-detection.png?branch=master)](https://travis-ci.org/angular-adaptive/adaptive-detection)
2+
3+
This module allows you to detect iOS and Android devices using user agent string
4+
5+
# Requirements
6+
7+
- AngularJS v 1.0+
8+
9+
# Usage
10+
11+
We use [bower](http://twitter.github.com/bower/) for dependency management. Add
12+
13+
dependencies: {
14+
"angular-adaptive-detection": "latest"
15+
}
16+
17+
To your `bower.json` file. Then run
18+
19+
bower install
20+
21+
This will copy the angular-isbn files into your `bower_components` folder, along with its dependencies. Load the script files in your application:
22+
23+
<script type="text/javascript" src="components/angular/angular.js"></script>
24+
<script type="text/javascript" src="components/angular-adaptive/adaptive-detection/src/adaptive-detection.js"></script>
25+
26+
Add the **adaptive.detection** module as a dependency to your application module:
27+
28+
var myAppModule = angular.module('MyApp', ['adaptive.detection']);
29+
30+
and include $detection provider as a dependency to your controller:
31+
32+
angular.module('MyApp').controller('MainCtrl', function ['$scope', '$detection', ($scope, $detection) {
33+
34+
}]);
35+
36+
### Configuration
37+
38+
You can configure provider to a custom User Agent string in app configuration.
39+
40+
$detection.setUserAgent('angular browser');
41+
42+
### Public methods
43+
44+
You can detect Android and iOS devices using:
45+
46+
$detection.isAndroid();
47+
$detection.isiOS();
48+
49+
50+
# Contributing
51+
52+
Contributions are welcome. Please make a pull request against canary branch and do not bump versions. Also include tests.
53+
54+
# Testing
55+
56+
We use karma and jshint to ensure the quality of the code. The easiest way to run these checks is to use grunt:
57+
58+
npm install -g grunt-cli
59+
npm install
60+
bower install
61+
grunt
62+
63+
The karma task will try to open Chrome as a browser in which to run the tests. Make sure this is available or change the configuration in `test/test.config.js`
64+
65+
# License
66+
67+
The MIT License
68+
69+
Copyright (c) 2013 Jan Antala, https://github.com/janantala

bower.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "angular-adaptive-detection",
3+
"version": "0.1.0",
4+
"description": "This module allows you to detect device.",
5+
"author": "https://github.com/angular-adaptive/adaptive-detection/graphs/contributors",
6+
"license": "MIT",
7+
"homepage": "http://angular-adaptive.github.io",
8+
"main": "./src/adaptive-detection.js",
9+
"ignore": [
10+
"**/.*",
11+
"node_modules",
12+
"components",
13+
"test*",
14+
"demo*",
15+
"Gruntfile.js",
16+
"package.json"
17+
],
18+
"dependencies": {
19+
"angular": "~1.x"
20+
},
21+
"devDependencies": {
22+
"angular-mocks": "~1.x"
23+
}
24+
}

package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "angular-adaptive-detection",
3+
"version": "0.1.0",
4+
"description": "This module allows you to detect device.",
5+
"author": "https://github.com/angular-adaptive/adaptive-detection/graphs/contributors",
6+
"license": "MIT",
7+
"homepage": "http://angular-adaptive.github.io",
8+
"main": "./src/adaptive-detection.js",
9+
"dependencies": {},
10+
"devDependencies": {
11+
"grunt": "~0.4.1",
12+
"grunt-karma": "*",
13+
"grunt-contrib-jshint": "~0.2.0"
14+
},
15+
"scripts": {},
16+
"repository": {
17+
"type": "git",
18+
"url": "git://github.com/angular-adaptive/adaptive-detection.git"
19+
}
20+
}

src/adaptive-detection.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* angular-adaptive-detection v0.1.0
3+
* The MIT License
4+
* Copyright (c) 2013 Jan Antala
5+
*/
6+
7+
(function () {
8+
9+
var adaptive = angular.module('adaptive.detection', []);
10+
11+
adaptive.provider('$detection', [function() {
12+
13+
this.userAgent = navigator.userAgent;
14+
15+
this.setUserAgent = function(userAgent) {
16+
this.userAgent = userAgent;
17+
};
18+
19+
this.$get = function() {
20+
var userAgent = this.userAgent;
21+
22+
return {
23+
getUserAgent: function(){
24+
return userAgent;
25+
},
26+
isiOS: function(){
27+
return (/(iPad|iPhone|iPod)/gi).test(userAgent);
28+
},
29+
isAndroid: function(){
30+
return (/(Android)/gi).test(userAgent);
31+
}
32+
};
33+
};
34+
35+
}]);
36+
37+
})();

test/test.conf.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = function(config) {
2+
config.set({
3+
basePath: '..',
4+
files: [
5+
'components/angular/angular.js',
6+
'components/angular-mocks/angular-mocks.js',
7+
'src/adaptive-detection.js',
8+
'test/*.spec.js'
9+
],
10+
frameworks: ['jasmine'],
11+
singleRun: true,
12+
browsers: [ 'Chrome' ]
13+
});
14+
};

test/unit.spec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
describe('adaptive.detection', function(){
3+
4+
var detection;
5+
6+
beforeEach(module('adaptive.detection', function($detectionProvider) {
7+
detection = $detectionProvider;
8+
}));
9+
10+
it('should allow to set custom userAgent', inject(function() {
11+
detection.setUserAgent('angular');
12+
expect(detection.userAgent).toEqual('angular');
13+
expect(detection.$get().getUserAgent()).toEqual('angular');
14+
}));
15+
16+
it('should detect iOS', inject(function() {
17+
detection.setUserAgent('iPhone');
18+
expect(detection.$get().isiOS()).toEqual(true);
19+
}));
20+
21+
it('should detect Android', inject(function() {
22+
detection.setUserAgent('Android');
23+
expect(detection.$get().isAndroid()).toEqual(true);
24+
}));
25+
26+
});

0 commit comments

Comments
 (0)