active-link.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * DO NOT EDIT THIS FILE.
  3. * See the following change record for more information,
  4. * https://www.drupal.org/node/2815083
  5. * @preserve
  6. **/
  7. (function (Drupal, drupalSettings) {
  8. Drupal.behaviors.activeLinks = {
  9. attach: function attach(context) {
  10. var path = drupalSettings.path;
  11. var queryString = JSON.stringify(path.currentQuery);
  12. var querySelector = path.currentQuery ? '[data-drupal-link-query=\'' + queryString + '\']' : ':not([data-drupal-link-query])';
  13. var originalSelectors = ['[data-drupal-link-system-path="' + path.currentPath + '"]'];
  14. var selectors = void 0;
  15. if (path.isFront) {
  16. originalSelectors.push('[data-drupal-link-system-path="<front>"]');
  17. }
  18. selectors = [].concat(originalSelectors.map(function (selector) {
  19. return selector + ':not([hreflang])';
  20. }), originalSelectors.map(function (selector) {
  21. return selector + '[hreflang="' + path.currentLanguage + '"]';
  22. }));
  23. selectors = selectors.map(function (current) {
  24. return current + querySelector;
  25. });
  26. var activeLinks = context.querySelectorAll(selectors.join(','));
  27. var il = activeLinks.length;
  28. for (var i = 0; i < il; i++) {
  29. activeLinks[i].classList.add('is-active');
  30. }
  31. },
  32. detach: function detach(context, settings, trigger) {
  33. if (trigger === 'unload') {
  34. var activeLinks = context.querySelectorAll('[data-drupal-link-system-path].is-active');
  35. var il = activeLinks.length;
  36. for (var i = 0; i < il; i++) {
  37. activeLinks[i].classList.remove('is-active');
  38. }
  39. }
  40. }
  41. };
  42. })(Drupal, drupalSettings);