1

I have some issues with a JavaScript portion that I have added to my WordPress footer.php:

<script>
jQuery('.showPosts').on('click', function() {
    if (jQuery(this).hasClass('hidePosts')) {
        jQuery(this).children('div').hide();
        jQuery(this).removeClass('hidePosts');
        jQuery(this).children('.greekCross').html('&#10010;');
    } else {
        jQuery(this).children('div').show();
        jQuery(this).addClass('hidePosts');
        jQuery(this).children('.greekCross').html('&#160;&#10145;');
    }
});
jQuery('.search-field').attr('placeholder','TYPE IN SEARCH TAGS...');
jQuery('.videoText').remove();
jQuery('.ytVideoContainer').addClass('left');
jQuery('.catContainer').addClass('right');
jQuery('.catContainer').addClass('noMarginTop');
var mq = window.matchMedia('(min-width: 767px)');
if (mq.matches) {
    // window width is at least 767px
    jQuery('.relatedVideoThumb').show();
} else {
    jQuery('.postcontentTitle').insertBefore('.catContainer');
    jQuery('.postcontent').insertBefore('.catContainer');
    jQuery('.relatedVideoThumb').hide();
}
var winWidth  = 0;
jQuery(window).resize(function() {
    winWidth = jQuery(window).width();
    if (winWidth < 768) {
        jQuery('.postcontentTitle').insertBefore('.catContainer');
        jQuery('.postcontent').insertBefore('.catContainer');
        jQuery('.relatedVideoThumb').hide();
    } else {
    jQuery('.catContainer').insertBefore('.postcontent');
    jQuery('.catContainer').insertBefore('.postcontentTitle');
    jQuery('.relatedVideoThumb').show();
    }
});
jQuery('.site-header .home-link').css('border', '0');
</script>

Every time I reload the page I receive in the Google Chrome Console the following:

Uncaught SyntaxError: Unexpected end of input

Being minified for optimization purposes I had to look into Firefox Firebug extension to see where exactly is this unexpected end of input. I received the following:

SyntaxError: missing } in compound statement
); }});jQuery('.site-header .home-link').css('border', '0');
------------------------------------------------------------

I don't see where I could had done something wrong, I've more than double check it but I am unable to find the mistake so any guidance or solution is more than welcomed.

3
  • Your script block is correct, the error is somewhere else. Try to remove this <script> block and check in google chrome again... Commented Oct 6, 2014 at 13:18
  • Is that the whole javascript code ? Maybe your code starts with $(document).ready(function(){ .. so the }) is missing. Commented Oct 6, 2014 at 13:18
  • I figure it out eventually. It's because the minify plugin that I use (WP Super Minify) somehow creates the issue. Commented Oct 6, 2014 at 13:24

1 Answer 1

1

SyntaxError: missing } in compound statement

This error message tells you to add a } is missing at this point.

Try to add it.

I suppose you will also have to add ) to complete your javascript code.

Sign up to request clarification or add additional context in comments.

3 Comments

I've tried but it wasn't the fix. Like i've mentioned above, the wordpress plugin that I use to minify the js files creates the issue.
so if the error is related to the minifier, it should be changed. maybe an update exists from wordpress, or the library used.
I've actually reactivated and remove the if statement for mq.matches and for some weird reason the error is gone but the functionality is working like it should.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.