Initial release
[ryf-theme.git] / js / active-link.js
CommitLineData
1e7a45c4
VSB
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
8(function (Drupal, drupalSettings) {
9 Drupal.behaviors.activeLinks = {
10 attach: function attach(context) {
11 var path = drupalSettings.path;
12 var queryString = JSON.stringify(path.currentQuery);
13 var querySelector = path.currentQuery ? '[data-drupal-link-query=\'' + queryString + '\']' : ':not([data-drupal-link-query])';
14 var originalSelectors = ['[data-drupal-link-system-path="' + path.currentPath + '"]'];
15 var selectors = void 0;
16
17 if (path.isFront) {
18 originalSelectors.push('[data-drupal-link-system-path="<front>"]');
19 }
20
21 selectors = [].concat(originalSelectors.map(function (selector) {
22 return selector + ':not([hreflang])';
23 }), originalSelectors.map(function (selector) {
24 return selector + '[hreflang="' + path.currentLanguage + '"]';
25 }));
26
27 selectors = selectors.map(function (current) {
28 return current + querySelector;
29 });
30
31 var activeLinks = context.querySelectorAll(selectors.join(','));
32 var il = activeLinks.length;
33 for (var i = 0; i < il; i++) {
34 activeLinks[i].classList.add('is-active');
35 }
36 },
37 detach: function detach(context, settings, trigger) {
38 if (trigger === 'unload') {
39 var activeLinks = context.querySelectorAll('[data-drupal-link-system-path].is-active');
40 var il = activeLinks.length;
41 for (var i = 0; i < il; i++) {
42 activeLinks[i].classList.remove('is-active');
43 }
44 }
45 }
46 };
47})(Drupal, drupalSettings);