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 Accordion Object in the Global Tribe variable 13 * 14 * @since 4.9.4 15 * 16 * @type {PlainObject} 17 */ 18tribe.events.views.accordion = {}; 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.accordion 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.4 38 * 39 * @type {PlainObject} 40 */ 41 obj.selectors = { 42 accordionTrigger: '[data-js~="tribe-events-accordion-trigger"]', 43 }; 44 45 /** 46 * Sets open accordion accessibility attributes 47 * 48 * @since 4.9.7 49 * 50 * @param {jQuery} $header jQuery object of header 51 * @param {jQuery} $content jQuery object of contents 52 * 53 * @return {void} 54 */ 55 obj.setOpenAccordionA11yAttrs = function( $header, $content ) { 56 $header.attr( 'aria-expanded', 'true' ) 57 $content.attr( 'aria-hidden', 'false' ); 58 }; 59 60 /** 61 * Sets close accordion accessibility attributes 62 * 63 * @since 4.9.7 64 * 65 * @param {jQuery} $header jQuery object of header 66 * @param {jQuery} $content jQuery object of contents 67 * 68 * @return {void} 69 */ 70 obj.setCloseAccordionA11yAttrs = function( $header, $content ) { 71 $header.attr( 'aria-expanded', 'false' ) 72 $content.attr( 'aria-hidden', 'true' ); 73 }; 74 75 /** 76 * Closes all accordions in $container 77 * 78 * @since 4.9.4 79 * 80 * @param {jQuery} $container jQuery object of view container 81 * 82 * @return {void} 83 */ 84 obj.closeAllAccordions = function( $container ) { 85 $container.find( obj.selectors.accordionTrigger ).each( function( index, header ) { 86 var $header = $( header ); 87 var contentId = $header.attr( 'aria-controls' ); 88 var $content = $document.find( '#' + contentId ); 89 90 obj.closeAccordion( $header, $content ); 91 } ); 92 }; 93 94 /** 95 * Opens accordion 96 * 97 * @since 4.9.7 98 * 99 * @param {jQuery} $header jQuery object of header 100 * @param {jQuery} $content jQuery object of contents 101 * 102 * @return {void} 103 */ 104 obj.openAccordion = function( $header, $content ) { 105 obj.setOpenAccordionA11yAttrs( $header, $content ); 106 $content.css( 'display', 'block' ); 107 }; 108 109 /** 110 * Closes accordion 111 * 112 * @since 4.9.7 113 * 114 * @param {jQuery} $header jQuery object of header 115 * @param {jQuery} $content jQuery object of contents 116 * 117 * @return {void} 118 */ 119 obj.closeAccordion = function( $header, $content ) { 120 obj.setCloseAccordionA11yAttrs( $header, $content ); 121 $content.css( 'display', '' ); 122 }; 123 124 /** 125 * Toggles accordion on header click 126 * 127 * @since 4.9.4 128 * 129 * @param {Event} event event object of click event 130 * 131 * @return {void} 132 */ 133 obj.toggleAccordion = function( event ) { 134 var $container = event.data.container; 135 var $header = $( event.data.target ); 136 var contentId = $header.attr( 'aria-controls' ); 137 var $content = $container.find( '#' + contentId ); 138 139 if ( 'true' === $header.attr( 'aria-expanded' ) ) { 140 obj.closeAccordion( $header, $content ); 141 } else { 142 obj.openAccordion( $header, $content ); 143 } 144 }; 145 146 /** 147 * Deinitializes accordion accessibility attributes 148 * 149 * @since 4.9.7 150 * 151 * @param {jQuery} $header jQuery object of header 152 * @param {jQuery} $content jQuery object of contents 153 * 154 * @return {void} 155 */ 156 obj.deinitAccordionA11yAttrs = function( $header, $content ) { 157 $header 158 .removeAttr( 'aria-expanded' ) 159 .removeAttr( 'aria-controls' ); 160 $content.removeAttr( 'aria-hidden' ); 161 }; 162 163 /** 164 * Initializes accordion accessibility attributes 165 * 166 * @since 4.9.7 167 * 168 * @param {jQuery} $header jQuery object of header 169 * @param {jQuery} $content jQuery object of contents 170 * 171 * @return {void} 172 */ 173 obj.initAccordionA11yAttrs = function( $header, $content ) { 174 $header 175 .attr( 'aria-expanded', 'false' ) 176 .attr( 'aria-controls', $content.attr( 'id' ) ); 177 $content.attr( 'aria-hidden', 'true' ); 178 }; 179 180 /** 181 * Deinitializes accordion 182 * 183 * @since 4.9.4 184 * 185 * @param {integer} index jQuery.each index param 186 * @param {HTMLElement} header header element from which to remove event 187 * 188 * @return {void} 189 */ 190 obj.deinitAccordion = function( index, header ) { 191 $( header ).off( 'click', obj.toggleAccordion ); 192 }; 193 194 /** 195 * Curry function to initialize accordion 196 * Used to pass in `$container` 197 * 198 * @since 4.9.4 199 * 200 * @param {jQuery} $container jQuery object of view container 201 * 202 * @return {function} function to add event listener to header 203 */ 204 obj.initAccordion = function( $container ) { 205 /** 206 * Initializes accordion 207 * 208 * @since 4.9.4 209 * 210 * @param {integer} index jQuery.each index param 211 * @param {HTMLElement} header header element from which to remove event 212 * 213 * @return {void} 214 */ 215 return function( index, header ) { 216 $( header ).on( 'click', { target: header, container: $container }, obj.toggleAccordion ); 217 }; 218 }; 219 220 /** 221 * Unbinds events for accordion click listeners 222 * 223 * @since 4.9.5 224 * 225 * @param {jQuery} $container jQuery object of view container 226 * 227 * @return {void} 228 */ 229 obj.unbindAccordionEvents = function( $container ) { 230 $container 231 .find( obj.selectors.accordionTrigger ) 232 .each( obj.deinitAccordion ); 233 }; 234 235 /** 236 * Binds events for accordion click listeners 237 * 238 * @since 4.9.4 239 * 240 * @param {jQuery} $container jQuery object of view container 241 * 242 * @return {void} 243 */ 244 obj.bindAccordionEvents = function( $container ) { 245 $container 246 .find( obj.selectors.accordionTrigger ) 247 .each( obj.initAccordion( $container ) ); 248 }; 249 250 /** 251 * Unbinds events for container 252 * 253 * @since 4.9.5 254 * 255 * @param {Event} event event object for 'beforeAjaxSuccess.tribeEvents' event 256 * @param {jqXHR} jqXHR Request object 257 * @param {PlainObject} settings Settings that this request was made with 258 * 259 * @return {void} 260 */ 261 obj.unbindEvents = function( event, jqXHR, settings ) { 262 var $container = event.data.container; 263 obj.unbindAccordionEvents( $container ); 264 $container.off( 'beforeAjaxSuccess.tribeEvents', obj.unbindEvents ); 265 }; 266 267 /** 268 * Binds events for container 269 * 270 * @since 4.9.5 271 * 272 * @param {Event} event event object for 'afterSetup.tribeEvents' event 273 * @param {integer} index jQuery.each index param from 'afterSetup.tribeEvents' event 274 * @param {jQuery} $container jQuery object of view container 275 * @param {object} data data object passed from 'afterSetup.tribeEvents' event 276 * 277 * @return {void} 278 */ 279 obj.bindEvents = function( event, index, $container, data ) { 280 obj.bindAccordionEvents( $container ); 281 $container.on( 'beforeAjaxSuccess.tribeEvents', { container: $container }, obj.unbindEvents ); 282 }; 283 284 /** 285 * Handles the initialization of the accordions when Document is ready 286 * 287 * @since 4.9.4 288 * 289 * @return {void} 290 */ 291 obj.ready = function() { 292 if ( ! tribe.events.views.manager ) { 293 // The script might be used outside of the Views v2 context, if that is the case, skip the auto-binding. 294 return; 295 } 296 297 $document.on( 'afterSetup.tribeEvents', tribe.events.views.manager.selectors.container, obj.bindEvents ); 298 }; 299 300 // Configure on document ready 301 $( obj.ready ); 302} )( jQuery, tribe.events.views.accordion );
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.