This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: is there any way to hide the results' scrollbar for desktop view, but make it vi

Home Forums Product Support Forums Ajax Search Pro for WordPress Support is there any way to hide the results' scrollbar for desktop view, but make it vi Reply To: is there any way to hide the results' scrollbar for desktop view, but make it vi

#41082
kyriankyrian
Participant

Thanks, I guess it’s a just a cache issue then!

Since I am here…

I want to run the below code on the search results to truncate the characters depending on the user screen size.
I have inserted the code via Oxygen above the results shortcode and it works so and so… it does truncate the texts but with a certain delay.
See https://accademiainfinita.it/2/meditazioni-guidate/

Do you think the only way to make this work is to put the code directly in the plugin file?

I know I am asking questions that are beyond the scope of support btw, just say the word and I’ll shut up 🙂

window.addEventListener("resize", truncateCharacters);

const query1 = window.matchMedia("(min-width: 480px) and (max-width: 991px)");
const query2 = window.matchMedia("(max-width: 479px)");

function truncateCharacters() {
    if (query1.matches) {
        const titles = document.querySelectorAll('.asp_res_url , .asp_res_text');
        for(let title of titles){
            if (title.innerText.length > 100) {
                title.innerText = title.innerText.slice(0,100) + "...";
            }
        }
    } else if (query2.matches) {
        const titles = document.querySelectorAll('.asp_res_url , .asp_res_text');
        for(let title of titles){
            if (title.innerText.length > 50) {
                title.innerText = title.innerText.slice(0,50) + "...";
            }
        }
    }
}

truncateCharacters();

query1.addListener(truncateCharacters);
query2.addListener(truncateCharacters);