Files
acrib.es/wp-content/plugins/kadence-blocks/includes/assets/js/kb-show-more.min.js

1 line
8.0 KiB
JavaScript
Raw Normal View History

(function(){"use strict";window.kadenceShowMore={cache:{},extractVisibleText(a,b){if(!a)return"";if(!b||0>=b)return"";const c=a.hasAttribute("inert");c&&a.removeAttribute("inert");const d=a.getBoundingClientRect(),e=d.top+b,f=[],g=a=>{if("SCRIPT"===a.tagName||"STYLE"===a.tagName||"NOSCRIPT"===a.tagName)return;const c=window.getComputedStyle(a);if("none"===c.display||"hidden"===c.visibility)return;const h=a.getBoundingClientRect();if(h.top>=e)return;let i=!1,j="";for(const b of a.childNodes)if(3===b.nodeType){const a=b.textContent.trim();a&&(i=!0,j+=a+" ")}if(i&&j.trim()){const a=h.top-d.top,c=h.bottom-d.top;if(a<b){if(c>b){const c=(b-a)/h.height,d=j.trim().split(/\s+/),e=Math.max(1,Math.floor(d.length*c));j=d.slice(0,e).join(" ")}f.push({text:j.trim(),top:a})}}for(const b of a.children)g(b)};if(g(a),c&&a.setAttribute("inert",""),0===f.length)return"";f.sort((c,a)=>c.top-a.top);const h=new Set;let i="";for(const c of f){if(h.has(c.text))continue;let a=!1;for(const b of h)if(b.includes(c.text)||c.text.includes(b)){a=!0;break}a||(h.add(c.text),i+=(i?" ":"")+c.text)}return this.cleanupExcerpt(i)},cleanupExcerpt(a){if(!a)return"";let b=a.replace(/<[^>]*>/g,"");if(b=b.replace(/\s+/g," ").trim(),80<b.length){const a=b.lastIndexOf("."),c=b.lastIndexOf("!"),d=b.lastIndexOf("?"),e=Math.max(a,c,d);40<e&&(b=b.substring(0,e+1))}return b},buildScreenReaderText(a,b){const c=window.kbShowMore||{},d=c.contentCollapsed||"Content is collapsed.",e=c.contentContinues||"Content continues.",f=c.activateButton||"Activate the",g=c.buttonToReveal||"button to reveal the full content.",h=c.showMoreDefault||"Show More",i=b||h;return a&&""!==a.trim()?a+" ... "+e+" "+f+" "+i+" "+g:d+" "+f+" "+i+" "+g},getCurrentMaxHeight(a){const b=a.querySelector(".wp-block-kadence-column.kb-show-more-content");if(!b)return 250;const c=window.getComputedStyle(b),d=c.maxHeight;if("none"===d)return null;const e=d.match(/([\d.]+)(px|em|rem)/);if(!e)return 250;const f=parseFloat(e[1]),g=e[2];if("px"===g)return f;if("em"===g||"rem"===g){const a=parseFloat(window.getComputedStyle(b).fontSize);return f*a}return 250},getFocusableElements(a){if(!a)return[];const b=Array.from(a.querySelectorAll("a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"]), [contenteditable=\"true\"], iframe, object, embed, area[href], audio[controls], video[controls], [role=\"button\"]:not([tabindex=\"-1\"]), [role=\"link\"]:not([tabindex=\"-1\"]), [role=\"menuitem\"]:not([tabindex=\"-1\"]), [role=\"menuitemcheckbox\"]:not([tabindex=\"-1\"]), [role=\"menuitemradio\"]:not([tabindex=\"-1\"]), [role=\"option\"]:not([tabindex=\"-1\"]), [role=\"switch\"]:not([tabindex=\"-1\"]), [role=\"tab\"]:not([tabindex=\"-1\"]), [role=\"textbox\"]:not([tabindex=\"-1\"])"));return b.filter(a=>{const b=window.getComputedStyle(a);if("none"===b.display||"hidden"===b.visibility||"0"===b.opacity)return!1;const c=a.getAttribute("tabindex");return"-1"!==c})},disableTabIndex(a){if(a){const b=this.getFocusableElements(a);b.forEach(a=>{document.activeElement===a&&a.blur();const b=a.getAttribute("tabindex");null===b?a.setAttribute("data-had-no-tabindex","true"):a.setAttribute("data-original-tabindex",b),a.setAttribute("tabindex","-1")})}},restoreTabIndex(a){if(a){const b=a.querySelectorAll("[data-original-tabindex], [data-had-no-tabindex]");b.forEach(a=>{const b=a.getAttribute("data-original-tabindex"),c=a.getAttribute("data-had-no-tabindex");null===b?"true"===c&&(a.removeAttribute("tabindex"),a.removeAttribute("data-had-no-tabindex")):(a.setAttribute("tabindex",b),a.removeAttribute("data-original-tabindex"))})}},updateAccessibility(a,b){const c=a.querySelector(".wp-block-kadence-column.kb-show-more-content");if(!c)return;const d=a.querySelector(".kb-show-more-sr-excerpt"),e=a.querySelector(".wp-block-kadence-advancedbtn.kb-show-more-buttons > .wp-block-kadence-singlebtn:nth-of-type(1)"),f=a.querySelector(".wp-block-kadence-advancedbtn.kb-show-more-buttons > .wp-block-kadence-singlebtn:nth-of-type(2)");let g="Show More";if(e){const a=e.querySel