Issue #3111409 by mherchel, proeung, larowlan, alexpott, lauriii, Gábor Hojtsy, andrewmacpherson, catch, xjm, andypost, rahulrasgon, rabbitlair, mrconnerton, poojakural, boulaffasae, jerseycheese, shimpy, Indrajith KB, DuneBL, kiran.kadam911, komalkolekar, keboca, hawkeye.twolf, andrewozone, Maithri Shetty, alexdmccabe, sd9121, Sreenivas Bttv, katannshaw, mgifford, nod_, webchick, mtift, rainbreaw, Berdir, brianperry, thejimbirch, Dom., q0rban, nitesh624, hansa11, himanshu_sindhwani, kostyashupenko, shaktik, bnjmnm, sharma.amitt16, sonam.chaturvedi, steinmb, shaal, ressa, Ramya Balasubramanian, Sebacic, pradeepjha, tanmaykadam, thedrupalkid, vinitk, volkswagenchick, viappidu, vebrovski, Ujval Shah, Webbeh, Yuri, trebormc, msuthars, mrinalini9, bash247, chetanbharambe, ellenoise, anevins, andriyun, CocoM, JayKandari, ambuj_gupta, hussainweb, jhodgdon, Pooja Ganjage, ju.vanderw, jwitkowski79, MaxPah, Lokender Singh2, jponch, KarenS, KarinG, Lal_: Add new Olivero frontend theme to Drupal 9.1 core as beta; later make it stable and the default
2020-10-16 09:43:55 +00:00
|
|
|
/**
|
2022-09-09 06:26:42 +00:00
|
|
|
* @file
|
|
|
|
* Customization of comments.
|
|
|
|
*/
|
Issue #3111409 by mherchel, proeung, larowlan, alexpott, lauriii, Gábor Hojtsy, andrewmacpherson, catch, xjm, andypost, rahulrasgon, rabbitlair, mrconnerton, poojakural, boulaffasae, jerseycheese, shimpy, Indrajith KB, DuneBL, kiran.kadam911, komalkolekar, keboca, hawkeye.twolf, andrewozone, Maithri Shetty, alexdmccabe, sd9121, Sreenivas Bttv, katannshaw, mgifford, nod_, webchick, mtift, rainbreaw, Berdir, brianperry, thejimbirch, Dom., q0rban, nitesh624, hansa11, himanshu_sindhwani, kostyashupenko, shaktik, bnjmnm, sharma.amitt16, sonam.chaturvedi, steinmb, shaal, ressa, Ramya Balasubramanian, Sebacic, pradeepjha, tanmaykadam, thedrupalkid, vinitk, volkswagenchick, viappidu, vebrovski, Ujval Shah, Webbeh, Yuri, trebormc, msuthars, mrinalini9, bash247, chetanbharambe, ellenoise, anevins, andriyun, CocoM, JayKandari, ambuj_gupta, hussainweb, jhodgdon, Pooja Ganjage, ju.vanderw, jwitkowski79, MaxPah, Lokender Singh2, jponch, KarenS, KarinG, Lal_: Add new Olivero frontend theme to Drupal 9.1 core as beta; later make it stable and the default
2020-10-16 09:43:55 +00:00
|
|
|
|
2021-12-18 06:12:16 +00:00
|
|
|
((Drupal, once) => {
|
2022-09-09 06:26:42 +00:00
|
|
|
/**
|
|
|
|
* Initialize show/hide button for the comments.
|
|
|
|
*
|
|
|
|
* @param {Element} comments
|
|
|
|
* The comment wrapper element.
|
|
|
|
*/
|
2021-06-29 07:31:29 +00:00
|
|
|
function init(comments) {
|
2022-09-09 06:26:42 +00:00
|
|
|
comments
|
|
|
|
.querySelectorAll('[data-drupal-selector="comment"]')
|
|
|
|
.forEach((comment) => {
|
|
|
|
if (
|
|
|
|
comment.nextElementSibling != null &&
|
|
|
|
comment.nextElementSibling.matches('.indented')
|
|
|
|
) {
|
|
|
|
comment.classList.add('has-children');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
comments.querySelectorAll('.indented').forEach((commentGroup) => {
|
2021-12-18 06:12:16 +00:00
|
|
|
const showHideWrapper = document.createElement('div');
|
2021-06-29 07:31:29 +00:00
|
|
|
showHideWrapper.setAttribute('class', 'show-hide-wrapper');
|
2022-09-09 06:26:42 +00:00
|
|
|
|
2021-12-18 06:12:16 +00:00
|
|
|
const toggleCommentsBtn = document.createElement('button');
|
2021-06-29 07:31:29 +00:00
|
|
|
toggleCommentsBtn.setAttribute('type', 'button');
|
|
|
|
toggleCommentsBtn.setAttribute('aria-expanded', 'true');
|
|
|
|
toggleCommentsBtn.setAttribute('class', 'show-hide-btn');
|
|
|
|
toggleCommentsBtn.innerText = Drupal.t('Replies');
|
2022-09-09 06:26:42 +00:00
|
|
|
|
2021-06-29 07:31:29 +00:00
|
|
|
commentGroup.parentNode.insertBefore(showHideWrapper, commentGroup);
|
|
|
|
showHideWrapper.appendChild(toggleCommentsBtn);
|
2022-09-09 06:26:42 +00:00
|
|
|
|
|
|
|
toggleCommentsBtn.addEventListener('click', (e) => {
|
2021-06-29 07:31:29 +00:00
|
|
|
commentGroup.classList.toggle('hidden');
|
2022-09-09 06:26:42 +00:00
|
|
|
e.currentTarget.setAttribute(
|
|
|
|
'aria-expanded',
|
|
|
|
commentGroup.classList.contains('hidden') ? 'false' : 'true',
|
|
|
|
);
|
2021-06-29 07:31:29 +00:00
|
|
|
});
|
Issue #3111409 by mherchel, proeung, larowlan, alexpott, lauriii, Gábor Hojtsy, andrewmacpherson, catch, xjm, andypost, rahulrasgon, rabbitlair, mrconnerton, poojakural, boulaffasae, jerseycheese, shimpy, Indrajith KB, DuneBL, kiran.kadam911, komalkolekar, keboca, hawkeye.twolf, andrewozone, Maithri Shetty, alexdmccabe, sd9121, Sreenivas Bttv, katannshaw, mgifford, nod_, webchick, mtift, rainbreaw, Berdir, brianperry, thejimbirch, Dom., q0rban, nitesh624, hansa11, himanshu_sindhwani, kostyashupenko, shaktik, bnjmnm, sharma.amitt16, sonam.chaturvedi, steinmb, shaal, ressa, Ramya Balasubramanian, Sebacic, pradeepjha, tanmaykadam, thedrupalkid, vinitk, volkswagenchick, viappidu, vebrovski, Ujval Shah, Webbeh, Yuri, trebormc, msuthars, mrinalini9, bash247, chetanbharambe, ellenoise, anevins, andriyun, CocoM, JayKandari, ambuj_gupta, hussainweb, jhodgdon, Pooja Ganjage, ju.vanderw, jwitkowski79, MaxPah, Lokender Singh2, jponch, KarenS, KarinG, Lal_: Add new Olivero frontend theme to Drupal 9.1 core as beta; later make it stable and the default
2020-10-16 09:43:55 +00:00
|
|
|
});
|
2021-06-29 07:31:29 +00:00
|
|
|
}
|
|
|
|
|
2022-09-09 06:26:42 +00:00
|
|
|
/**
|
|
|
|
* Attaches the comment behavior to comments.
|
|
|
|
*
|
|
|
|
* @type {Drupal~behavior}
|
|
|
|
*
|
|
|
|
* @prop {Drupal~behaviorAttach} attach
|
|
|
|
* Attaches the show/hide behavior for indented comments.
|
|
|
|
*/
|
2021-06-29 07:31:29 +00:00
|
|
|
Drupal.behaviors.comments = {
|
2021-12-18 06:12:16 +00:00
|
|
|
attach(context) {
|
2022-09-09 06:26:42 +00:00
|
|
|
once('comments', '[data-drupal-selector="comments"]', context).forEach(
|
|
|
|
init,
|
|
|
|
);
|
|
|
|
},
|
2021-06-29 07:31:29 +00:00
|
|
|
};
|
2022-09-09 06:26:42 +00:00
|
|
|
})(Drupal, once);
|