1/** 2 * Makes sure we have all the required levels on the Tribe Object. 3 * 4 * @since 5.0.0 5 * 6 * @type {PlainObject} 7 */ 8tribe.filterBar = tribe.filterBar || {}; 9 10/** 11 * Configures Filter Checkboxes Object in the Global Tribe variable. 12 * 13 * @since 5.0.0 14 * 15 * @type {PlainObject} 16 */ 17tribe.filterBar.filterCheckboxes = {}; 18 19/** 20 * Initializes in a Strict env the code that manages the filter checkboxes. 21 * 22 * @since 5.0.0 23 * 24 * @param {PlainObject} $ jQuery 25 * @param {PlainObject} obj tribe.filterBar.filterCheckboxes 26 * 27 * @return {void} 28 */ 29( function( $, obj ) { 30 'use strict'; 31 var $document = $( document ); 32 33 /** 34 * Selectors used for configuration and setup. 35 * 36 * @since 5.0.0 37 * 38 * @type {PlainObject} 39 */ 40 obj.selectors = { 41 checkbox: '[data-js="tribe-filter-bar-c-checkbox-input"]', 42 }; 43 44 /** 45 * Handle checkbox change event. 46 * 47 * @since 5.0.0 48 * 49 * @param {Event} event event object of change event. 50 * 51 * @return {void} 52 */ 53 obj.handleCheckboxChange = function( event ) { 54 console.log('asdas') 55 var key = event.target.name; 56 var value = event.target.value; 57 console.log('key is: ', key) 58 console.log('value is: ', value) 59 if ( ! key || ! value ) { 60 return; 61 } 62 63 var urlObject = tribe.filterBar.filters.getCurrentUrlAsObject( event.data.container ); 64 65 console.log('urlObject: -->', urlObject) 66 67 var location = event.target.checked 68 ? tribe.filterBar.filters.addKeyValueToQuery( urlObject, key, value ) 69 : tribe.filterBar.filters.removeKeyValueFromQuery( urlObject, key, value ); 70 71 tribe.filterBar.filters.submitRequest( event.data.container, location.href ); 72 }; 73 74 /** 75 * Unbind events for filter checkboxes functionality. 76 * 77 * @since 5.0.0 78 * 79 * @param {jQuery} $container jQuery object of view container. 80 * 81 * @return {void} 82 */ 83 obj.unbindEvents = function( $container ) { 84 $container.find( obj.selectors.checkbox ).off(); 85 }; 86 87 /** 88 * Bind events for filter checkboxes functionality. 89 * 90 * @since 5.0.0 91 * 92 * @param {jQuery} $container jQuery object of view container. 93 * 94 * @return {void} 95 */ 96 obj.bindEvents = function( $container ) { 97 $container 98 .find( obj.selectors.checkbox ) 99 .each( function( index, checkbox ) { 100 $( checkbox ).on( 'change', { container: $container }, obj.handleCheckboxChange ); 101 } ); 102 }; 103 104 /** 105 * Deinitialize filter checkboxes JS. 106 * 107 * @since 5.0.0 108 * 109 * @param {Event} event event object for 'beforeAjaxSuccess.tribeEvents' event. 110 * 111 * @return {void} 112 */ 113 obj.deinit = function( event ) { 114 var $container = event.data.container; 115 obj.unbindEvents( $container ); 116 $container.off( 'beforeAjaxSuccess.tribeEvents', obj.deinit ); 117 }; 118 119 /** 120 * Initialize filter checkboxes JS. 121 * 122 * @since 5.0.0 123 * 124 * @param {Event} event event object for 'afterSetup.tribeEvents' event. 125 * @param {integer} index jQuery.each index param from 'afterSetup.tribeEvents' event. 126 * @param {jQuery} $container jQuery object of view container. 127 * 128 * @return {void} 129 */ 130 obj.init = function( event, index, $container ) { 131 obj.bindEvents( $container ); 132 $container.on( 'beforeAjaxSuccess.tribeEvents', { container: $container }, obj.deinit ); 133 }; 134 135 /** 136 * Handles the initialization of filter checkboxes when Document is ready. 137 * 138 * @since 5.0.0 139 * 140 * @return {void} 141 */ 142 obj.ready = function() { 143 $document.on( 144 'afterSetup.tribeEvents', 145 tribe.events.views.manager.selectors.container, 146 obj.init 147 ); 148 }; 149 150 // Configure on document ready. 151 $( obj.ready ); 152} )( jQuery, tribe.filterBar.filterCheckboxes );
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.