1(function (Drupal, $) { 2 'use strict'; 3 4 Drupal.behaviors.browser_detect = { 5 browserVersion: function () { 6 const userBrowser = (navigator.userAgent).toLowerCase(); 7 const maxTouchPoints = navigator.maxTouchPoints; 8 let $html = document.getElementsByTagName('html')[0], 9 browsers = [], 10 systemOp = [], 11 matches; 12 13 // Browser 14 browsers.safari = userBrowser.indexOf('safari'); 15 browsers.chrome = (userBrowser.indexOf('chrome') > -1 || userBrowser.indexOf('crios') > -1 ) ? 1 : -1; 16 browsers.firefox = userBrowser.indexOf('firefox'); 17 browsers.ie = userBrowser.indexOf('msie'); 18 browsers.ie11 = userBrowser.indexOf('rv:11'); 19 browsers.msedge = userBrowser.indexOf('edg'); 20 browsers.samsung = userBrowser.indexOf('samsung'); 21 browsers.ucbrowser = userBrowser.indexOf('ucbrowser'); 22 browsers.facebook = (userBrowser.indexOf('fbdv') > -1 || userBrowser.indexOf('fb_iab') > -1 ) ? 1 : -1; 23 browsers.instagram = userBrowser.indexOf('instagram'); 24 25 //SO 26 systemOp.linux = userBrowser.indexOf('linux'); 27 systemOp.macintosh = (userBrowser.indexOf('macintosh') > -1 && maxTouchPoints === 0) ? 1 : -1; 28 systemOp.windows = userBrowser.indexOf('windows'); 29 systemOp.ipad = (userBrowser.indexOf('ipad') > -1) || (userBrowser.indexOf('macintosh') && maxTouchPoints > 0) ? 1 : -1; 30 systemOp.android = userBrowser.indexOf('android'); 31 systemOp.iphone = userBrowser.indexOf('iphone'); 32 33 //Chrome, Safari, Edge, Samsung, UC, Facebook & Instagram className 34 if(browsers.samsung > -1) { 35 $html.classList.add('samsungbrowser'); 36 } else if(browsers.ucbrowser > -1) { 37 $html.classList.add('ucbrowser'); 38 } else if(browsers.facebook > -1) { 39 $html.classList.add('facebook'); 40 } else if(browsers.instagram > -1) { 41 $html.classList.add('instagram'); 42 } else if ((browsers.safari > -1) && (browsers.chrome <= -1) && (browsers.msedge <= -1)) { 43 $html.classList.add('safari'); 44 matches = userBrowser.match(/version\/([0-9]*)/); 45 $html.classList.add(`safari${matches[1]}`); 46 } else if ((browsers.chrome > -1) && (browsers.msedge <= -1)) { 47 $html.classList.add('chrome'); 48 matches = userBrowser.match(/chrome\/([0-9]*)|crios\/([0-9]*)/); 49 $html.classList.add(`chrome${matches[1]}`); 50 } else if (browsers.msedge > -1) { 51 $html.classList.add('edge'); 52 matches = userBrowser.match(/edge\/([0-9]*)|edg\/([0-9]*)/); 53 $html.classList.add(`edge${matches[1]}`); 54 } 55 56 //firefox 57 if (browsers.firefox > -1) { 58 $html.classList.add('firefox'); 59 matches = userBrowser.match(/firefox\/([0-9]*)/); 60 $html.classList.add(`firefox${matches[1]}`); 61 } 62 63 //IE 64 if (browsers.ie > -1 || browsers.ie11 > -1) { 65 $html.classList.add('ie'); 66 if (browsers.ie > -1) { 67 matches = userBrowser.match(/msie\ ([0-9]*)/); 68 $html.classList.add(`ie${matches[1]}`); 69 } else { 70 //IE11 71 $html.classList.add('ie11'); 72 } 73 } 74 75 //Windows 76 if (systemOp.windows > -1) { 77 $html.classList.add('windows'); 78 $html.classList.add('desktop'); 79 } 80 //macintosh 81 if (systemOp.macintosh > -1) { 82 $html.classList.add('macintosh'); 83 $html.classList.add('desktop'); 84 } 85 //linux 86 if (systemOp.linux > -1 && systemOp.android <= -1) { 87 $html.classList.add('linux'); 88 $html.classList.add('desktop'); 89 } 90 //android 91 if (systemOp.android > -1) { 92 $html.classList.add('android'); 93 $html.classList.add('mobile'); 94 } 95 //ipad 96 if (systemOp.ipad > -1) { 97 $html.classList.add('ipad'); 98 $html.classList.add('mobile'); 99 $html.classList.add('ios'); 100 } 101 //iphone 102 if (systemOp.iphone > -1) { 103 $html.classList.add('iphone'); 104 $html.classList.add('mobile'); 105 $html.classList.add('ios'); 106 } 107 }, 108 109 attach: function (context) { 110 const hasHtmlTag = $('html', context).length; 111 if (hasHtmlTag) { 112 Drupal.behaviors.browser_detect.browserVersion(); 113 } 114 } 115 }; 116 117})(Drupal, jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.