PageSourceSearch

https://seo.org/wp-content/themes/Avada-Child-Theme/js/bird-ajax.js

js seo.org collected 2026-10-02 10:27:41 UTC 5,788 bytes, 166 lines download raw bytes

1jQuery(document).ready(function ($) {
2
3    // Elemento donde mostramos los filtros activos
4    const $filtroContainer = $('#lista-filtros');
5    const $filtrosActivos = $('#filtros-activos');
6
7    // Captura cambios en checkboxes y radios
8    $('#form input[type="checkbox"], #form input[type="radio"]').on('change', function () {
9        applyFilters();
10    });
11
12    function applyFilters() {
13        const filters = {};
14        const $form = $('#form');
15
16        $.each($form.serializeArray(), function (i, field) {
17            if (!filters[field.name]) {
18                filters[field.name] = [];
19            }
20            filters[field.name].push(field.value);
21        });
22
23        // Limpieza de claves erróneas y vacías
24        const sanitized_filters = {};
25        $.each(filters, function (key, val) {
26            const clean_key = key.replace(/\[.*$/, '');
27            sanitized_filters[clean_key] = val;
28        });
29
30        Object.keys(sanitized_filters).forEach(key => {
31            if (sanitized_filters[key].length === 0 || sanitized_filters[key][0] === '') {
32                delete sanitized_filters[key];
33            }
34        });
35
36        // Muestra loader
37        $('#birds-results').html('<p>Cargando...</p>');
38
39        // Envío via AJAX
40        $.ajax({
41            url: bird_ajax.ajax_url,
42            type: 'POST',
43            data: {
44                action: 'load_filtered_birds',
45                filters: sanitized_filters,
46                nonce: bird_ajax.nonce
47            },
48            success: function (response) {
49                $('#birds-results').html(response);
50
51                // Actualizar listado de filtros activos
52                actualizarFiltrosActivos(sanitized_filters);
53                // Actualiza el número de resultados
54                const $resultsContainer = $(response);
55                const count = $resultsContainer.filter('.thumbtitle').length;
56
57                if (count === 0) {
58                    $('#contador-resultados').html('No se encontraron aves con esos filtros.');
59                } else {
60                    if(count==1){
61                        $('#contador-resultados').html(count + ' ave encontrada');
62                    }
63                    else{
64                        $('#contador-resultados').html(count + ' aves encontradas');
65                    }
66
67                }
68            },
69            error: function () {
70                $('#birds-results').html('<p>Error al cargar resultados.</p>');
71            }
72        });
73    }
74
75    // Función para mostrar los filtros activos
76    function actualizarFiltrosActivos(filters) {
77        $filtroContainer.empty();
78
79        let tiene_filtros = false;
80
81        $.each(filters, function (key, values) {
82            $.each(values, function (i, value) {
83                tiene_filtros = true;
84
85                const item = $('<div>', {
86                    class: 'filtro-item',
87                    html: value + '<span class="cerrar" onclick="removeFilter(\'' + key + '\', \'' + value + '\')">×</span>'
88                });
89
90                $filtroContainer.append(item);
91            });
92        });
93
94        // Mostrar u ocultar contenedor según si hay filtros
95        $filtrosActivos.toggle(!!tiene_filtros);
96    }
97
98    // Eliminar un filtro específico
99    window.removeFilter = function (key, value) {
100        const $input = $(`input[name='${key}[]'][value='${value}'], input[name='${key}'][value='${value}']`);
101
102        if ($input.is(':radio')) {
103            $input.prop('checked', false);
104        } else {
105            $input.prop('checked', false);
106        }
107
108        // Actualizar el estado de las pestañas después de quitar el filtro
109        updateTabStates();
110
111        applyFilters(); // Volver a aplicar filtros
112    };
113
114// Función para actualizar el estado de las pestañas
115    function updateTabStates() {
116        // Obtener todas las pestañas
117        const $tabs = $('.onglets .onglet');
118
119        $tabs.each(function() {
120            const tabId = $(this).attr('id').replace('onglet_', '');
121            const tabContentId = 'contenu_onglet_' + tabId;
122            const $tabContent = $('#' + tabContentId);
123
124            if ($tabContent.length) {
125                // Verificar si hay filtros activos en esta pestaña
126                const hasActiveFilters = $tabContent.find('input[type="checkbox"]:checked, input[type="radio"]:checked').length > 0;
127
128                // Actualizar clase según si hay filtros activos
129                if (hasActiveFilters) {
130                    $(this).removeClass('onglet_0').addClass('onglet_1');
131                } else {
132                    $(this).removeClass('onglet_1').addClass('onglet_0');
133                }
134            }
135        });
136    }
137
138// También necesitamos llamar a updateTabStates cuando se aplican filtros inicialmente
139    function actualizarFiltrosActivos(filters) {
140        $filtroContainer.empty();
141
142        let tiene_filtros = false;
143
144        $.each(filters, function (key, values) {
145            $.each(values, function (i, value) {
146                tiene_filtros = true;
147
148                const item = $('<div>', {
149                    class: 'filtro-item',
150                    html: value + '<span class="cerrar" onclick="removeFilter(\'' + key + '\', \'' + value + '\')">×</span>'
151                });
152
153                $filtroContainer.append(item);
154            });
155        });
156
157        // Mostrar u ocultar contenedor según si hay filtros
158        $filtrosActivos.toggle(!!tiene_filtros);
159
160        // Actualizar estado de las pestañas
161        updateTabStates();
162    }
163
164    // Cargar resultados iniciales
165    applyFilters();
166});

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.