Skip to content

Commit

Permalink
Add IE 11, attempt to detect IE in compatibility mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
biggora authored and biggora committed Dec 8, 2013
1 parent ffe8ee1 commit 1fad1b0
Show file tree
Hide file tree
Showing 3 changed files with 298 additions and 42 deletions.
37 changes: 32 additions & 5 deletions lib/express-useragent.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @created 2011-12-10 17:19:10
* @category Express Helpers
* @package express-useragent
* @version 0.0.8
* @version 0.0.9
* @copyright Copyright (c) 2009-2011 - All rights reserved.
* @license MIT License
* @author Alexey Gordeyev IK <aleksej@gordejev.lv>
Expand All @@ -13,10 +13,10 @@
*/

var UserAgent = function() {
this.version = '0.0.8';
this.version = '0.0.9';
this._Versions = {
Firefox: /firefox\/([\d\w\.\-]+)/i,
IE: /msie\s([\d\.]+[\d])/i,
IE: /msie\s([\d\.]+[\d])|trident\/\d+\.\d+;\s+[rv:]+(\d+\.\d)/i,
Chrome: /chrome\/([\d\w\.\-]+)/i,
Safari: /version\/([\d\w\.\-]+)/i,
Opera: /version\/([\d\w\.\-]+)/i,
Expand All @@ -38,7 +38,7 @@ var UserAgent = function() {
Chromium: /chromium/i,
Chrome: /chrome/i,
Safari: /safari/i,
IE: /msie/i,
IE: /msie|trident/i,
Opera: /opera/i,
PS3: /playstation 3/i,
PSP: /playstation portable/i,
Expand Down Expand Up @@ -85,6 +85,7 @@ var UserAgent = function() {
isBlackberry : false,
isOpera : false,
isIE : false,
isIECompatibilityMode : false,
isSafari : false,
isFirefox : false,
isWebkit : false,
Expand Down Expand Up @@ -184,7 +185,7 @@ var UserAgent = function() {
break;
case 'IE':
if (this._Versions.IE.test(string)) {
return RegExp.$1;
return RegExp.$2? RegExp.$2:RegExp.$1;
}
break;
case 'ps3':
Expand Down Expand Up @@ -317,6 +318,30 @@ var UserAgent = function() {
return 'unknown';
}
};

this.testCompatibilityMode = function() {
var ua = this;
if(this.Agent.isIE){
if(/Trident\/(\d)\.0/i.test(ua.Agent.source)){
var tridentVersion = parseInt(RegExp.$1,10);
var version = parseInt(ua.Agent.Version,10);
if(version === 7 && tridentVersion === 6){
ua.Agent.isIECompatibilityMode = true;
ua.Agent.Version = 10.0;
}

if(version === 7 && tridentVersion === 5){
ua.Agent.isIECompatibilityMode = true;
ua.Agent.Version = 9.0;
}

if(version === 7 && tridentVersion === 4){
ua.Agent.isIECompatibilityMode = true;
ua.Agent.Version = 8.0;
}
}
}
};

this.reset = function reset() {
var ua = this;
Expand Down Expand Up @@ -392,6 +417,7 @@ var UserAgent = function() {
ua.testBot();
ua.testMobile();
ua.testAndriodTablet();
ua.testCompatibilityMode();
return ua.Agent;
};

Expand All @@ -409,6 +435,7 @@ var UserAgent = function() {
ua.testBot();
ua.testMobile();
ua.testAndriodTablet();
ua.testCompatibilityMode();
req.useragent = ua.Agent;
res.locals({"useragent" : ua.Agent});
next();
Expand Down
74 changes: 37 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
{
"name": "express-useragent",
"description": "ExpressJS user-agent middleware",
"version": "0.0.8-1",
"homepage": "https://github.com/biggora/express-useragent/",
"repository": {
"type": "git",
"url": "git://github.com/biggora/express-useragent.git"
},
"author": "Aleksej Gordejev <aleksej@gordejev.lv> (https://github.com/biggora/)",
"keywords": [
"useragent",
"connect",
"express",
"trinte",
"railway",
"compound",
"middleware"
],
"main": "./index.js",
"directories": {
"lib": "lib",
"tests": "tests"
},
"engines": {
"node": ">=0.5"
},
"dependencies": {},
"devDependencies": {
"connect": ">= 1.7.1 < 2.0.0",
"express": ">= 2.5.0 < 3.0.0",
"nodeunit": ">=0.5.4"
},
"scripts": {
"test": "nodeunit tests/browsers.js"
}
}
{
"name": "express-useragent",
"description": "ExpressJS/Connect user-agent middleware exposing",
"version": "0.0.9",
"homepage": "https://github.com/biggora/express-useragent/",
"repository": {
"type": "git",
"url": "git://github.com/biggora/express-useragent.git"
},
"author": "Aleksej Gordejev <aleksej@gordejev.lv> (https://github.com/biggora/)",
"keywords": [
"useragent",
"connect",
"express",
"trinte",
"railway",
"compound",
"middleware"
],
"main": "./index.js",
"directories": {
"lib": "lib",
"tests": "tests"
},
"engines": {
"node": ">=0.5"
},
"dependencies": {},
"devDependencies": {
"connect": ">= 1.7.1 < 2.0.0",
"express": ">= 2.5.0 < 3.0.0",
"nodeunit": ">=0.5.4"
},
"scripts": {
"test": "nodeunit tests/browsers.js"
}
}
Loading

0 comments on commit 1fad1b0

Please sign in to comment.