matomo.admin.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /**
  2. * @file
  3. * Matomo admin behaviors.
  4. */
  5. (function ($) {
  6. "use strict";
  7. /**
  8. * Provide the summary information for the tracking settings vertical tabs.
  9. */
  10. Drupal.behaviors.trackingSettingsSummary = {
  11. attach: function () {
  12. // Make sure this behavior is processed only if drupalSetSummary is defined.
  13. if (typeof jQuery.fn.drupalSetSummary === 'undefined') {
  14. return;
  15. }
  16. $('#edit-page-visibility-settings').drupalSetSummary(function (context) {
  17. var $radio = $('input[name="matomo_visibility_request_path_mode"]:checked', context);
  18. if ($radio.val() === '0') {
  19. if (!$('textarea[name="matomo_visibility_request_path_pages"]', context).val()) {
  20. return Drupal.t('Not restricted');
  21. }
  22. else {
  23. return Drupal.t('All pages with exceptions');
  24. }
  25. }
  26. else {
  27. return Drupal.t('Restricted to certain pages');
  28. }
  29. });
  30. $('#edit-role-visibility-settings').drupalSetSummary(function (context) {
  31. var vals = [];
  32. $('input[type="checkbox"]:checked', context).each(function () {
  33. vals.push($.trim($(this).next('label').text()));
  34. });
  35. if (!vals.length) {
  36. return Drupal.t('Not restricted');
  37. }
  38. else if ($('input[name="matomo_visibility_user_role_mode"]:checked', context).val() === '1') {
  39. return Drupal.t('Excepted: @roles', {'@roles': vals.join(', ')});
  40. }
  41. else {
  42. return vals.join(', ');
  43. }
  44. });
  45. $('#edit-user-visibility-settings').drupalSetSummary(function (context) {
  46. var $radio = $('input[name="matomo_visibility_user_account_mode"]:checked', context);
  47. if ($radio.val() === '0') {
  48. return Drupal.t('Not customizable');
  49. }
  50. else if ($radio.val() === '1') {
  51. return Drupal.t('On by default with opt out');
  52. }
  53. else {
  54. return Drupal.t('Off by default with opt in');
  55. }
  56. });
  57. $('#edit-linktracking').drupalSetSummary(function (context) {
  58. var vals = [];
  59. if ($('input#edit-matomo-trackmailto', context).is(':checked')) {
  60. vals.push(Drupal.t('Mailto links'));
  61. }
  62. if ($('input#edit-matomo-trackfiles', context).is(':checked')) {
  63. vals.push(Drupal.t('Outbound links'));
  64. vals.push(Drupal.t('Downloads'));
  65. }
  66. if ($('input#edit-matomo-trackcolorbox', context).is(':checked')) {
  67. vals.push(Drupal.t('Colorbox'));
  68. }
  69. if (!vals.length) {
  70. return Drupal.t('Not tracked');
  71. }
  72. return Drupal.t('@items enabled', {'@items': vals.join(', ')});
  73. });
  74. $('#edit-messagetracking').drupalSetSummary(function (context) {
  75. var vals = [];
  76. $('input[type="checkbox"]:checked', context).each(function () {
  77. vals.push($.trim($(this).next('label').text()));
  78. });
  79. if (!vals.length) {
  80. return Drupal.t('Not tracked');
  81. }
  82. return Drupal.t('@items enabled', {'@items': vals.join(', ')});
  83. });
  84. $('#edit-search').drupalSetSummary(function (context) {
  85. var vals = [];
  86. if ($('input#edit-matomo-site-search', context).is(':checked')) {
  87. vals.push(Drupal.t('Site search'));
  88. }
  89. if (!vals.length) {
  90. return Drupal.t('Not tracked');
  91. }
  92. return Drupal.t('@items enabled', {'@items': vals.join(', ')});
  93. });
  94. $('#edit-domain-tracking').drupalSetSummary(function (context) {
  95. var $radio = $('input[name="matomo_domain_mode"]:checked', context);
  96. if ($radio.val() === '0') {
  97. return Drupal.t('A single domain');
  98. }
  99. else if ($radio.val() === '1') {
  100. return Drupal.t('One domain with multiple subdomains');
  101. }
  102. });
  103. $('#edit-page-title-hierarchy').drupalSetSummary(function (context) {
  104. var vals = [];
  105. if ($('input#edit-matomo-page-title-hierarchy', context).is(':checked')) {
  106. vals.push(Drupal.t('Show page titles'));
  107. }
  108. if ($('input#edit-matomo-page-title-hierarchy-exclude-home', context).is(':checked')) {
  109. vals.push(Drupal.t('Hide home page'));
  110. }
  111. if (!vals.length) {
  112. return Drupal.t('Not tracked');
  113. }
  114. return Drupal.t('@items enabled', {'@items': vals.join(', ')});
  115. });
  116. $('#edit-privacy').drupalSetSummary(function (context) {
  117. var vals = [];
  118. if ($('input#edit-matomo-privacy-donottrack', context).is(':checked')) {
  119. vals.push(Drupal.t('Universal web tracking opt-out'));
  120. }
  121. if (!vals.length) {
  122. return Drupal.t('No privacy');
  123. }
  124. return Drupal.t('@items enabled', {'@items': vals.join(', ')});
  125. });
  126. }
  127. };
  128. })(jQuery);