1jQuery(document).ready(function ($) { 2 3 const formulario = $('#formulario-busqueda'); 4 5 const inputBusqueda = $('#buscar-paginas'); 6 7 const textoBuscador = $('#textoBuscador'); 8 9 const resultadoBusqueda = $('#resultado-busqueda'); 10 11 const botonToggle = $('#toggle-buscar-paginas'); 12 13 const buttonIcon = botonToggle.find('i'); 14 15 // ========================================= 16 // INICIAL 17 // ========================================= 18 19 formulario.hide(); 20 21 var container = $('#contenedorBuscador'); 22 23 var widgets = container.children(); 24 25 widgets.insertAfter(container); 26 27 container.hide(); 28 29 // ========================================= 30 // ABRIR / CERRAR BUSCADOR 31 // ========================================= 32 33 botonToggle.on('click', function (e) { 34 35 e.stopPropagation(); 36 37 if (formulario.is(':visible')) { 38 39 cerrarBuscador(); 40 41 } else { 42 43 abrirBuscador(); 44 } 45 }); 46 47 // ========================================= 48 // EVITAR CIERRE INTERNO 49 // ========================================= 50 51 formulario.on('click', function (e) { 52 53 e.stopPropagation(); 54 55 }); 56 57 // ========================================= 58 // CERRAR CLICK AFUERA 59 // ========================================= 60 61 $(document).on('click', function () { 62 63 cerrarBuscador(); 64 65 }); 66 67 // ========================================= 68 // FOCUS EN BARRA 69 // ========================================= 70 71 $('.buscador-box').on('click', function () { 72 73 inputBusqueda.focus(); 74 75 }); 76 77 // ========================================= 78 // BUSQUEDA AJAX 79 // ========================================= 80 81 inputBusqueda.on('keyup', function () { 82 83 var searchQuery = $(this).val().trim(); 84 85 // ========================================= 86 // MOSTRAR / OCULTAR TEXTO 87 // ========================================= 88 89 if (searchQuery === '') { 90 91 textoBuscador.fadeIn(200); 92 93 resultadoBusqueda 94 .html('') 95 .hide(); 96 97 return; 98 99 } else { 100 101 textoBuscador.fadeOut(200); 102 103 } 104 105 // ========================================= 106 // MOSTRAR RESULTADOS 107 // ========================================= 108 109 resultadoBusqueda 110 .show() 111 .css({ 112 'height': '500px', 113 'overflow-y': 'auto', 114 'background-color': '#FEFBFF' 115 }); 116 117 // AJAX 118 $.ajax({
119 120 url: buscarPaginasAjax.ajaxurl, 121 122 type: 'POST', 123 124 data: { 125 action: 'buscar_paginas', 126 search_query: searchQuery 127 }, 128 129 success: function (response) { 130 131 resultadoBusqueda.html(response); 132 133 } 134 135 }); 136 137 }); 138 139 // ========================================= 140 // REDIRECCION LINKS 141 // ========================================= 142 143 $(document).on('click', '.pagina a', function (e) { 144 145 e.preventDefault(); 146 147 var pageUrl = $(this).attr('href'); 148 149 window.location.href = pageUrl; 150 151 }); 152 153 // ========================================= 154 // FUNCIONES 155 // ========================================= 156 157 function abrirBuscador() { 158 159 formulario.css('display', 'flex'); 160 161 botonToggle.addClass('activo'); 162 163 buttonIcon.removeClass('fa-search'); 164 165 buttonIcon.addClass('fa-times'); 166 167 setTimeout(function () { 168 169 inputBusqueda.focus(); 170 171 }, 100); 172 } 173 174 function cerrarBuscador() { 175 176 formulario.css('display', 'none'); 177 178 resultadoBusqueda.html('').hide(); 179 180 inputBusqueda.val(''); 181 182 textoBuscador.show(); 183 184 botonToggle.removeClass('activo'); 185 186 buttonIcon.removeClass('fa-times'); 187 188 buttonIcon.addClass('fa-search'); 189 } 190 191});
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.