Event Calendar widget filters causing Javascript errors

Home Forums Calendar Products Events Calendar PRO Event Calendar widget filters causing Javascript errors

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #133100
    timwakeling
    Participant

    Hi – I have a problem with the Events Calendar Pro 3.5.1 when used in conjunction with the Page Widgets plugin (this one: http://wordpress.org/plugins/wp-page-widget/). I added an “Event Categories” widget and its “Add filter” dropdown is just an ordinary select box rather than the fancy one that comes up when I place the widget in a main widget area. The selection is also not saved when the widget is saved. As a clue to why, I get several errors in my console, centering on this bit of the code in widget-calendar.php:

    setTimeout( function () {
    jQuery( “select.calendar-widget-add-filter:not(#widget-tribe-mini-calendar-__i__-selector)” ).select2();
    calendar_toggle_all();
    }, 600 );

    The console reports that “undefined is not a function” after the line calling select2(). Commenting out this line produces an error on calendar_toggle_all(). These are the only errors in the console, and I checked that JS was running fine up to that line. Hence I’m coming to you first rather than the Page Widgets developer (it doesn’t seem as if his code is breaking the JS), though he’ll be my next port of call.

    Have you heard of this issue before? Any thoughts? It’d be much appreciated!

    #133473
    Barry
    Member

    I’m not sure how much we’re going to be able to help here, unfortunately. It looks like that plugin effectively embeds the widget admin screen within the post editor – but correct me if I’m wrong there – and it may well be the case that we don’t add certain scripts in that situation that our widgets will nonetheless expect to be present when their settings UI is exposed.

    So while I appreciate you coming to us and can see why it might look like our code is breaking here, which I guess it is, that’s really only because it’s being pulled into a place where it doesn’t expect to find itself (and that wouldn’t happen in the normal course of events).

    That said, if you talk to the developer or team behind WP Page Widget and they can point to something we’re doing that’s clearly contrary to WordPress best practices we’ll definitely make ourselves open to their feedback.

    Thanks – and I hope you figure out a way to integrate the two nicely 🙂

    #144395
    timwakeling
    Participant

    Hi – thanks for your response. You are right of course that it’s not directly your fault! But I thought I’d share with you the answer that I eventually found, in case you want to adjust your plugin to be compatible with Page Widgets.

    Quite simply, the appropriate scripts are only being loaded on “widgets.php”, and Page Widgets needs to use them on “post.php”. To make this work as desired, I just modified line 18 of /events-calendar-pro/lib/widget-calendar.class.php from

    if ( $hook != ‘widgets.php’ )

    to

    if ( $hook != ‘widgets.php’ && $hook != ‘post.php’ )

    Now everything works. I realise that if you were to implement this you’d want to either detect the Page Widgets plugin and add this line if it is found (so as not to load the scripts needlessly), or alternatively add a tick box in your options along the lines of “Enable Page Widgets compability”, which would add this bit.

    I doubt I’m the only user of this very handy page widgets plugin… 🙂

    Anyway, I’ll leave it with you!

    PS. Actually, I’ve changed my implementation to run your script loaders from my functions.php when post.php is detected, so that I can update your plugin later and not break things, but the above would be a clue to how you could do it your end if you wanted to.

    #144457
    Barry
    Member

    Thanks for sharing!

    Definitely feel free to post on our UserVoice page if you want to propose a change/new setting to accommodate this. At this time certainly it’s going to have to be something users implement by adding a snippet to their theme’s functions.php file (or a similar approach), but it’s not impossible we’d roll something into a future release of the plugin 🙂

    Cheers 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Event Calendar widget filters causing Javascript errors’ is closed to new replies.