1/** 2 * Makes sure we have all the required levels on the Tribe Object 3 * 4 * @since 4.9.4 5 * 6 * @type {PlainObject} 7 */ 8tribe.events = tribe.events || {}; 9tribe.events.views = tribe.events.views || {}; 10 11/** 12 * Configures Multiday Events Object in the Global Tribe variable 13 * 14 * @since 4.9.4 15 * 16 * @type {PlainObject} 17 */ 18tribe.events.views.multidayEvents = {}; 19 20/** 21 * Initializes in a Strict env the code that manages the Event Views 22 * 23 * @since 4.9.4 24 * 25 * @param {PlainObject} $ jQuery 26 * @param {PlainObject} obj tribe.events.views.multidayEvents 27 * 28 * @return {void} 29 */ 30( function( $, obj ) { 31 'use strict'; 32 var $document = $( document ); 33 34 /** 35 * Selectors used for configuration and setup 36 * 37 * @since 4.9.5 38 * 39 * @type {PlainObject} 40 */ 41 obj.selectors = {}; 42 43 /** 44 * Selector prefixes used for creating selectors 45 * 46 * @since 4.9.5 47 * 48 * @type {PlainObject} 49 */ 50 obj.selectorPrefixes = { 51 month: '.tribe-events-calendar-month__', 52 }; 53 54 /** 55 * Selector suffixes used for creating selectors 56 * 57 * @since 4.9.5 58 * 59 * @type {PlainObject} 60 */ 61 obj.selectorSuffixes = { 62 multidayEvent: 'multiday-event', 63 hiddenMultidayEvent: 'multiday-event-hidden', 64 multidayEventBarInner: 'multiday-event-bar-inner', 65 multidayEventBarInnerFocus: 'multiday-event-bar-inner--focus', 66 multidayEventBarInnerHover: 'multiday-event-bar-inner--hover', 67 }; 68 69 /** 70 * Find visible multiday event that relates to the hidden multiday event 71 * 72 * @since 4.9.5 73 * 74 * @param {jQuery} $container jQuery object of view container. 75 * @param {jQuery} $hiddenMultidayEvent jQuery object of hidden multiday event 76 * 77 * @return {jQuery} jQuery object of visible multiday event or false if none found 78 */ 79 obj.findVisibleMultidayEvents = function( $container, $hiddenMultidayEvent ) { 80 var eventId = $hiddenMultidayEvent.closest( obj.selectors.multidayEvent ).data( 'event-id' ); 81 82 return $container 83 .find( obj.selectors.multidayEvent + '[data-event-id=' + eventId + ']' ) 84 }; 85 86 /** 87 * Toggle hover class on visible multiday event when hidden multiday triggers hover event 88 * 89 * @since 4.9.4 90 * 91 * @param {Event} event event object 92 * 93 * @return {void} 94 */ 95 obj.toggleHoverClass = function( event ) { 96 event.data.target.toggleClass( obj.selectors.multidayEventBarInnerHover.className() ); 97 }; 98 99 /** 100 * Toggle focus class on visible multiday event when hidden multiday triggers focus event 101 * 102 * @since 4.9.4 103 * 104 * @param {Event} event event object 105 * 106 * @return {void} 107 */ 108 obj.toggleFocusClass = function( event ) { 109 event.data.target.toggleClass( obj.selectors.multidayEventBarInnerFocus.className() ); 110 }; 111 112 /** 113 * Unbinds events for hover and focus of hidden multiday events. 114 * 115 * @since 4.9.5 116 * 117 * @param {jQuery} $container jQuery object of view container. 118 * 119 * @return {void} 120 */ 121 obj.unbindMultidayEvents = function( $container ) { 122 var $hiddenMultidayEvents = $container.find( obj.selectors.hiddenMultidayEvent ); 123 124 $hiddenMultidayEvents.each( function( hiddenIndex, hiddenMultidayEvent ) { 125 $( hiddenMultidayEvent ).off(); 126 } ); 127 }; 128 129 /** 130 * Binds events for hover and focus of hidden multiday events. 131 * 132 * @since 4.9.4 133 * 134 * @param {jQuery} $container jQuery object of view container. 135 * 136 * @return {void} 137 */ 138 obj.bindMultidayEvents = function( $container ) { 139 var $hiddenMultidayEvents = $container.find( obj.selectors.hiddenMultidayEvent ); 140 141 $hiddenMultidayEvents.each( function( hiddenIndex, hiddenMultidayEvent ) { 142 var $hiddenMultidayEvent = $( hiddenMultidayEvent ); 143 var $visibleMultidayEvents = obj.findVisibleMultidayEvents( $container, $hiddenMultidayEvent ); 144 145 $visibleMultidayEvents.each( function( visibleIndex, visibleMultidayEvent ) { 146 var $visibleMultidayEvent = $( visibleMultidayEvent ); 147 var $visiblemultidayEventBarInner = $visibleMultidayEvent.find( obj.selectors.multidayEventBarInner ); 148 149 $hiddenMultidayEvent 150 .on( 'mouseenter mouseleave', { target: $visiblemultidayEventBarInner }, obj.toggleHoverClass ) 151 .on( 'focus blur', { target: $visiblemultidayEventBarInner }, obj.toggleFocusClass ); 152 } ); 153 } ); 154 }; 155 156 /** 157 * Resets selectors to empty object 158 * 159 * @since 4.9.5 160 * 161 * @return {void} 162 */ 163 obj.deinitSelectors = function() { 164 obj.selectors = {}; 165 }; 166 167 /** 168 * Initializes selectors based on view slug 169 * 170 * @since 4.9.5 171 * 172 * @param {string} viewSlug slug of view 173 * 174 * @return {void} 175 */ 176 obj.initSelectors = function( viewSlug ) { 177 var selectorPrefix = obj.selectorPrefixes[ viewSlug ]; 178 179 Object 180 .keys( obj.selectorSuffixes ) 181 .forEach( function( key ) { 182 obj.selectors[ key ] = selectorPrefix + obj.selectorSuffixes[ key ]; 183 } ); 184 }; 185 186 /** 187 * Unbinds events for container. 188 * 189 * @since 4.9.5 190 * 191 * @param {Event} event event object for 'beforeAjaxSuccess.tribeEvents' event 192 * @param {jqXHR} jqXHR Request object 193 * @param {PlainObject} settings Settings that this request was made with 194 * 195 * @return {void} 196 */ 197 obj.unbindEvents = function( event, jqXHR, settings ) { 198 var $container = event.data.container; 199 obj.deinitSelectors(); 200 obj.unbindMultidayEvents( $container ); 201 $container.off( 'beforeAjaxSuccess.tribeEvents', obj.unbindEvents ); 202 }; 203 204 /** 205 * Binds events for container. 206 * 207 * @since 4.9.9 208 * 209 * @param {jQuery} $container jQuery object of view container. 210 * @param {object} data data object passed from 'afterSetup.tribeEvents' event. 211 * 212 * @return {void} 213 */ 214 obj.bindEvents = function( $container, data ) { 215 var viewSlug = data.slug; 216 var allowedViews = $container.data( 'tribeEventsMultidayEventsAllowedViews' ); 217 218 if ( -1 === allowedViews.indexOf( viewSlug ) ) { 219 return; 220 } 221 222 obj.initSelectors( viewSlug ); 223 obj.bindMultidayEvents( $container ); 224 $container.on( 'beforeAjaxSuccess.tribeEvents', { container: $container }, obj.unbindEvents ); 225 }; 226 227 /** 228 * Initialize allowed views 229 * 230 * @since 4.9.9 231 * 232 * @param {jQuery} $container jQuery object of view container. 233 * 234 * @return {void} 235 */ 236 obj.initAllowedViews = function( $container ) { 237 $container.trigger( 'beforeMultidayEventsInitAllowedViews.tribeEvents', [ $container ] ); 238 239 var theme = [ 'month' ]; 240 $container.data( 'tribeEventsMultidayEventsAllowedViews', theme ); 241 242 $container.trigger( 'afterMultidayEventsInitAllowedViews.tribeEvents', [ $container ] ); 243 }; 244 245 /** 246 * Initialize multiday events. 247 * 248 * @since 4.9.9 249 * 250 * @param {Event} event event object for 'afterSetup.tribeEvents' event 251 * @param {integer} index jQuery.each index param from 'afterSetup.tribeEvents' event. 252 * @param {jQuery} $container jQuery object of view container. 253 * @param {object} data data object passed from 'afterSetup.tribeEvents' event. 254 * 255 * @return {void} 256 */ 257 obj.init = function( event, index, $container, data ) { 258 obj.initAllowedViews( $container ); 259 obj.bindEvents( $container, data ); 260 }; 261 262 /** 263 * Handles the initialization of multiday events when Document is ready 264 * 265 * @since 4.9.4 266 * 267 * @return {void} 268 */ 269 obj.ready = function() { 270 $document.on( 'afterSetup.tribeEvents', tribe.events.views.manager.selectors.container, obj.init ); 271 }; 272 273 // Configure on document ready 274 $( obj.ready ); 275} )( jQuery, tribe.events.views.multidayEvents );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.