Gravatar for simon.byrne@ifsworld.com

Question by simonbyrne, Dec 5, 2014 1:26 PM

jQuery events not being called on initial page load (Coveo for Sitecore)

Hi,

I just spoke to Simon at US/Canada support and he suggested I post this question here.

I am trying to set some CSS on page elements after the initial page load using the jQuery event methods. I have tried almost every event listed here. I'm getting it to work just fine after you have changed the values in the facets. But I have to make changes to the facets in order for the CSS to be applied. It doesn't work on the initial page load/search results. I'm hoping somebody may be able to point me in the right direction?

My code is currently:

Coveo.$('#search').on('deferredQuerySuccess', function(){
    var resultsHeight = $('div.wrapper').height();
    $('.CoveoFacet ul.coveo-values').each(function () {
        var facetHeight = $(this).height();
        if (facetHeight > resultsHeight) {
            var minHeight = facetHeight;
            $('div.wrapper').css("min-height", minHeight);
        }
    });
});
2 Replies
Gravatar for simon.byrne@ifsworld.com

Answer by simonbyrne, Dec 5, 2014 2:15 PM

OK, I think I managed to figure this out for myself with a little help from some good old fashioned console logging. :-) I think the problem was in my jQuery, and that I needed to reset the min-height first before going through the each loop (see line 2 below). It seems very odd that this would have any effect on the initial load state, but it appears to be working now. I leave my own solution here in case this helps anybody else:

Coveo.$('#search').on('deferredQuerySuccess', function(){
        $('div.wrapper').css("min-height", "");
        var resultsHeight = $('div.wrapper').height();
        $('.CoveoFacet ul.coveo-values').each(function () {
            var facetHeight = $(this).height();
            if (facetHeight > resultsHeight) {
                var minHeight = facetHeight;
                $('div.wrapper').css("min-height", minHeight);
            }
        });
    });
Gravatar for vseguin@coveo.com

Answer by Vincent Séguin, Dec 5, 2014 2:11 PM

Hi Simon,

Where exactly are you putting this code? Can you show us the full snippet of your layout file?

Gravatar for simon.byrne@ifsworld.com

Comment by simonbyrne, Dec 5, 2014 2:17 PM

Thank you, Vincent, for your quick reply. As you will see below, I figured this out for myself!

Ask a question