Skip to content

Commit

Permalink
Simplify has("ie") detection.
Browse files Browse the repository at this point in the history
Trident is set for IE8+, so I removed some legacy code that was only needed for IE6-7.

Also, document.documentMode seems to be always set for IE8-11, even
without an x-ua-compatible <meta> tag, but I left in code to check
navigator.appVersion too, just in case it's needed for future
versions of IE.
  • Loading branch information
wkeese committed May 4, 2015
1 parent 4ad0cd7 commit 6b6da21
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 28 deletions.
35 changes: 7 additions & 28 deletions sniff.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,41 +36,20 @@ define(["./features"], function (has) {

has.add("wp", parseFloat(dua.split("Windows Phone ")[1]) || undefined);


// Browser detection
var webkit = parseFloat(dua.split("WebKit/")[1]) || undefined;
if (webkit) {
has.add("webkit", webkit);
has.add("chrome", parseFloat(dua.split("Chrome/")[1]) || undefined);
has.add("safari", dav.indexOf("Safari") >= 0 && !has("chrome") && !has("android") ?
parseFloat(dav.split("Version/")[1]) : undefined);
} else {
var isIE = 0;
if (document.all) {
// IE < 11
isIE = parseFloat(dav.split("MSIE ")[1]) || undefined;
} else if (dav.indexOf("Trident")) {
// IE >= 9
isIE = parseFloat(dav.split("rv:")[1]) || undefined;
}
if (isIE) {
// In cases where the page has an HTTP header or META tag with
// X-UA-Compatible, then it is in emulation mode.
// Make sure isIE reflects the desired version.
// Only switch the value if documentMode's major version
// is different from isIE's major version.
var mode = document.documentMode;
if (mode && Math.floor(isIE) !== mode) {
isIE = mode;
}

has.add("ie", isIE);
} else if (dua.indexOf("Gecko") >= 0) {
// Mozilla and firefox
has.add("mozilla", tv);
// We really need to get away from this. Consider a sane isGecko approach for the future.
has.add("ff", parseFloat(dua.split("Firefox/")[1] || dua.split("Minefield/")[1]) || undefined);
}
} else if (dav.indexOf("Trident") >= 0) {
// IE8+
has.add("ie", document.documentMode || parseFloat(dav.split("rv:")[1]));
} else if (dua.indexOf("Gecko") >= 0) {
// Mozilla and firefox
has.add("mozilla", tv);
has.add("ff", parseFloat(dua.split("Firefox/")[1] || dua.split("Minefield/")[1]) || undefined);
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/functional/sniff.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
Expand Down

0 comments on commit 6b6da21

Please sign in to comment.