/** * @file Sets up the event bar javascript. * This file should load after tribe events core and pro js and before any events view javascript. * @version 3.0 */ /** * @global * @desc This global is used in various functions throughout the plugin to determine if the view is being changed. Its value will be set to 'change_view' when true. */ var tribe_events_bar_action; (function( window, document, $, td, te, tf, ts, tt, dbug ) { /* * $ = jQuery * td = tribe_ev.data * te = tribe_ev.events * tf = tribe_ev.fn * ts = tribe_ev.state * tt = tribe_ev.tests * dbug = tribe_debug */ $( document ).ready( function() { // @ifdef DEBUG if ( dbug ) { if ( !$().bootstrapDatepicker ) { debug.warn( 'TEC Debug: vendor bootstrapDatepicker was not loaded before its dependant file tribe-events-bar.js' ); } if ( !$().placeholder ) { debug.warn( 'TEC Debug: vendor placeholder was not loaded before its dependant file tribe-events-bar.js' ); } } // @endif var $tribebar = $( '#tribe-bar-form' ), $tribedate = $( '#tribe-bar-date' ), $tribe_events = $( '#tribe-events' ), $tribe_header = $( '#tribe-events-header' ), start_day = 0, $tribebarselect = $( 'select[name=tribe-bar-view]' ); if ( $tribe_header.length ) { start_day = $tribe_header.data( 'startofweek' ); } /** * @function eventsBarWidth * @desc eventsBarWidth applies responsive css classes to the bar to adjust its layout for smaller screens. * @param {jQuery} $tribebar The event bar jquery object. */ function eventsBarWidth( $tribebar ) { if ( $tribebar.parents( '.tribe-bar-disabled' ).length ) { return; } var tribeBarWidth = $tribebar.width(); if ( tribeBarWidth > 800 ) { $tribebar.removeClass( 'tribe-bar-mini tribe-bar-collapse' ).addClass( 'tribe-bar-full' ); } else { $tribebar.removeClass( 'tribe-bar-full' ).addClass( 'tribe-bar-mini' ); } if ( tribeBarWidth < 728 ) { $tribebar.removeClass( 'tribe-bar-mini' ).addClass( 'tribe-bar-collapse' ); } else { $tribebar.removeClass( 'tribe-bar-collapse' ); } } eventsBarWidth( $tribebar ); $tribebar.resize( function() { eventsBarWidth( $tribebar ); } ); if ( !$( '.tribe-events-week-grid' ).length ) { if ( ts.view !== 'month' ) { // begin display date formatting var date_format = 'yyyy-mm-dd'; if ( ts.datepicker_format !== '0' ) { // we are not using the default query date format, lets grab it from the data array date_format = td.datepicker_formats.main[ts.datepicker_format]; var url_date = tf.get_url_param( 'tribe-bar-date' ); // if url date is set and datepicker format is different from query format // we need to fix the input value to emulate that before kicking in the datepicker if ( url_date ) { $tribedate.val( tribeDateFormat( url_date, ts.datepicker_format ) ); } else if ( ts.view === 'day' && $tribedate.val().length !== 0 ) { $tribedate.val( tribeDateFormat( $tribedate.val(), ts.datepicker_format ) ); } } // @ifdef DEBUG dbug && debug.info( 'TEC Debug: bootstrapDatepicker was just initialized in "tribe-events-bar.js" on:', $tribedate ); // @endif td.datepicker_opts = { weekStart : start_day, format : date_format, autoclose: true }; $tribedate .bootstrapDatepicker( td.datepicker_opts ); } } $tribedate.blur( function() { if ( $tribedate.val() === '' && $( '.datepicker.dropdown-menu' ).is( ':hidden' ) && tt.live_ajax() && tt.pushstate ) { ts.date = td.cur_date; td.cur_url = td.base_url; $( te ).trigger( 'tribe_ev_runAjax' ); } } ); // Add some classes if ( $( '.tribe-bar-settings' ).length ) { $( '#tribe-events-bar' ).addClass( 'tribe-has-settings' ); } if ( $( '#tribe-events-bar .hasDatepicker' ).length ) { $( '#tribe-events-bar' ).addClass( 'tribe-has-datepicker' ); } // Implement views links function format( view ) { return '' + view.text + ''; } // Implement placeholder $( 'input[name*="tribe-bar-"]' ).placeholder(); // Create list $( '