public/javascripts/ie-emulation-modes-warning.js   A
last analyzed

Complexity

Total Complexity 10
Complexity/F 3.33

Size

Lines of Code 41
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 10
c 1
b 0
f 0
nc 2
mnd 1
bc 9
fnc 3
dl 0
loc 41
rs 10
bpm 3
cpm 3.3333
noi 1

2 Functions

Rating   Name   Duplication   Size   Complexity  
A ie-emulation-modes-warning.js ➔ actualNonEmulatedIEMajorVersion 0 13 3
A ie-emulation-modes-warning.js ➔ emulatedIEMajorVersion 0 9 2
1
// NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT
2
// IT'S JUST JUNK FOR OUR DOCS!
3
// ++++++++++++++++++++++++++++++++++++++++++
4
/*!
5
 * Copyright 2014 Twitter, Inc.
6
 *
7
 * Licensed under the Creative Commons Attribution 3.0 Unported License. For
8
 * details, see http://creativecommons.org/licenses/by/3.0/.
9
 */
10
// Intended to prevent false-positive bug reports about Bootstrap not working properly in old versions of IE due to folks testing using IE's unreliable emulation modes.
11
(function () {
12
  'use strict';
13
14
  function emulatedIEMajorVersion() {
15
    var groups = /MSIE ([0-9.]+)/.exec(window.navigator.userAgent)
16
    if (groups === null) {
17
      return null
18
    }
19
    var ieVersionNum = parseInt(groups[1], 10)
20
    var ieMajorVersion = Math.floor(ieVersionNum)
21
    return ieMajorVersion
22
  }
23
24
  function actualNonEmulatedIEMajorVersion() {
25
    // Detects the actual version of IE in use, even if it's in an older-IE emulation mode.
26
    // IE JavaScript conditional compilation docs: http://msdn.microsoft.com/en-us/library/ie/121hztk3(v=vs.94).aspx
27
    // @cc_on docs: http://msdn.microsoft.com/en-us/library/ie/8ka90k2e(v=vs.94).aspx
28
    var jscriptVersion = new Function('/*@cc_on return @_jscript_version; @*/')() // jshint ignore:line
0 ignored issues
show
Performance Best Practice introduced by
Using new Function() to create a function is slow and difficult to debug. Such functions do not create a closure. Consider using another way to define your function.
Loading history...
29
    if (jscriptVersion === undefined) {
30
      return 11 // IE11+ not in emulation mode
31
    }
32
    if (jscriptVersion < 9) {
33
      return 8 // IE8 (or lower; haven't tested on IE<8)
34
    }
35
    return jscriptVersion // IE9 or IE10 in any mode, or IE11 in non-IE11 mode
36
  }
37
38
  var ua = window.navigator.userAgent
39
  if (ua.indexOf('Opera') > -1 || ua.indexOf('Presto') > -1) {
40
    return // Opera, which might pretend to be IE
41
  }
42
  var emulated = emulatedIEMajorVersion()
43
  if (emulated === null) {
44
    return // Not IE
45
  }
46
  var nonEmulated = actualNonEmulatedIEMajorVersion()
47
48
  if (emulated !== nonEmulated) {
49
    window.alert('WARNING: You appear to be using IE' + nonEmulated + ' in IE' + emulated + ' emulation mode.\nIE emulation modes can behave significantly differently from ACTUAL older versions of IE.\nPLEASE DON\'T FILE BOOTSTRAP BUGS based on testing in IE emulation modes!')
50
  }
51
})();
52