mirror of
https://github.com/lancedikson/bowser
synced 2024-10-27 20:34:22 +00:00
Merge branch 'release/1.4.1'
This commit is contained in:
commit
47dc65adba
@ -1,5 +1,8 @@
|
|||||||
# Bowser Changelog
|
# Bowser Changelog
|
||||||
|
|
||||||
|
### 1.4.1 (July 7, 2016)
|
||||||
|
|
||||||
|
- [FIX] Fix `strictMode` logic for `isUnsupportedBrowser`
|
||||||
|
|
||||||
### 1.4.0 (June 28, 2016)
|
### 1.4.0 (June 28, 2016)
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
"sniff",
|
"sniff",
|
||||||
"detection"
|
"detection"
|
||||||
],
|
],
|
||||||
"version": "1.3.0",
|
"version": "1.4.1",
|
||||||
"homepage": "https://github.com/ded/bowser",
|
"homepage": "https://github.com/ded/bowser",
|
||||||
"scripts": [
|
"scripts": [
|
||||||
"src/bowser.js"
|
"src/bowser.js"
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
"sniff",
|
"sniff",
|
||||||
"detection"
|
"detection"
|
||||||
],
|
],
|
||||||
"version": "1.4.0",
|
"version": "1.4.1",
|
||||||
"homepage": "https://github.com/ded/bowser",
|
"homepage": "https://github.com/ded/bowser",
|
||||||
"author": "Dustin Diaz <dustin@dustindiaz.com> (http://dustindiaz.com)",
|
"author": "Dustin Diaz <dustin@dustindiaz.com> (http://dustindiaz.com)",
|
||||||
"main": "./src/bowser.js",
|
"main": "./src/bowser.js",
|
||||||
|
104
src/bowser.js
104
src/bowser.js
@ -419,7 +419,7 @@
|
|||||||
* @return {number}
|
* @return {number}
|
||||||
*/
|
*/
|
||||||
function getVersionPrecision(version) {
|
function getVersionPrecision(version) {
|
||||||
return version.split(".").length;
|
return version.split(".").length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -453,36 +453,36 @@
|
|||||||
* @return {Number} comparison result
|
* @return {Number} comparison result
|
||||||
*/
|
*/
|
||||||
function compareVersions(versions) {
|
function compareVersions(versions) {
|
||||||
// 1) get common precision for both versions, for example for "10.0" and "9" it should be 2
|
// 1) get common precision for both versions, for example for "10.0" and "9" it should be 2
|
||||||
var precision = Math.max(getVersionPrecision(versions[0]), getVersionPrecision(versions[1]));
|
var precision = Math.max(getVersionPrecision(versions[0]), getVersionPrecision(versions[1]));
|
||||||
var chunks = map(versions, function (version) {
|
var chunks = map(versions, function (version) {
|
||||||
var delta = precision - getVersionPrecision(version);
|
var delta = precision - getVersionPrecision(version);
|
||||||
|
|
||||||
// 2) "9" -> "9.0" (for precision = 2)
|
// 2) "9" -> "9.0" (for precision = 2)
|
||||||
version = version + new Array(delta + 1).join(".0");
|
version = version + new Array(delta + 1).join(".0");
|
||||||
|
|
||||||
// 3) "9.0" -> ["000000000"", "000000009"]
|
// 3) "9.0" -> ["000000000"", "000000009"]
|
||||||
return map(version.split("."), function (chunk) {
|
return map(version.split("."), function (chunk) {
|
||||||
return new Array(20 - chunk.length).join("0") + chunk;
|
return new Array(20 - chunk.length).join("0") + chunk;
|
||||||
}).reverse();
|
}).reverse();
|
||||||
});
|
});
|
||||||
|
|
||||||
// iterate in reverse order by reversed chunks array
|
// iterate in reverse order by reversed chunks array
|
||||||
while (--precision >= 0) {
|
while (--precision >= 0) {
|
||||||
// 4) compare: "000000009" > "000000010" = false (but "9" > "10" = true)
|
// 4) compare: "000000009" > "000000010" = false (but "9" > "10" = true)
|
||||||
if (chunks[0][precision] > chunks[1][precision]) {
|
if (chunks[0][precision] > chunks[1][precision]) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
else if (chunks[0][precision] === chunks[1][precision]) {
|
|
||||||
if (precision === 0) {
|
|
||||||
// all version chunks are same
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else if (chunks[0][precision] === chunks[1][precision]) {
|
||||||
|
if (precision === 0) {
|
||||||
|
// all version chunks are same
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -504,33 +504,32 @@
|
|||||||
* @return {Boolean}
|
* @return {Boolean}
|
||||||
*/
|
*/
|
||||||
function isUnsupportedBrowser(minVersions, strictMode, ua) {
|
function isUnsupportedBrowser(minVersions, strictMode, ua) {
|
||||||
var _bowser = bowser;
|
var _bowser = bowser;
|
||||||
|
|
||||||
// make strictMode param optional with ua param usage
|
// make strictMode param optional with ua param usage
|
||||||
if (typeof strictMode === 'string') {
|
if (typeof strictMode === 'string') {
|
||||||
ua = strictMode;
|
ua = strictMode;
|
||||||
strictMode = void(0);
|
strictMode = void(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strictMode === void(0)) {
|
if (strictMode === void(0)) {
|
||||||
strictMode = false;
|
strictMode = false;
|
||||||
}
|
}
|
||||||
if (ua) {
|
if (ua) {
|
||||||
_bowser = detect(ua);
|
_bowser = detect(ua);
|
||||||
}
|
}
|
||||||
|
|
||||||
var version = "" + _bowser.version;
|
var version = "" + _bowser.version;
|
||||||
for (var browser in minVersions) {
|
for (var browser in minVersions) {
|
||||||
if (minVersions.hasOwnProperty(browser)) {
|
if (minVersions.hasOwnProperty(browser)) {
|
||||||
if (_bowser[browser]) {
|
if (_bowser[browser]) {
|
||||||
// browser version and min supported version.
|
// browser version and min supported version.
|
||||||
if (compareVersions([version, minVersions[browser]]) < 0) {
|
return compareVersions([version, minVersions[browser]]) < 0;
|
||||||
return true; // unsupported
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return strictMode; // not found
|
}
|
||||||
|
|
||||||
|
return strictMode; // not found
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -538,10 +537,11 @@
|
|||||||
*
|
*
|
||||||
* @param {Object} minVersions map of minimal version to browser
|
* @param {Object} minVersions map of minimal version to browser
|
||||||
* @param {Boolean} [strictMode = false] flag to return false if browser wasn't found in map
|
* @param {Boolean} [strictMode = false] flag to return false if browser wasn't found in map
|
||||||
|
* @param {String} [ua] user agent string
|
||||||
* @return {Boolean}
|
* @return {Boolean}
|
||||||
*/
|
*/
|
||||||
function check(minVersions, strictMode) {
|
function check(minVersions, strictMode, ua) {
|
||||||
return !isUnsupportedBrowser(minVersions, strictMode);
|
return !isUnsupportedBrowser(minVersions, strictMode, ua);
|
||||||
}
|
}
|
||||||
|
|
||||||
bowser.isUnsupportedBrowser = isUnsupportedBrowser;
|
bowser.isUnsupportedBrowser = isUnsupportedBrowser;
|
||||||
|
10
test/test.js
10
test/test.js
@ -112,11 +112,21 @@ describe('Unsupported browser check', function() {
|
|||||||
assert.equal(unsupported, false);
|
assert.equal(unsupported, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should be passed by #isUnsupportedBrowser for IE10.6 and for IE10 miminal version specified in strict mode', function() {
|
||||||
|
var unsupported = browser.isUnsupportedBrowser({msie: "10"}, true, this.ie10_6);
|
||||||
|
assert.equal(unsupported, false);
|
||||||
|
});
|
||||||
|
|
||||||
it('should NOT be passed by #check for IE10.6 and for IE11 miminal version specified', function() {
|
it('should NOT be passed by #check for IE10.6 and for IE11 miminal version specified', function() {
|
||||||
var supported = browser.check({msie: "11"}, this.ie10_6);
|
var supported = browser.check({msie: "11"}, this.ie10_6);
|
||||||
assert.equal(supported, false);
|
assert.equal(supported, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should NOT be passed by #check for IE10.6 and for IE11 miminal version specified in strict mode', function() {
|
||||||
|
var supported = browser.check({msie: "11"}, true, this.ie10_6);
|
||||||
|
assert.equal(supported, false);
|
||||||
|
});
|
||||||
|
|
||||||
it('should be passed by #check for IE10.6 when version was not specified', function() {
|
it('should be passed by #check for IE10.6 when version was not specified', function() {
|
||||||
var supported = browser.check({}, this.ie10_6);
|
var supported = browser.check({}, this.ie10_6);
|
||||||
assert.equal(supported, true);
|
assert.equal(supported, true);
|
||||||
|
Loading…
Reference in New Issue
Block a user