function _agentInit()

in trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js [199:418]


function _agentInit()
{
  // convert all characters to lowercase to simplify testing
  var agentString = navigator.userAgent.toLowerCase();

  // note that this only returns m.n (e.g. if the
  // version number is 2.3.4, this returns the float 2.3)
  var version = parseFloat(navigator.appVersion);

  // note that isBlackBerry refers to the BlackBerry browser
  // we do not currently specify the BlackBerry platform
  // because it is not necessary (if we decide to support
  // other browsers on the BlackBerry platform it may become necessary)
  var isBlackBerry      = false;
  var isGecko           = false;
  var isIE              = false;
  var isMac             = false;
  var isNav             = false;
  var isOpera           = false;
  var isPIE             = false;
  var isSafari          = false;
  var isSolaris         = false;
  var isWindows         = false;
  var isWindowsMobile6  = false;
  var isNokiaPhone      = false;
  var kind              = "unknown";

  // Group IE and IE based browsers such as IE Mobile on WM5 and WM6
  var isIEGroup         = false;

  // Indicate browser's PPR capability support
  var pprUnsupported    = false;

  // Indicate whether the browser and platform are capable of
  // sending PPR requests via JSF Ajax
  var useJsfAjax = true;

  // Flag to indicate that document object is sufficiently implemented to
  // provide good level of access to HTML, XHTML and XML document.
  // For example, Windows Mobile 5 and Blackberry does not implement
  // document.body, document.forms or document.documentElement and this
  // flag is set to false. Some features implemented in Core.js and
  // Page.js are not executed for the browsers when it is set to false.
  var supportsDomDocument = true;

  // Identifies browsers that do not support node.nodeType
  var supportsNodeType    = true;

  // Indicate browser's validation capability support
  var supportsValidation  = true;

  if (agentString.indexOf("msie") != -1
			|| agentString.indexOf("trident") != -1)
  {
    var matches = null;
    // extract ie's version from the ie string
    if (agentString.indexOf("msie") != -1) {
        matches = agentString.match(/msie (.*);/);
        version = parseFloat(matches[1]);
    } else if (agentString.indexOf("trident") != -1) {
        matches = agentString.match(/trident\/(.*);/);
        version = parseFloat(matches[1]) + 4.0;
    }
    isIEGroup = true;

    // All IE based mobile browsers
    if (agentString.indexOf("windows ce") != -1)
    {
      supportsNodeType = false;
      supportsDomDocument = false;
      supportsValidation = false;

      // PPC200X and Windows Mobile 5
      if (agentString.indexOf("ppc") != -1 &&
          version >= 4.0)
      {
        // This user agent indicates the browser is WindowsMobile 5 or
        // earlier version of PIE
        isPIE = true;

        // Windows Mobile 5 DOM and XMLHttpRequest support are not
        // sufficient to support PPR in this framework effectively.
        pprUnsupported = true;
        kind = "pie";
      }
      else
      {
        // This user agent indicates the browser is WindowsMobile 6 PIE
        isWindowsMobile6 = true;
        // A new kind string was given to WM6 browser as the
        // capability is significantly different from predecessors.
        kind = "iemobile";
        // Switch off JSF ajax for time being. There are still unresolved
        // issues with Mojarra in supporting mobile-browsers
        useJsfAjax = false;
      }
    }
    else
    {
      isIE = true;
      kind = "ie";
    }
  }
  else if (agentString.indexOf("opera") != -1)
  {
    isOpera = true;
    kind = "opera";
  }
  else if ((agentString.indexOf("applewebkit") != -1) ||
           (agentString.indexOf("safari") != -1))
  {
    isSafari = true
    kind = "safari";
  }
  else if (agentString.indexOf("gecko/") != -1)
  {
    isGecko = true;
    kind = "gecko";
    version = 1.0;
  }
  else if(agentString.indexOf("blackberry") != -1)
  {
    // if we support non-BlackBerry Browser agents on blackberry
    // devices in the future, we may need to revisit this because
    // those agents may include "blackberry" in the User-Agent
    // string; we can't just check if the User-Agent "starts with"
    // blackberry because navigator.userAgent on BlackBery Browser 4.0
    // starts with Mozilla/4.0 (even though the User-Agent sent to the
    // server starts with BlackBerry<model>/<version>)

    // BlackBerry Browser 4.0+ supports navigator.appVersion,
    // and earlier versions don't support script, so we can
    // leave the version as defined above

    // BlackBerryXXXX/Y.Y.Y.Y is the BlackBerry user agent format
    // XXXX is the model number and Y.Y.Y.Y is the OS version number.
    // At this moment, BlackBerry below version 4.6 is regarded as
    // basic HTML browser for the JS performance reason.
    // The following lines should be uncommented when we decide to
    // handle BlackBerry version 4.0~4.5 separate from the batch of
    // Basic HTML browsers after its JS performance improves.
    /*
    var versionStart = agentString.substring(agentString.indexOf(
                                                      "blackberry") + 9);
    versionStart = versionStart.substring(versionStart.indexOf("/") + 1);
    version = parseFloat(versionStart);

    if (version < 4.6)
    {
      pprUnsupported = true;
      supportsDomDocument = false;
      supportsValidation = false;
    }
    */

    isBlackBerry = true;
    kind = "blackberry";
    // Switch off the JSF ajax for time being. There are still unresolved
    // issues with Mojarra in supporting mobile browsers
    useJsfAjax = false;
  }
  else if ((agentString.indexOf('mozilla')    != -1) &&
           (agentString.indexOf('spoofer')    == -1) &&
           (agentString.indexOf('compatible') == -1))
  {
    if (version >= 5.0)
    {
      isGecko = true;
      kind = "gecko";
      version = 1.0;
    }
    else
    {
      isNav = true;
      kind = "nn";
    }
  }
  if (agentString.indexOf('win') != -1)
  {
    isWindows = true;
  }
  else if (agentString.indexOf('mac') != -1)
  {
    isMac = true;
  }
  else if (agentString.indexOf('sunos') != -1)
  {
    isSolaris = true;
  }
  else if ((agentString.indexOf('symbian') != -1) ||
           (agentString.indexOf('nokia') != -1))
  {
     isNokiaPhone = true;
     pprUnsupported = true;
  }

  _agent.isBlackBerry           = isBlackBerry;
  _agent.isGecko                = isGecko;
  _agent.isIE                   = isIE;
  _agent.isIEGroup              = isIEGroup;
  _agent.isMac                  = isMac;
  _agent.isNav                  = isNav;
  _agent.isNokiaPhone           = isNokiaPhone;
  _agent.isOpera                = isOpera;
  _agent.isPIE                  = isPIE;
  _agent.isSafari               = isSafari;
  _agent.isSolaris              = isSolaris;
  _agent.isWindows              = isWindows;
  _agent.isWindowsMobile6       = isWindowsMobile6;
  _agent.kind                   = kind;
  _agent.pprUnsupported         = pprUnsupported;
  _agent.useJsfAjax             = useJsfAjax;
  _agent.supportsDomDocument    = supportsDomDocument;
  _agent.supportsNodeType       = supportsNodeType;
  _agent.supportsValidation     = supportsValidation;
  _agent.version                = version;

  _agent.atLeast                = _atLeast;
  _agent.atMost                 = _atMost;
}