/* Copyright (C) 2012-2014 Hewlett-Packard Development Company, L.P. All Rights Reserved. The contents of this software are proprietary and confidential to the Hewlett-Packard Development Company, L.P. No part of this program may be photocopied, reproduced, or translated into another programming language without prior written consent of the Hewlett-Packard Development Company, L.P. */ //== Declare globals from other files, for JSLint == /*global jQuery: false */ /** * Detect the browser and version. * Flags set for supported browsers[version] (and above): * chrome[23] * firefox[15] * msie[9] **/ (function ($) { 'use strict'; var SUPPORTED_BROWSERS = { CHROME: { name: 'Chrome', version: 23 }, FIREFOX: { name: 'Firefox', version: 15 }, MSIE: { name: 'MSIE', version: 9 } }; navigator.whoIs = (function() { /* Example of navigator.userAgent values: * Firefox: "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0" * Chrome: "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36" * IE8: "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; GTB7.5; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; .NET4.0C; OfficeLiveConnector.1.5; OfficeLivePatch.1.3; .NET CLR 3.0.30729; .NET4.0E)" * IE9: * IE10: "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET CLR 1.0.3705; .NET CLR 1.1.4322; SLCC1; InfoPath.3; .NET4.0C; .NET4.0E)" * IE11: win7 enterprise "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; rv:11.0) like Gecko" * win8 "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko" * Note for IE 11: the "rv" part is not always reported by some touch devices * iceweasel: version 3.5.16 "Mozilla/5.0 (x11; u; Linux i686; en-US; rv1.9.1.16) Gecko/20111108 Iceweasel/3.5.16 (like Firefox/3.5.16)" */ var ua = navigator.userAgent, tem, uaMatch = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [], browserInfo = {}; var name = uaMatch[1], version = uaMatch[2]; // MSIE is no longer reported with IE11. The version is retrieved from "rv:11" if (/trident/i.test(name)) { tem = /\brv[ :]+(\d+)/g.exec(ua) || []; name = 'MSIE'; version = (tem[1] || ''); } if (name === 'Chrome') { tem = ua.match(/\bOPR\/(\d+)/); if (tem) { name = 'Opera'; version = tem[1]; } } uaMatch = version ? [name, version]: [navigator.appName, navigator.appVersion, '-?']; tem = ua.match(/version\/(\d+)/i); if (tem) { uaMatch.splice(1, 1, tem[1]); } browserInfo.name = uaMatch[0]; browserInfo.version = uaMatch[1]; return browserInfo; }()); // Causes the validation to fail in browser without a console //window.console.log('Detected browser: ' + navigator.whoIs.name + ' ' + navigator.whoIs.version + ')'); function isSupported(browserInfo, supportedBrowser) { return browserInfo.name === supportedBrowser.name && browserInfo.version >= supportedBrowser.version; } $.isSupportedBrowser = function () { if (isSupported(navigator.whoIs, SUPPORTED_BROWSERS.FIREFOX) || isSupported(navigator.whoIs, SUPPORTED_BROWSERS.CHROME) || isSupported(navigator.whoIs, SUPPORTED_BROWSERS.MSIE)) { return true; } return false; }; $.verifySupportedBrowser = function ($container) { if (!$.isSupportedBrowser()) { $container.html( $('
').addClass('unsupported-browser-indicator').append( $('
').addClass('unsupported-browser-img') ) ).addClass('unsupported-browser'); return false; } return true; }; }(jQuery));