PageSourceSearch

https://bayfc.com/wp-content/plugins/gutenberghub-query-taxonomy/dist/frontend.js?ver=6ab5eed07acb4

js bayfc.com collected 2026-09-25 03:56:02 UTC 11,005 bytes, 324 lines download raw bytes

vendor: 111 bytes, lines 1-5
1/******/ (() => { // webpackBootstrap
2/******/ 	"use strict";
3/******/ 	var __webpack_modules__ = ({
4
5/***/ "./
5packages/frontend/src/query-by-taxonomy.js":
6/*!****************************************************!*\
7  !*** ./packages/frontend/src/query-by-taxonomy.js ***!
8  \****************************************************/
9/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
10
11__webpack_require__.r(__webpack_exports__);
12/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils */ "./packages/frontend/src/utils.js");
13
14class GutenberghubQueryByTaxonomy {
15  /**
16   * Constructor.
17   *
18   * @param {HTMLDivElement} queryContainer - Query loop container.
19   * @param {HTMLDivElement} container - Block container.
20   */
21  constructor(queryContainer, container) {
22    this.queryContainer = queryContainer;
23    this.container = container;
24
25    /**
26     * Query Identity.
27     *
28     * @type {number}
29     */
30    this.queryId = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.ctbParseQueryId)(this.queryContainer);
31
32    /**
33     * All relevant query elements from different layouts.
34     *
35     * @type {{
36     *  selectbox?: HTMLSelectElement | null | undefined;
37     *  checkboxesContainer: HTMLDivElement | null | undefined;
38     * }}
39     */
40    this.queryElements = {
41      /**
42       * Radio Container.
43       */
44      radiosContainer: this?.container?.querySelector(':scope > .gutenberghub-query-taxonomy-radio'),
45      /**
46       * Selectbox Container.
47       */
48      selectbox: this?.container?.querySelector(':scope select'),
49      /**
50       * Selectbox Container.
51       */
52      checkboxesContainer: this?.container?.querySelector(':scope > .gutenberghub-query-taxonomy-checkbox')
53    };
54    if (this.queryElements.selectbox) {
55      this.initializeSelectbox();
56    }
57    if (this.queryElements.checkboxesContainer) {
58      this.initializeCheckbox();
59    }
60    if (this.queryElements.radiosContainer) {
61      this.initializeRadio();
62    }
63  }
64
65  /**
66   * Loads the taxonomy query.
67   *
68   * @param {{
69   *  taxonomy: string;
70   *  term: string;
71   * }} query
72   * @param {string[]|false} include Include just the given terms.
73   *
74   * @return {void}
75   */
76  loadQuery(query) {
77    let include = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
78    const url = new URL(location.href);
79    let hasTerms = url.searchParams.has(query.taxonomy) && url.searchParams.get(query.taxonomy) !== '';
80    let terms = hasTerms ? url.searchParams.get(query.taxonomy)?.split(',') : [];
81    if (Array.isArray(include)) {
82      terms = [...terms, query.term];
83      terms = terms.filter(term => include.includes(term));
84      terms = [...new Set(terms)];
85      url.searchParams.set(query.taxonomy, terms.join(','));
86    } else {
87      url.searchParams.set(query.taxonomy, query.term);
88    }
89    url.searchParams.set('qid', this.queryId.toString());
90    location.assign(url.search);
91  }
92
93  /**
94   * Removes the taxonomy query.
95   *
96   * @param {string} taxonomy - Taxonomy name.
97   *
98   * @return {void}
99   */
100  removeQuery(taxonomy) {
101    const url = new URL(location.href);
102    url.searchParams.delete(taxonomy);
103    location.assign(url.search);
104  }
105  activeTaxonomyTaxonomy(taxonomy) {
106    var _url$searchParams$get;
107    const url = new URL(location.href);
108    return (_url$searchParams$get = url.searchParams.get(taxonomy)) !== null && _url$searchParams$get !== void 0 ? _url$searchParams$get : '';
109  }
110  /**
111   * Initializes the selectbox filter.
112   *
113   * @return {void}
114   */
115  initializeSelectbox() {
116    const url = new URL(location.href);
117    if (Number(url.searchParams.get('qid')) === this.queryId) {
118      this.queryElements.selectbox.value = this.activeTaxonomyTaxonomy(this.queryElements.selectbox.name);
119    }
120    this.queryElements.selectbox?.addEventListener('change', event => {
121      if (event.target.value !== '') {
122        this.loadQuery({
123          taxonomy: event.target?.name,
124          term: event.target?.value
125        });
126      } else {
127        this.removeQuery(event.target?.name);
128      }
129    });
130  }
131
132  /**
133   * Initializes the radio filter.
134   *
135   * @return {void}
136   */
137  initializeRadio() {
138    const {
139      radiosContainer
140    } = this.queryElements;
141    const taxonomySlug = radiosContainer?.dataset['tax'];
142    const radios = radiosContainer?.querySelectorAll('input[type="radio"]');
143    const url = new URL(location.href);
144    radios?.forEach(radio => {
145      if (radio.value === this.activeTaxonomyTaxonomy(taxonomySlug) && Number(url.searchParams.get('qid')) === this.queryId) {
146        radio.checked = true;
147      } else {
148        radio.checked = false;
149      }
150      radio.addEventListener('change', event => {
151        const includedTerms = Array.from(radios).filter(radio => {
152          if (radio.name === event.target.value) {
153            return event.target.checked;
154          } else {
155            return radio.checked;
156          }
157        }).map(radio => radio.value);
158        if (includedTerms.length > 0 && event.target.value !== '') {
159          this.loadQuery({
160            taxonomy: taxonomySlug,
161            term: event.target.value
162          }, includedTerms);
163        } else {
164          console.log(event.target.value);
165          this.removeQuery(taxonomySlug);
166        }
167      });
168    });
169  }
170
171  /**
172   * Initializes the checkbox filter.
173   *
174   * @return {void}
175   */
176  initializeCheckbox() {
177    const {
178      checkboxesContainer
179    } = this.queryElements;
180    const taxonomySlug = checkboxesContainer?.dataset['tax'];
181    const checkboxes = checkboxesContainer?.querySelectorAll('input[type="checkbox"]');
182    const url = new URL(location.href);
183    checkboxes?.forEach(checkbox => {
184      const currentActiveTaxonomy = this.activeTaxonomyTaxonomy(taxonomySlug).split(',').find(tax => tax === checkbox.value);
185      if (currentActiveTaxonomy && Number(url.searchParams.get('qid')) === this.queryId) {
186        checkbox.checked = true;
187      } else {
188        checkbox.checked = false;
189      }
190      checkbox.addEventListener('change', event => {
191        const includedTerms = Array.from(checkboxes).filter(checkbox => {
192          if (checkbox.name === event.target.value) {
193            return event.target.checked;
194          } else {
195            return checkbox.checked;
196          }
197        }).map(checkbox => checkbox.value);
198        if (includedTerms.length > 0) {
199          this.loadQuery({
200            taxonomy: taxonomySlug,
201            term: event.target.value
202          }, includedTerms);
203        } else {
204          this.removeQuery(taxonomySlug);
205        }
206      });
207    });
208  }
209}
210window.addEventListener('load', () => {
211  /**
212   * @type {NodeListOf<HTMLDivElement>} Loop Blocks.
213   */
214  const ctbQueryLoopBlocks = document.querySelectorAll('.wp-block-query');
215  ctbQueryLoopBlocks.forEach(queryLoopBlock => {
216    queryLoopBlock.querySelectorAll(':scope .gutenberghub-query-taxonomy').forEach(container => {
217      new GutenberghubQueryByTaxonomy(queryLoopBlock, container);
218    });
219  });
220});
221
222/***/ }),
223
224/***/ "./packages/frontend/src/utils.js":
225/*!****************************************!*\
226  !*** ./packages/frontend/src/utils.js ***!
227  \****************************************/
228/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
229
230__webpack_require__.r(__webpack_exports__);
231/* harmony export */ __webpack_require__.d(__webpack_exports__, {
232/* harmony export */   "ctbParseQueryId": () => (/* binding */ ctbParseQueryId)
233/* harmony export */ });
234/**
235 * Parses the gutenberghub query id from the query loop instance.
236 *
237 * @param {HTMLDivElement|null} queryLoopInstance - Query loop instance.
238 * @return {number} - Query id if found, otherwise -1.
239 */
240function ctbParseQueryId(queryLoopInstance) {
241  if (!queryLoopInstance) {
242    return -1;
243  }
244  const classList = Array.from(queryLoopInstance.classList);
245  const queryClass = classList.find(className => className.startsWith('ghub-query-id-'));
246  if (!queryClass) {
247    return -1;
248  }
249  const classTokens = queryClass.split('-');
250  return Number(classTokens[classTokens.length - 1]);
251}
252
253/***/ })
vendor: 2,827 bytes, lines 253-324
253
254
255/******/ 	});
256/************************************************************************/
257/******/ 	// The module cache
258/******/ 	var __webpack_module_cache__ = {};
259/******/ 	
260/******/ 	// The require function
261/******/ 	function __webpack_require__(moduleId) {
262/******/ 		// Check if module is in cache
263/******/ 		var cachedModule = __webpack_module_cache__[moduleId];
264/******/ 		if (cachedModule !== undefined) {
265/******/ 			return cachedModule.exports;
266/******/ 		}
267/******/ 		// Create a new module (and put it into the cache)
268/******/ 		var module = __webpack_module_cache__[moduleId] = {
269/******/ 			// no module.id needed
270/******/ 			// no module.loaded needed
271/******/ 			exports: {}
272/******/ 		};
273/******/ 	
274/******/ 		// Execute the module function
275/******/ 		__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
276/******/ 	
277/******/ 		// Return the exports of the module
278/******/ 		return module.exports;
279/******/ 	}
280/******/ 	
281/************************************************************************/
282/******/ 	/* webpack/runtime/define property getters */
283/******/ 	(() => {
284/******/ 		// define getter functions for harmony exports
285/******/ 		__webpack_require__.d = (exports, definition) => {
286/******/ 			for(var key in definition) {
287/******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
288/******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
289/******/ 				}
290/******/ 			}
291/******/ 		};
292/******/ 	})();
293/******/ 	
294/******/ 	/* webpack/runtime/hasOwnProperty shorthand */
295/******/ 	(() => {
296/******/ 		__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
297/******/ 	})();
298/******/ 	
299/******/ 	/* webpack/runtime/make namespace object */
300/******/ 	(() => {
301/******/ 		// define __esModule on exports
302/******/ 		__webpack_require__.r = (exports) => {
303/******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
304/******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
305/******/ 			}
306/******/ 			Object.defineProperty(exports, '__esModule', { value: true });
307/******/ 		};
308/******/ 	})();
309/******/ 	
310/************************************************************************/
311var __webpack_exports__ = {};
312// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
313(() => {
314/*!****************************************!*\
315  !*** ./packages/frontend/src/index.js ***!
316  \****************************************/
317__webpack_require__.r(__webpack_exports__);
318/* harmony import */ var _query_by_taxonomy__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./query-by-taxonomy */ "./packages/frontend/src/query-by-taxonomy.js");
319
320})();
321
322/******/ })()
323;
324//# sourceMappingURL=frontend.js.map

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.