I am registering custom event handlers using .on() in $(document).ready() but they are not being triggered.
I have verified in both Chrome and Firefox that
- The events are being registered to the correct elements,
- The handler is working correctly,
- The even is being triggered on the correct elements
I've also registered the same handler under a built-in event (e.g. click) and everything works perfectly.
I tried to create a minimum working example, but haven't been able to replicate this behavior.
Of Relevance
- Everything works in jQuery 1.12.4, but not in 3.2.1
- The code is being run as part of a custom WordPress 4.9.1 plugin
- Test Page
- Full Code
- The custom event is named eor:date-change
- The event is registered and triggered on .eor-calendar elements
- The basic logic flow is a user clicks on a navigation button ( .eor-nav ) which sets the date on the calendar ( .eor-calendar ) via the data-current-date attribute. The eor:date-change event is then triggered which updates the dates on the calendar, and triggers an eor:appointment-change event on each of the appointments. The appointments then update their data accordingly.
Relevant Code
$( document ).ready( function( ) {
$( '.eor-calendar' ).on( 'eor:date-change', function() {
eor_updateCalendarToCurrentDate( $( this ) );
} );
} );
function eor_setCalendarDate( date, calendar, timezone ) {
var $ = $ || jQuery;
if( ! ( date instanceof Date ) ) {
date = new Date( date );
}
if( ! calendar ) {
calendar = $( '.eor-calendars-wrapper .eor-calendar' );
}
calendar.each( function() {
var self = $( this );
var startDate = eor_stringToDate( self.data( 'start-date' ), timezone );
var endDate = ( self.data( 'end-date' ) ? eor_stringToDate( self.data( 'end-date' ), timezone ) : undefined );
if( startDate <= date ) {
if( ! endDate || date <= endDate ) {
// set date
var dateString = eor_dateToString( date );
self.attr( 'data-current-date', dateString );
self.data( 'current-date', dateString );
// trigger event to update calendar
self.trigger( 'eor:date-change' );
}
}
} );
}
Update 1 When checking the jQuery version ($.fn.jquery) I get
3.2.1 -ajax,-ajax/jsonp,-ajax/load,-ajax/parseXML,-ajax/script,-ajax/var/location,-ajax/var/nonce,-ajax/var/rquery,-ajax/xhr,-manipulation/_evalUrl,-event/ajax,-effects,-effects/Tween,-effects/animatedSelector
Perhaps the functionality I need has been removed by WordPress. If this is the case how can I include it?