WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Events Manager] Calendar Function - AJAX function or Classes help (4 posts)

  1. Mr Brainz
    Member
    Posted 2 years ago #

    How you doing?

    I'm using the beautiful Events Manager plugin to display a calendar of upcoming events. I want to be able to highlight each category with a different colour on the calendar.

    I tried to add categories as a class in the template but EM only outputs them as an unordered list.

    My workaround was to populate a hidden DIV with the categories and use jQuery to generate classes off the back of that.

    Template:

    <li><a href="#_EVENTURL"><span>#_24HSTARTTIME</span> <strong>#_NAME</strong></a> <div class="eventcats">#_EVENTCATEGORIES</div></li>

    jQuery:

    if ( $j('.em-calendar-wrapper').length ) {
    	$j('.eventful > ul li, .eventful-today > ul li').each( function() {
    		var cats = '';
    		$j(this).find('.eventcats ul li').each( function() {
    			catit = $j(this).find('a').text();
    			cats = cats + catit.toLowerCase().replace(/ /g, '-') + ' ';
    		});
    		cats = $j.trim(cats);
    		$j(this).addClass(cats);
    	});
    }

    This works, but the problem is that when you change month then the calendar updates with AJAX, and as the above jQuery is running on (document).load then it resets when the month is changed.

    So my question is: Can I pass my function into the AJAX on change somewhere, or better still, is there a way to add clean classes based on categories into the calendar item template?

    I know you guys that run EM love taking on board suggestions so I thought I'd post here and try my luck.

    Hope someone can help.

    Greg

  2. Mr Brainz
    Member
    Posted 2 years ago #

    Ok I've managed to hack my function into the events-manager.js file and it works, but this is obviously very bad practice as it will break when the plugin updates.

    So any suggestions on another way to do this would be awesome like awesome sauce.

    Thanks,

    Greg

  3. Marcus
    NetWebLogic Support
    Posted 2 years ago #

    actually, an event is triggered -

    $(this).trigger('em_calendar_load')

    you can just bind to that in jquery

  4. Mr Brainz
    Member
    Posted 2 years ago #

    Thanks so much for your help Marcus. I'd never binded a function to an event before so I had to do some Googling.

    Came up with

    $j(document).bind('em_calendar_load', function() { calColours(); });

    Worked like a charm.

    Still think that there's room for a way to add classes for even categories though. It will help with styling and therefore usability.

    Cheers

Topic Closed

This topic has been closed to new replies.

About this Topic