eventespresso / ee4-events-calendar

Event Espresso Calendar addon (for EE4+)
0 stars 3 forks source link

Add a check for eeCal before using it. #5

Closed Pebblo closed 6 years ago

Pebblo commented 6 years ago

Issue Overview

From time to time we run into issues with the calendar and page builders where the calendar scripts aren't loading on the page.

We usually provide a snippet that loads the scripts on specific pages, but then that means they need to update that snippet if they add additional pages. If we load the calendar scripts on all pages to work around that then you'll get a JS error on any page that doesn't use the calendar shortcode:

http://take.ms/IUVzg

espresso_calendar.js?ver=3.2.12.p:55 Uncaught ReferenceError: eeCAL is not defined
    at HTMLDocument.<anonymous> (espresso_calendar.js?ver=3.2.12.p:55)
    at i (jquery.js?ver=1.12.4:2)
    at Object.fireWith [as resolveWith] (jquery.js?ver=1.12.4:2)
    at Function.ready (jquery.js?ver=1.12.4:2)
    at HTMLDocument.K (jquery.js?ver=1.12.4:2)
## Bug report or feature request?

Steps to Reproduce (for bugs)

Add this snippet to your site: https://gist.github.com/joshfeck/5d9c88fea504c0b111c3df8f24ad25d9

Remove the && is_page( 'calendar' ) from line 7 and visit any page that doesn't use the calendar shortcode.

The fix for the above is to add a check for eeCAL in espresso_calendar.js, whilst not ideal it prevents the error and doesn't cause any other issues.