Skip to content

Commit

Permalink
v1.3.0
Browse files Browse the repository at this point in the history
    - use Mobile-Detect@2.8.17
    - add method 'userAgents()' to handle cases where more than one browser matches
    - change method 'is()' to reflect that more than one match is possible for patterns
    - fix #34 is('MobileBot') not working
    - mitigate #36 ucbrowser detect as safari on android os
    - disable failing unit-tests (testing particular device matches)
  • Loading branch information
hgoebl committed Sep 18, 2015
1 parent 1a3e09a commit c2949fd
Show file tree
Hide file tree
Showing 9 changed files with 1,485 additions and 1,230 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
v1.3.0:
date: 2015-09-17
changes:
- use Mobile-Detect@2.8.17
- add method 'userAgents()' to handle cases where more than one browser matches
- change method 'is()' to reflect that more than one match is possible for patterns
- fix #34 is('MobileBot') not working
- mitigate #36 ucbrowser detect as safari on android os
- disable failing unit-tests (testing particular device matches)

v1.2.1:
date: 2015-07-19
changes:
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ You can easily extend it, e.g. `android`, `iphone`, etc.

## Size (bytes)

* development: 62986
* minified: 35717
* minified + gzipped: 14924 (`cat mobile-detect.min.js | gzip -9f | wc -c`)
* development: 66076
* minified: 36464
* minified + gzipped: 15204 (`cat mobile-detect.min.js | gzip -9f | wc -c`)

# Installation

Expand All @@ -120,11 +120,11 @@ You can easily extend it, e.g. `android`, `iphone`, etc.

## CDN - [jsDelivr](http://www.jsdelivr.com/#!mobile-detect.js)

<script src="//cdn.jsdelivr.net/mobile-detect.js/1.2.1/mobile-detect.min.js"></script>
<script src="//cdn.jsdelivr.net/mobile-detect.js/1.3.0/mobile-detect.min.js"></script>

## cdnjs - [cdnjs.com](https://cdnjs.com/libraries/mobile-detect)

<script src="//cdnjs.cloudflare.com/ajax/libs/mobile-detect/1.2.1/mobile-detect.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/mobile-detect/1.3.0/mobile-detect.min.js"></script>

# Extending/Modifying Behaviour

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mobile-detect",
"version": "1.2.1",
"version": "1.3.0",
"description": "Device detection (phone, tablet, desktop, mobile grade, os, versions)",
"homepage": "http://hgoebl.github.io/mobile-detect.js/",
"keywords": [
Expand Down
69 changes: 64 additions & 5 deletions generate/mobile-detect.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ define(function () {
return a != null && b != null && a.toLowerCase() === b.toLowerCase();
}

function containsIC(array, value) {
var valueLC, i, len = array.length;
if (!len || !value) {
return false;
}
valueLC = value.toLowerCase();
for (i = 0; i < len; ++i) {
if (valueLC === array[i].toLowerCase()) {
return true;
}
}
return false;
}

function convertPropsToRegExp(object) {
for (var key in object) {
if (hasOwnProp.call(object, key)) {
Expand Down Expand Up @@ -71,7 +85,7 @@ define(function () {
}());

/**
* Test userAgent string against a set of rules and find the matched key.
* Test userAgent string against a set of rules and find the first matched key.
* @param {Object} rules (key is String, value is RegExp)
* @param {String} userAgent the navigator.userAgent (or HTTP-Header 'User-Agent').
* @returns {String|null} the matched key if found, otherwise <tt>null</tt>
Expand All @@ -88,6 +102,25 @@ define(function () {
return null;
};

/**
* Test userAgent string against a set of rules and return an array of matched keys.
* @param {Object} rules (key is String, value is RegExp)
* @param {String} userAgent the navigator.userAgent (or HTTP-Header 'User-Agent').
* @returns {Array} an array of matched keys, may be empty when there is no match, but not <tt>null</tt>
* @private
*/
impl.findMatches = function(rules, userAgent) {
var result = [];
for (var key in rules) {
if (hasOwnProp.call(rules, key)) {
if (rules[key].test(userAgent)) {
result.push(key);
}
}
}
return result;
};

/**
* Check the version of the given property in the User-Agent.
*
Expand Down Expand Up @@ -457,10 +490,15 @@ define(function () {
},

/**
* Returns the detected user-agent string or <tt>null</tt>.
* Returns the (first) detected user-agent string or <tt>null</tt>.
* <br>
* The returned user-agent is one of following keys:<br>
* <br><tt>{{{keys.uas}}}</tt><br>
* <br>
* In most cases calling {@link MobileDetect#userAgent} will be sufficient. But there are rare
* cases where a mobile device pretends to be more than one particular browser. You can get the
* list of all matches with {@link MobileDetect#userAgents} or check for a particular value by
* providing one of the defined keys as first argument to {@link MobileDetect#is}.
*
* @returns {String} the key for the detected user-agent or <tt>null</tt>
* @function MobileDetect#userAgent
Expand All @@ -472,6 +510,27 @@ define(function () {
return this._cache.userAgent;
},

/**
* Returns all detected user-agent strings.
* <br>
* The array is empty or contains one or more of following keys:<br>
* <br><tt>{{{keys.uas}}}</tt><br>
* <br>
* In most cases calling {@link MobileDetect#userAgent} will be sufficient. But there are rare
* cases where a mobile device pretends to be more than one particular browser. You can get the
* list of all matches with {@link MobileDetect#userAgents} or check for a particular value by
* providing one of the defined keys as first argument to {@link MobileDetect#is}.
*
* @returns {Array} the array of detected user-agent keys or <tt>[]</tt>
* @function MobileDetect#userAgents
*/
userAgents: function () {
if (this._cache.userAgents === undefined) {
this._cache.userAgents = impl.findMatches(impl.mobileDetectRules.uas, this.ua);
}
return this._cache.userAgents;
},

/**
* Returns the detected operating system string or <tt>null</tt>.
* <br>
Expand Down Expand Up @@ -535,12 +594,12 @@ define(function () {
* tablet or one of the listed additional keys, otherwise <tt>false</tt>
* @function MobileDetect#is
*/
is: function(key) {
return equalIC(key, this.userAgent()) ||
is: function (key) {
return containsIC(this.userAgents(), key) ||
equalIC(key, this.os()) ||
equalIC(key, this.phone()) ||
equalIC(key, this.tablet()) ||
equalIC(key, impl.findMatch(impl.mobileDetectRules.utils, this.ua));
containsIC(impl.findMatches(impl.mobileDetectRules.utils, this.ua), key);
},

/**
Expand Down
Loading

0 comments on commit c2949fd

Please sign in to comment.