You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
4.1 KiB

  1. (function() {
  2. // cookie functions
  3. var trustArcHelper = {};
  4. var temp = location.host.split('.').reverse();
  5. var rootDomain = '.' + temp[1] + '.' + temp[0];
  6. trustArcHelper.cookieDomain = rootDomain;
  7. trustArcHelper.sanitizeUntrusted = function(s) {
  8. var str = '';
  9. if (typeof s == 'string') {
  10. str = s.replace(/[;'<\/>=\)\(]/gm, '!');
  11. } else if (typeof s == 'number' || typeof s == 'boolean') {
  12. str = s;
  13. }
  14. return str;
  15. };
  16. trustArcHelper.getCookie = function(cookieName) {
  17. var name = encodeURI(cookieName) + '=';
  18. var cookieValue = '';
  19. var ca = document.cookie.split(';');
  20. for (var i = 0; i < ca.length; i++) {
  21. var c = ca[i];
  22. while (c.charAt(0) == ' ') c = c.substring(1);
  23. if (c.indexOf(name) === 0) {
  24. cookieValue = c.substring(name.length, c.length);
  25. return decodeURIComponent(cookieValue);
  26. }
  27. }
  28. return cookieValue;
  29. };
  30. trustArcHelper.setCookie = function(cookieName, cookieValue, exdays) {
  31. // check for html markup in cookieValue
  32. // if html markup present, remove the markup portion
  33. var cookieVal = cookieValue || '';
  34. cookieVal = trustArcHelper.sanitizeUntrusted(cookieVal);
  35. // set expiration time
  36. var expires = '';
  37. if (typeof exdays != 'undefined' && exdays > 0) {
  38. var d = new Date();
  39. d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
  40. expires = '; expires=' + d.toUTCString();
  41. }
  42. document.cookie =
  43. encodeURI(cookieName) +
  44. '=' +
  45. encodeURIComponent(cookieVal) +
  46. expires +
  47. '; path=/; domain=' +
  48. trustArcHelper.cookieDomain;
  49. };
  50. trustArcHelper.loadScript = function(c, a) {
  51. var b = document.createElement('script');
  52. b.type = 'text/javascript';
  53. if (a && typeof a == 'function') {
  54. if (b.readyState) {
  55. b.onreadystatechange = function() {
  56. if (b.readyState === 'loaded' || b.readyState === 'complete') {
  57. b.onreadystatechange = null;
  58. a();
  59. }
  60. };
  61. } else {
  62. b.onload = function() {
  63. a();
  64. };
  65. }
  66. }
  67. b.src = c;
  68. document.getElementsByTagName('head')[0].appendChild(b);
  69. };
  70. // load the trust arc script
  71. var taCountry = '';
  72. var taState = '';
  73. if (trustArcHelper.getCookie('trustArcTesting') == 'yes') {
  74. taCountry = trustArcHelper.getCookie('trustArcCountry') || 'us';
  75. taCountry = taCountry.toLowerCase();
  76. if (taCountry == 'us') {
  77. taState = trustArcHelper.getCookie('trustArcState');
  78. }
  79. }
  80. if (
  81. document.location.pathname.indexOf('/forms') !== 0 &&
  82. document.location.hostname !== 'redhat.lookbookhq.com'
  83. ) {
  84. if (taState == 'ca') {
  85. // just used for ccpa testing
  86. trustArcHelper.loadScript(
  87. 'https://consent.trustarc.com/notice?domain=redhatstage.com&c=teconsent&state=ca&js=nj&noticeType=bb&gtm=1&text=true&privacypolicylink=https://www.redhat.com/en/about/privacy-policy'
  88. );
  89. } else if (taCountry) {
  90. trustArcHelper.loadScript(
  91. 'https://consent.trustarc.com/notice?domain=redhat.com&c=teconsent&country=' +
  92. taCountry +
  93. '&js=nj&noticeType=bb&gtm=1&text=true&privacypolicylink=https://www.redhat.com/en/about/privacy-policy'
  94. );
  95. } else {
  96. trustArcHelper.loadScript(
  97. 'https://consent.trustarc.com/notice?domain=redhat.com&c=teconsent&js=nj&noticeType=bb&gtm=1&text=true&privacypolicylink=https://www.redhat.com/en/about/privacy-policy'
  98. );
  99. }
  100. }
  101. var _STATE = {};
  102. function runOnce() {
  103. if (
  104. !_STATE.hasRunOnce &&
  105. window.truste &&
  106. truste.eu &&
  107. truste.eu.prefclose
  108. ) {
  109. _STATE.oldValue = parseInt(truste.eu.bindMap.prefCookie);
  110. _STATE.oldMethod = truste.eu.prefclose;
  111. truste.eu.prefclose = function() {
  112. _STATE.oldMethod();
  113. if (_STATE.oldValue != parseInt(truste.eu.bindMap.prefCookie))
  114. setTimeout(function() {
  115. window.location.reload();
  116. }, 20);
  117. };
  118. _STATE.hasRunOnce = true;
  119. _STATE.i && clearInterval(_STATE.i);
  120. }
  121. }
  122. _STATE.i = setInterval(runOnce, 10);
  123. // end trust arc script
  124. })();