Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatibility with Apache module PageSpeed: Uncaught Error: The item should not be image type #8

Open
emibcn opened this issue May 18, 2018 · 0 comments

Comments

@emibcn
Copy link

emibcn commented May 18, 2018

Hello there!
I've been struggling for over 2 days until I saw PageSpeed adding code to the HTML code (I'm debugging a Plesk server not administrated by myself). PageSpeed adds code to the HTML page that uses the img.onload event to ensure image is loaded and probably other stuff. It breaks Unite Gallery making it raise the infamous Uncaught Error: The item should not be image type. I don't think UniteGallery should do a correction, but it could be done.

I've found that the problem is raised in a race condition, when the gallery constructor is called before all images are completely loaded. To avoid this race condition (as a workaround), I call the gallery constructor after all images are 100% loaded:

(function() {
    
    var code = "#gallery_{{ gallery.pk }}",
        imgs = $(code + ' img'),
        len = imgs.length,
        counter = 0;

    $(code).on("imgready", function() {
        var options = {};
        {% if gallery.options %}jQuery.extend(options, {{ gallery.options|safe }});{% endif %}
        $(code).unitegallery(options);
    });

    function incrementCounter() {
        counter++;
        if ( counter === len ) {
            console.log( 'All images loaded!' );
            $(code).trigger("imgready");
        }
    }
    
    [].forEach.call( imgs, function( img ) {
        if(img.complete) {
            incrementCounter();
        }
        else {
            img.addEventListener( 'load', incrementCounter, false );
        }
    } );

})();

Hope it helps to others having this issue.

Edit: Found a link of people with same issue: https://valiano.ticksy.com/ticket/706985

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant