PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.7
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.7
2.0.13 2.0.12 2.0.11 2.0.10 2.0.9 trunk 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8
blockenberg / blocks / filter-gallery / frontend.js

frontend.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.7, at blocks/filter-gallery/frontend.js

42 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* Filter Gallery — frontend.js */
2 ( function () {
3 function initFilter( wrap ) {
4 const buttons = Array.from( wrap.querySelectorAll( '.bkfg-btn' ) );
5 const items = Array.from( wrap.querySelectorAll( '.bkfg-item' ) );
6 if ( ! buttons.length || ! items.length ) return;
7
8 buttons.forEach( function ( btn ) {
9 btn.addEventListener( 'click', function () {
10 // Update active button
11 buttons.forEach( b => b.classList.remove( 'bkfg-active' ) );
12 btn.classList.add( 'bkfg-active' );
13
14 const filter = ( btn.dataset.filter || '*' ).trim();
15
16 items.forEach( function ( item ) {
17 if ( filter === '*' ) {
18 item.classList.remove( 'bkfg-hidden' );
19 } else {
20 const tags = ( item.dataset.tags || '' ).split( ',' ).map( t => t.trim() );
21 if ( tags.includes( filter ) ) {
22 item.classList.remove( 'bkfg-hidden' );
23 } else {
24 item.classList.add( 'bkfg-hidden' );
25 }
26 }
27 } );
28 } );
29 } );
30 }
31
32 function init() {
33 document.querySelectorAll( '.bkfg-wrap[data-filter]' ).forEach( initFilter );
34 }
35
36 if ( document.readyState === 'loading' ) {
37 document.addEventListener( 'DOMContentLoaded', init );
38 } else {
39 init();
40 }
41 }() );
42