(function(){
'use strict';
window.RMWR={
toggle: function(id, openText, closeText){
const link=document.getElementById('readlink' + id);
const content=document.getElementById('read' + id);
if(!link||!content){
return;
}
const isExpanded=content.style.display!=='none'&&content.getAttribute('aria-hidden')!=='true';
const textElement=link.querySelector('.rmwr-text')||link;
const wrapper=link.closest('.rmwr-wrapper');
if(isExpanded){
this.collapse(content);
if(textElement===link){
link.innerHTML=this.escapeHtml(openText);
}else{
textElement.textContent=openText;
}
link.setAttribute('aria-expanded', 'false');
content.setAttribute('aria-hidden', 'true');
}else{
this.expand (content);
if(textElement===link){
link.innerHTML=this.escapeHtml(closeText);
}else{
textElement.textContent=closeText;
}
link.setAttribute('aria-expanded', 'true');
content.setAttribute('aria-hidden', 'false');
if(wrapper&&wrapper.dataset.smoothScroll!=='false'){
const offset=parseInt(wrapper.dataset.scrollOffset||0);
this.smoothScrollTo(content, offset);
}}
},
expand: function(element){
element.style.display='block';
const animation=element.dataset.animation||'fade';
if(animation==='fade'){
element.style.opacity='0';
element.style.overflow='hidden';
element.offsetHeight;
const duration=300;
element.style.transition=`opacity ${duration}ms ease-in-out`;
element.style.opacity='1';
setTimeout(function(){
element.style.overflow='';
element.style.transition='';
}, duration);
}else{
element.style.display='block';
}},
collapse: function(element){
const animation=element.dataset.animation||'fade';
if(animation==='fade'){
const duration=300;
element.style.transition=`opacity ${duration}ms ease-in-out`;
element.style.opacity='0';
element.style.overflow='hidden';
setTimeout(function(){
element.style.display='none';
element.style.overflow='';
element.style.transition='';
}, duration);
}else{
element.style.display='none';
}},
escapeHtml: function(text){
const div=document.createElement('div');
div.textContent=text;
return div.innerHTML;
},
smoothScrollTo: function(element, offset){
if(!element) return;
const elementPosition=element.getBoundingClientRect().top;
const offsetPosition=elementPosition + window.pageYOffset - (offset||0);
window.scrollTo({
top: offsetPosition,
behavior: 'smooth'
});
},
init: function(){
document.addEventListener('click', function(e){
const link=e.target.closest('.read-link');
if(!link){
return;
}
e.preventDefault();
e.stopPropagation();
const id=link.id.replace('readlink', '');
const openText=link.dataset.openText||link.getAttribute('data-open-text')||'Read More';
const closeText=link.dataset.closeText||link.getAttribute('data-close-text')||'Read Less';
RMWR.toggle(id, openText, closeText);
});
document.addEventListener('keydown', function(e){
const link=e.target.closest('.read-link');
if(!link||(e.key!=='Enter'&&e.key!==' ')){
return;
}
e.preventDefault();
e.stopPropagation();
const id=link.id.replace('readlink', '');
const openText=link.dataset.openText||link.getAttribute('data-open-text')||'Read More';
const closeText=link.dataset.closeText||link.getAttribute('data-close-text')||'Read Less';
RMWR.toggle(id, openText, closeText);
});
if(typeof rmwrSettings!=='undefined'&&rmwrSettings.printExpand!==false){
window.addEventListener('beforeprint', function(){
const allContent=document.querySelectorAll('.read_div[style*="display: none"]');
allContent.forEach(function(content){
content.style.display='block';
content.setAttribute('aria-hidden', 'false');
const contentId=content.id.replace('read', '');
const contentLink=document.getElementById('readlink' + contentId);
if(contentLink){
contentLink.setAttribute('aria-expanded', 'true');
}});
});
}}
};
if(document.readyState==='loading'){
document.addEventListener('DOMContentLoaded', RMWR.init);
}else{
RMWR.init();
}})();