Calendar widget: How to change category filters without reloading (using ajax)

WordPress Event Management, Calendars & Registration Forums Pre Sales Questions Calendar widget: How to change category filters without reloading (using ajax)

This topic contains 4 replies, has 2 voices, and was last updated by  Stephen Harris 6 years, 1 month ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #30021 Reply

    Hi, I need to combine a calendar widget with a list of categories the user can activate/deactivate. This should be possible without reloading the page. The calendar widget already does ajax calls for the “previous month” and “next month” links. The category filter list should behave in the same way.

    I took a look at frontend.js. Can I overwrite or extend the default functionality in any way? Everytime the user adds or removes a category, the calendar should be reloaded with an ajax call, so that the new categories can be applied to the calendar widget shortcode.

    Another small thing I would like to add would be to highlight the day of the currently active archive page in the widget (if the widget is embedded on a archive/month/day page and the month of the selected day is currently visible). Should I add this as a feature request to Github? Or is there any workaround to add this? I could add this with a custom javascript file, but the problem is that the user can reload the calendar with ajax, and then the changes would have to be re-applied.

    Christian Voigt
    #30031 Reply

    The plug-in uses client side ‘hooks’, so you can do this with a bit of javascript (loaded separately, but will need to be after the plug-in scripts):

    wp.hooks.addFilter( 'eventorganiser.fullcalendar_render_event', function( bool, event, element, view ){
    
       //if event should be hidden return false
       //if event should be visible return true
       //if you want to leave the event visibility unchanged return bool;
    
       //event will contain the event categories.
    
       return bool;
    }, 4 );
    

    That hook will filter which events are visible on the calendar, so can remove those which aren’t in the desired categories.

    When a user changes which categories are selected you’ll want to reload the calendar:

    $('.eo-fullcalendar').fullcalendar('rerenderEvents');
    
    Stephen Harris
    #30090 Reply

    I just found out that you already answered my question (I expected to get notified by mail from this forum, but did not receive a notification).

    Thank you for your help! The client side hooks are what I was looking for.

    Christian Voigt
    #30093 Reply

    Ok, I looked into the client side hooks. You were talking about the full calendar, not the widget calendar, right?

    In my code the filter is not called for the widget calendar. If I understand frontend.js right, clicking on “next month” will simply use $.getJson’s callback to change the widget’s content without applying any filters.

    Is there any other way to add this functionality for the widget calendar?

    Christian Voigt
    #30132 Reply

    Hi Christian,

    Yes that’s for the fullcalendar, unfortunately there are no plans to add hooks for the widget calendar.

    Stephen Harris
Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: Calendar widget: How to change category filters without reloading (using ajax)
Your information:




To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax


<a href="" title="" rel=""> <blockquote cite=""> <code> <pre> <em> <strong> <del datetime=""> <ul> <ol start=""> <li> <img src="" border="" alt="" height="" width=""> <p style=""> <span style="">